Changeset 4046
- Timestamp:
- 04/17/08 08:53:01 (3 months ago)
- Files:
-
- trunk/dabo/biz/dBizobj.py (modified) (14 diffs)
- trunk/dabo/dApp.py (modified) (1 diff)
- trunk/dabo/db/dBackend.py (modified) (3 diffs)
- trunk/dabo/db/dCursorMixin.py (modified) (1 diff)
- trunk/dabo/db/dbFirebird.py (modified) (1 diff)
- trunk/dabo/db/dbMySQL.py (modified) (3 diffs)
- trunk/dabo/db/dbPostgreSQL.py (modified) (3 diffs)
- trunk/dabo/db/dbSQLite.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/biz/dBizobj.py
r4043 r4046 258 258 259 259 260 def beginTransaction(self): 261 """Attempts to begin a transaction at the database level, and returns 262 True/False depending on its success. 263 """ 264 ret = self._getTransactionToken() 265 if ret: 266 self._CurrentCursor.beginTransaction() 267 return ret 268 269 270 def commitTransaction(self): 271 """Attempts to commit a transaction at the database level, and returns 272 True/False depending on its success. 273 """ 274 ret = self._hasTransactionToken() and self._CurrentCursor.commitTransaction() 275 if ret: 276 self._releaseTransactionToken() 277 return ret 278 279 280 def rollbackTransaction(self): 281 """Attempts to rollback a transaction at the database level, and returns 282 True/False depending on its success. 283 """ 284 ret = self._hasTransactionToken() and self._CurrentCursor.rollbackTransaction() 285 if ret: 286 self._releaseTransactionToken() 287 return ret 288 289 260 290 def _getTransactionToken(self): 261 """Ask the Application for the transaction token. 262 263 If the token is granted, then this bizobj has the ability to begin and 264 end transactions. 291 """Ask the Application for the transaction token. If the token is granted, 292 then this bizobj has the ability to begin and end transactions. 265 293 """ 266 294 try: … … 273 301 274 302 303 def _hasTransactionToken(self): 304 """Returns True/False, depending on whether this bizobj 305 currently "holds" the transaction token. 306 """ 307 try: 308 ret = self.Application.hasTransactionToken(self) 309 except AttributeError: 310 ret = hasattr(dabo, "_bizTransactionToken") and (dabo._bizTransactionToken is self) 311 return ret 312 313 275 314 def _releaseTransactionToken(self): 276 """Ask the Application to give up the transaction token. 277 278 Once this is done, other bizobjs can receive the token to begin and 279 end transactions. 315 """Ask the Application to give up the transaction token. Once this is done, 316 other bizobjs can receive the token to begin and end transactions. 280 317 """ 281 318 try: … … 291 328 cursor = self._CurrentCursor 292 329 current_row = self.RowNumber 293 isTransactionManager = False 294 if startTransaction: 295 isTransactionManager = self._getTransactionToken() 296 if isTransactionManager: 297 cursor.beginTransaction() 298 330 startTransaction = startTransaction and self.beginTransaction() 299 331 try: 300 332 self.scanChangedRows(self.save, includeNewUnchanged=self.SaveNewUnchanged, 301 333 startTransaction=False) 302 if isTransactionManager: 303 cursor.commitTransaction() 304 self._releaseTransactionToken() 334 if startTransaction: 335 self.commitTransaction() 305 336 306 337 except dException.ConnectionLostException, e: … … 309 340 except dException.DBQueryException, e: 310 341 # Something failed; reset things. 311 if isTransactionManager: 312 cursor.rollbackTransaction() 313 self._releaseTransactionToken() 342 if startTransaction: 343 self.rollbackTransaction() 314 344 # Pass the exception to the UI 315 345 self.RowNumber = current_row 316 346 raise dException.DBQueryException, e 317 347 except dException.dException, e: 318 if isTransactionManager: 319 cursor.rollbackTransaction() 320 self._releaseTransactionToken() 348 if startTransaction: 349 self.rollbackTransaction() 321 350 self.RowNumber = current_row 322 351 raise … … 346 375 self._validate() 347 376 348 isTransactionManager = False 349 if startTransaction: 350 isTransactionManager = self._getTransactionToken() 351 if isTransactionManager: 352 cursor.beginTransaction() 353 377 startTransaction = startTransaction and self.beginTransaction() 354 378 # Save to the Database, but first save the IsAdding flag as the save() call 355 379 # will reset it to False: … … 369 393 370 394 # Finish the transaction, and requery the children if needed. 371 if isTransactionManager: 372 cursor.commitTransaction() 373 self._releaseTransactionToken() 395 if startTransaction: 396 self.commitTransaction() 374 397 if self.RequeryChildOnSave: 375 398 self.requeryAllChildren() … … 383 406 except dException.DBQueryException, e: 384 407 # Something failed; reset things. 385 if isTransactionManager: 386 cursor.rollbackTransaction() 387 self._releaseTransactionToken() 408 if startTransaction: 409 self.rollbackTransaction() 388 410 # Pass the exception to the UI 389 411 raise dException.DBQueryException, e … … 391 413 except dException.dException, e: 392 414 # Something failed; reset things. 393 if isTransactionManager: 394 cursor.rollbackTransaction() 395 self._releaseTransactionToken() 415 if startTransaction: 416 self.rollbackTransaction() 396 417 # Pass the exception to the UI 397 418 raise … … 441 462 raise dException.BusinessRuleViolation, errMsg 442 463 443 isTransactionManager = False 444 if startTransaction: 445 isTransactionManager = self._getTransactionToken() 446 if isTransactionManager: 447 cursor.beginTransaction() 448 464 startTransaction = startTransaction and self.beginTransaction() 449 465 try: 450 466 for child in self.__children: 451 467 child.deleteAll(startTransaction=False) 452 if isTransactionManager: 453 cursor.commitTransaction() 454 self._releaseTransactionToken() 468 if startTransaction: 469 self.commitTransaction() 455 470 456 471 except dException.DBQueryException, e: 457 if isTransactionManager: 458 cursor.rollbackTransaction() 459 self._releaseTransactionToken() 472 if startTransaction: 473 self.rollbackTransaction() 460 474 raise dException.DBQueryException, e 461 475 except StandardError, e: 462 if isTransactionManager: 463 cursor.rollbackTransaction() 464 self._releaseTransactionToken() 476 if startTransaction: 477 self.rollbackTransaction() 465 478 raise StandardError, e 466 479 self.afterDeleteAllChildren() … … 485 498 raise dException.dException, _("Deletion prohibited - there are related child records.") 486 499 487 isTransactionManager = False 488 if startTransaction: 489 isTransactionManager = self._getTransactionToken() 490 if isTransactionManager: 491 cursor.beginTransaction() 492 500 startTransaction = startTransaction and self.beginTransaction() 493 501 try: 494 502 cursor.delete() … … 505 513 child.cancelAll() 506 514 child.requery() 507 508 if isTransactionManager: 509 cursor.commitTransaction() 510 self._releaseTransactionToken() 515 if startTransaction: 516 self.commitTransaction() 511 517 512 518 if not inLoop: … … 515 521 self.afterDelete() 516 522 except dException.DBQueryException, e: 517 if isTransactionManager: 518 cursor.rollbackTransaction() 519 self._releaseTransactionToken() 523 if startTransaction: 524 self.rollbackTransaction() 520 525 raise dException.DBQueryException, e 521 526 except StandardError, e: 522 if isTransactionManager: 523 cursor.rollbackTransaction() 524 self._releaseTransactionToken() 527 if startTransaction: 528 self.rollbackTransaction() 525 529 raise StandardError, e 526 530 … … 529 533 """ Delete all rows in the data set.""" 530 534 cursor = self._CurrentCursor 531 isTransactionManager = False 532 if startTransaction: 533 isTransactionManager = self._getTransactionToken() 534 if isTransactionManager: 535 cursor.beginTransaction() 535 startTransaction = startTransaction and self.beginTransaction() 536 536 try: 537 537 while self.RowCount > 0: 538 538 self.first() 539 539 ret = self.delete(startTransaction=False, inLoop=True) 540 if isTransactionManager: 541 cursor.commitTransaction() 542 self._releaseTransactionToken() 540 if startTransaction: 541 self.commitTransaction() 543 542 544 543 self.afterPointerMove() … … 546 545 self.afterDelete() 547 546 except dException.DBQueryException, e: 548 if isTransactionManager: 549 cursor.rollbackTransaction() 550 self._releaseTransactionToken() 547 if startTransaction: 548 self.rollbackTransaction() 551 549 raise dException.DBQueryException, e 552 550 except StandardError, e: 553 if isTransactionManager: 554 cursor.rollbackTransaction() 555 self._releaseTransactionToken() 551 if startTransaction: 552 self.rollbackTransaction() 556 553 raise StandardError, e 557 554 trunk/dabo/dApp.py
r4003 r4046 902 902 903 903 904 def hasTransactionToken(self, biz): 905 """Returns True/False, depending on whether the specified 906 bizobj currently "holds" the transaction token. 907 """ 908 cn = biz._connection 909 return (self._transactionTokens.get(cn) is biz) 910 911 904 912 def releaseTransactionToken(self, biz): 905 913 """When a process that would normally close a transaction happens, the trunk/dabo/db/dBackend.py
r3606 r4046 207 207 self._connection.begin() 208 208 dabo.dbActivityLog.write("SQL: begin") 209 return True 209 210 210 211 … … 213 214 self._connection.commit() 214 215 dabo.dbActivityLog.write("SQL: commit") 216 return True 215 217 216 218 … … 219 221 self._connection.rollback() 220 222 dabo.dbActivityLog.write("SQL: rollback") 223 return True 221 224 222 225 trunk/dabo/db/dCursorMixin.py
r4030 r4046 466 466 467 467 def sort(self, col, ord=None, caseSensitive=True): 468 """ Sort the result set on the specified column in the specified order. 469 470 If the sort direction is not specified, sort() cycles among Ascending, 471 Descending and no sort order. 468 """ Sort the result set on the specified column in the specified order. If the sort 469 direction is not specified, default to ascending order. If 'cycle' is specified as the 470 direction, use the next ordering in the list [None, 'ASC', 'DESC']. The possible 471 values for 'ord' are: 472 None 473 "" (i.e., an empty string) 474 ASC 475 DESC 476 CYCLE 477 Only the first three characters are significant; case is ignored. 472 478 """ 473 479 currCol = self.sortColumn 474 480 currOrd = self.sortOrder 475 481 currCase = self.sortCase 482 if ord is None: 483 ord = "ASC" 484 elif ord == "": 485 ord = None 486 else: 487 ord = ord[:3].upper() 488 if ord == "CYC": 489 ord = {"ASC": "DES", "DES": None, None: "ASC"}[currOrd] 490 col = currCol 476 491 477 492 # Make sure that the specified column is a column in the result set trunk/dabo/db/dbFirebird.py
r3606 r4046 198 198 def beginTransaction(self, cursor): 199 199 """ Begin a SQL transaction.""" 200 ret = False 200 201 if not self._connection._has_transaction(): 201 202 self._connection.begin() 202 203 dabo.dbActivityLog.write("SQL: begin") 204 ret = True 205 return ret 203 206 204 207 trunk/dabo/db/dbMySQL.py
r3606 r4046 66 66 cursor.execute("START TRANSACTION") 67 67 dabo.dbActivityLog.write("SQL: begin") 68 return True 68 69 69 70 … … 72 73 cursor.execute("COMMIT") 73 74 dabo.dbActivityLog.write("SQL: commit") 75 return True 74 76 75 77 … … 78 80 cursor.execute("ROLLBACK") 79 81 dabo.dbActivityLog.write("SQL: rollback") 82 return True 80 83 81 84 trunk/dabo/db/dbPostgreSQL.py
r3869 r4046 32 32 def beginTransaction(self, cursor): 33 33 dabo.dbActivityLog.write("SQL: begin (implicit, nothing done)") 34 pass34 return True 35 35 36 36 … … 64 64 else: 65 65 sqltablestr = (("SELECT schemaname || '.' || tablename AS tablename FROM pg_tables WHERE (schemaname not like 'pg_%s' and schemaname not like 'information%s') and has_table_privilege('%s', schemaname || '.' || tablename, 'SELECT')") % ('%','%',self.conn_user)) 66 66 67 sqltablestr = (("""SELECT schemaname || '.' || tablename AS tablename 68 FROM pg_tables 69 WHERE (schemaname not like 'pg_%s' 70 and schemaname not like 'information%s') 71 and has_table_privilege('%s', schemaname || '.' || tablename, 'SELECT') 72 """) % ('%','%',self.conn_user)) 73 # if includeSystemTables: 74 # sqltablestr = ("select relname from pg_class where relkind= 'r' ") 75 # else: 76 # sqltablestr = ("select relname from pg_class where relkind= 'r' and relname not like 'pg_%' and relname not like 'sql_%' ") 77 78 print 79 print "sqltablestr = ", sqltablestr 80 print "conn_user = ", self.conn_user 81 print 67 82 cursor.execute(sqltablestr) 68 83 rs = cursor.getDataSet() … … 70 85 for record in rs: 71 86 tables.append(record["tablename"]) 87 # tables.append(record["relname"]) 72 88 return tuple(tables) 73 89 trunk/dabo/db/dbSQLite.py
r4013 r4046 84 84 cursor.execute("BEGIN") 85 85 dabo.dbActivityLog.write("SQL: begin") 86 return True 86 87 87 88 … … 92 93 cursor.execute("COMMIT", errorClass=opError) 93 94 dabo.dbActivityLog.write("SQL: commit") 95 return True 94 96 except opError, e: 95 97 # There is no transaction active in this case, so ignore the error. … … 104 106 cursor.execute("ROLLBACK") 105 107 dabo.dbActivityLog.write("SQL: rollback") 108 return True 106 109 107 110
