Ticket #1258: pymssql.patch

File pymssql.patch, 1.6 KB (added by Cheng <czhang.cmu+web@…>, 18 years ago)

patch for pymssql

  • pymssql.py

    === pymssql.py
    ==================================================================
     
    197197                x = "'" + string.replace(str(x), "'", "''") + "'"
    198198        elif type(x) in (types.IntType, types.LongType, types.FloatType):
    199199                pass
     200        elif type(x) == types.BooleanType:
     201                x = x and 1 or 0
    200202        elif x is None:
    201203                x = 'NULL'
    202204        elif hasattr(x, '__pg_repr__'):
     
    225227
    226228        def __init__(self, cnx):
    227229                self.__cnx = cnx
     230                self.__autocommit = False
    228231                try:
    229232                        self.__cnx.query("begin tran")
    230233                        self.__cnx.fetch_array()
     
    240243        def commit(self):
    241244                if self.__cnx == None:
    242245                        raise OperationalError, "invalid connection."
     246                if self.__autocommit == True:
     247                        return
    243248                try:
    244249                        self.__cnx.query("commit tran")
    245250                        self.__cnx.fetch_array()
     
    251256        def rollback(self):
    252257                if self.__cnx == None:
    253258                        raise OperationalError, "invalid connection."
     259                if self.__autocommit == True:
     260                        return
    254261                try:
    255262                        self.__cnx.query("rollback tran")
    256263                        self.__cnx.fetch_array()
     
    266273                        return pymssqlCursor(self.__cnx)
    267274                except:
    268275                        raise OperationalError, "invalid connection."
     276       
     277        def autocommit(self,status):
     278                if status:
     279                        if self.__autocommit == False:
     280                                self.__cnx.query("rollback tran")
     281                                self.__cnx.fetch_array()
     282                                self.__autocommit = True
     283                else:
     284                        if self.__autocommit == True:
     285                                self.__cnx.query("begin tran")
     286                                self.__cnx.fetch_array()
     287                                self.__autocommit = False
    269288
    270289
    271 
    272290# connects to a database
    273291def connect(dsn = None, user = "sa", password = "", host = "127.0.0.1", database = "master"):
    274292        # first get params from DSN
Back to Top