python database access the following attributes are also defined on connection objects row_factory function that gets called to create the object representing the contents of each result row this function takes two argumentsthe cursor object used to obtain the result and tuple with the raw result row text_factory function that is called to create the objects representing text values in the database the function must take single argument that is utf- -encoded byte string the return value should be some kind of string by defaulta unicode string is returned total_changes an integer representing the number of rows that have been modified since the database connection was opened final feature of connection objects is that they can be used with the contextmanager protocol to automatically handle transactions for exampleconn sqlite connect("somedb"with connconn execute("insert into sometable values (?,?)"("foo","bar"))in this examplea commit(operation is automatically performed after all statements in the with block have executed and no errors have occurred if any kind of exception is raiseda rollback(operation is performed and the exception is reraised cursors and basic operations to perform basic operations on sqlite databaseyou first have to create cursor object using the cursor(method of connection you then use the execute()executemany()or executescript(methods of the cursor to execute sql statements see the database api section for further details about the general operation of these methods instead of repeating that information herea set of common database use cases are presented along with sample code the goal is to show both the operation of cursor objects and some common sql operations for those programmers who might need brief refresher on the syntax creating new database tables the following code shows how to open database and create new tableimport sqlite conn sqlite connect("mydb"cur conn cursor(cur execute("create table stocks (symbol textshares integerprice real)"conn commit(when defining tablesa few primitive sqlite datatypes should be usedtextintegerrealand blob the blob type is bytestringwhereas the text type is assumed to be utf- -encoded unicode lib fl ff