Python Tutorial ( PDFDrive )
COMMIT Operation: Commit is the operation, which gives a green signal to database to finalize the changes, and after this operation,no change can be reverted back.Here is a simple example to call commit method.db.commit()ROLLBACK Operation: If you are not satisfied with one or more of the changes and you want to revert back those changes completely,then use rollback() method.Here is a simple example to call rollback() method.db.rollback()Disconnecting Database: To disconnect Database connection, use close() method.db.close()If the connection to a database is closed by the user with the close() method, any outstanding transactions arerolled back by the DB. However, instead of depending on any of DB lower level implementation details, yourapplication would be better off calling commit or rollback explicitly.Handling Errors: There are many sources of errors. A few examples are a syntax error in an executed SQL statement, aconnection failure, or calling the fetch method for an already canceled or finished statement handle.The DB API defines a number of errors that must exist in each database module. The following table lists theseexceptions.ExceptionWarningErrorInterfaceErrorDatabaseErrorDataErrorOperationalErrorIntegrityErrorInternalErrorDescriptionUsed for non-fatal issues. Must subclass StandardError.Base class for errors. Must subclass StandardError.Used for errors in the database module, not the database itself. Must subclassError.Used for errors in the database. Must subclass Error.Subclass of DatabaseError that refers to errors in the data.Subclass of DatabaseError that refers to errors such as the loss of a connection tothe database. These errors are generally outside of the control of the Pythonscripter.Subclass of DatabaseError for situations that would damage the relational integrity,such as uniqueness constraints or foreign keys.Subclass of DatabaseError that refers to errors internal to the database module,such as a cursor no longer being active.TUTORIALS POINT Simply Easy Learning
ProgrammingErrorSubclass of DatabaseError that refers to errors such as a bad table name andother things that can safely be blamed on you.NotSupportedError Subclass of DatabaseError that refers to trying to call unsupported functionality.Your Python scripts should handle these errors, but before using any of the above exceptions, make sure yourMySQLdb has support for that exception. You can get more information about them by reading the DB API 2.0specification.TUTORIALS POINT Simply Easy Learning
- Page 295 and 296: os.tempnam(dir, prefix)Parameters
- Page 297 and 298: Description The method ttyname() re
- Page 299 and 300: Return Value This method does not
- Page 301 and 302: Return Value This method returns t
- Page 303 and 304: KeyErrorNameErrorUnboundLocalErrorE
- Page 305 and 306: ......................else:If there
- Page 307 and 308: print "Error: can\'t find file or r
- Page 309 and 310: self.args = argSo once you defined
- Page 311 and 312: 'Optional class documentation strin
- Page 313 and 314: For the above class let's try to ac
- Page 315 and 316: print 'Calling child method'c = Chi
- Page 317 and 318: Data Hiding: An object's attribute
- Page 319 and 320: groups()This method returns all mat
- Page 321 and 322: SYNTAX: re.sub(pattern, repl, strin
- Page 323 and 324: \s Matches whitespace. Equivalent t
- Page 325 and 326: Backreferences: This matches a prev
- Page 327 and 328: CHAPTER20Python CGI ProgrammingWhat
- Page 329 and 330: If you click hello.py, then this pr
- Page 331 and 332: Simple URL Example : Get Metho
- Page 333 and 334: </form>The result of this code is t
- Page 335 and 336: text_content = form.getvalue('textc
- Page 337 and 338: Here is an example of how to retrie
- Page 339 and 340: CHAPTER21Python Database AccessThe
- Page 341 and 342: EXAMPLE: Following is the example o
- Page 343 and 344: ('Mac', 'Mohan', 20, 'M', 2000)try:
- Page 345: DELETE Operation: DELETE operation
- Page 349 and 350: The socket Module: To create a so
- Page 351 and 352: Protocol Common function Port No Py
- Page 353 and 354: Subject: SMTP e-mail testThis is a
- Page 355 and 356: try:smtpObj = smtplib.SMTP('localho
- Page 357 and 358: count = 0while count < 5:time.sleep
- Page 359 and 360: Synchronizing Threads: The threadi
- Page 361 and 362: thread = myThread(threadID, tName,
- Page 363 and 364: <stars>10</stars><description>Talk
- Page 365 and 366: print "Rating:", self.ratingelif se
- Page 367 and 368: Format: DVDRating: PGDescription: T
- Page 369 and 370: Tkinter Widgets Tkinter provides v
- Page 371 and 372: fgfontheighthighlightcolorimagejust
- Page 373 and 374: WidthXscrollincrementXscrollcommand
- Page 375 and 376: pattern when it is over the checkbu
- Page 377 and 378: The Entry widget is used to accept
- Page 379 and 380: E1 = Entry(top, bd =5)E1.pack(side
- Page 381 and 382: Optionanchorbgbitmapbdcursorfontfgh
- Page 383 and 384: selectmodeDetermines how many items
- Page 385 and 386: Syntax: Here is the simple syntax t
- Page 387 and 388: Menu The goal of this widget is to
- Page 389 and 390: filemenu.add_command(label="Exit",
- Page 391 and 392: Example: Try the following example
- Page 393 and 394: WidthWraplengthWidth of the label i
- Page 395 and 396: label appears in the top left corne
ProgrammingError
Subclass of DatabaseError that refers to errors such as a bad table name and
other things that can safely be blamed on you.
NotSupportedError Subclass of DatabaseError that refers to trying to call unsupported functionality.
Your Python scripts should handle these errors, but before using any of the above exceptions, make sure your
MySQLdb has support for that exception. You can get more information about them by reading the DB API 2.0
specification.
TUTORIALS POINT
Simply Easy Learning