Ticket #5062: pymssql.diff
File pymssql.diff, 3.6 KB (added by , 17 years ago) |
---|
-
pymssql.py
133 133 134 134 # first try to execute all queries 135 135 totrows = 0 136 sql = "" 137 try: 138 for params in param_seq: 139 if params != None: 140 sql = _quoteparams(operation, params) 136 #import pdb 137 #pdb.set_trace() 138 #Respect GO terminator 139 for sql in operation.split('\nGO'): 140 if sql=='': 141 continue 142 try: 143 for params in param_seq: 144 if params != None: 145 sql = _quoteparams(sql, params) 146 147 #print sql 148 ret = self.__source.query(sql) 149 if ret == 1: 150 self._result = self.__source.fetch_array() 151 totrows = totrows + self._result[self.__resultpos][1] 152 else: 153 self._result = None 154 raise DatabaseError, "error: %s" % self.__source.errmsg() 155 except Exception,e: 156 if self.__source.errmsg() == None: 157 raise e 141 158 else: 142 sql = operation 143 #print sql 144 ret = self.__source.query(sql) 145 if ret == 1: 146 self._result = self.__source.fetch_array() 147 totrows = totrows + self._result[self.__resultpos][1] 148 else: 149 self._result = None 150 raise DatabaseError, "error: %s" % self.__source.errmsg() 151 except: 152 raise DatabaseError, "internal error: %s" % self.__source.errmsg() 159 raise DatabaseError, "internal error: %s" % self.__source.errmsg() 153 160 154 161 # then initialize result raw count and description 155 162 if len(self._result[self.__resultpos][0]) > 0: … … 220 227 # alternative quoting by Luciano Pacheco <lucmult@gmail.com> 221 228 #elif hasattr(x, 'timetuple'): 222 229 # x = time.strftime('\'%Y%m%d %H:%M:%S\'', x.timetuple()) 230 elif type(x) == types.BooleanType: 231 x = x and 1 or 0 223 232 else: 224 233 #print "didn't like " + x + " " + str(type(x)) 225 234 raise InterfaceError, 'do not know how to handle type %s' % type(x) … … 244 253 245 254 def __init__(self, cnx): 246 255 self.__cnx = cnx 256 self.__autocommit = False 247 257 try: 248 self.__cnx.query(" begin tran")258 self.__cnx.query("IF @@TRANCOUNT>0 begin tran") 249 259 self.__cnx.fetch_array() 250 260 except: 251 261 raise OperationalError, "invalid connection." … … 259 269 def commit(self): 260 270 if self.__cnx == None: 261 271 raise OperationalError, "invalid connection." 272 273 if self.__autocommit == True: 274 return 275 262 276 try: 263 self.__cnx.query(" commit tran")277 self.__cnx.query("IF @@TRANCOUNT>0 commit tran") 264 278 self.__cnx.fetch_array() 265 self.__cnx.query(" begin tran")279 self.__cnx.query("IF @@TRANCOUNT>0 begin tran") 266 280 self.__cnx.fetch_array() 267 281 except: 268 282 raise OperationalError, "can't commit." … … 270 284 def rollback(self): 271 285 if self.__cnx == None: 272 286 raise OperationalError, "invalid connection." 287 288 if self.__autocommit == True: 289 return 290 273 291 try: 274 self.__cnx.query(" rollback tran")292 self.__cnx.query("IF @@TRANCOUNT>0 rollback tran") 275 293 self.__cnx.fetch_array() 276 self.__cnx.query(" begin tran")294 self.__cnx.query("IF @@TRANCOUNT>0 begin tran") 277 295 self.__cnx.fetch_array() 278 296 except: 279 297 raise OperationalError, "can't rollback." 280 298 299 def autocommit(self,status): 300 if status: 301 if self.__autocommit == False: 302 self.__cnx.query("IF @@TRANCOUNT>0 rollback tran") 303 self.__cnx.fetch_array() 304 self.__autocommit = True 305 else: 306 if self.__autocommit == True: 307 self.__cnx.query("IF @@TRANCOUNT>0 begin tran") 308 self.__cnx.fetch_array() 309 self.__autocommit = False 310 281 311 def cursor(self): 282 312 if self.__cnx == None: 283 313 raise OperationalError, "invalid connection."