Connection, cursor Two objects of the database
Python Database Diagramming Process
Connection, cursor metaphor
Parameter list for Connection ()
- Host, the database server hostname of the connection, by default localhost (localhost).
- User, the username of the connection database, default to the current user.
- passwd, connection password, no default value.
- DB, connected database name, no default value.
- Conv, maps text to a Python-type dictionary.
MySQLdb.converters.conversions
- Cursorclass,cursor () The type used, the default value is MySQLdb.cursors.Cursor.
- Compress, enable the Protocol compression feature.
- Named_pipe, in Windows, is connected to a named pipe.
- Init_command, once the connection is established, specify a statement for the database server to run.
- Read_default_file, use the specified MySQL configuration file.
- Read_default_group, read the default group.
- Unix_socket, in Unix, the socket used by the connection uses TCP by default.
Port, which specifies the connection port for the database server, which is 3306 by default.
The Db.close () method of the Connection object closes the database connection and frees the related resources.
- The Db.cursor ([Cursorclass]) method of the Connection object returns a pointer object that is used to access and manipulate the data in the database.
- The Db.begin () method of the Connection object is used to start a transaction, and if the database's autocommit has been turned on, close it until the transaction calls commit () and rollback () end.
- The Db.commit () and Db.rollback () methods of the Connection object represent transaction commits and fallback, respectively.
- The Cursor.close () method of the pointer object closes the pointer and frees the related resource.
- The Cursor.execute (Query[,parameters]) method of the pointer object executes the database query.
- The pointer object's Cursor.fetchall () extracts all the rows in the pointer's result set, returning a tuple of result sets (tuples).
- The Cursor.fetchmany ([size=cursor.arraysize]) of the pointer object extracts multiple rows from the query result set, and we can specify the number of rows to be fetched with optional parameters.
- The Cursor.fetchone () of the pointer object returns the next row from the query result set.
- The Cursor.arraysize property of the pointer object specifies the number of rows returned by the Cursor.fetchmany () method, affecting the performance of the Fetchall (), which is the default value of 1.
The Cursor.rowcount property of the pointer object indicates the number of rows that occurred in the last query or update. 1 indicates that the query has not started or the data has not been queried.
Methods supported by the Connection object
Cursor
Common methods:
Common Properties:
- Connection: Creating a database connection for this cursor object
- ArraySize: Use the Fetchmany () method to remove the number of records at one time, default to 1
Django eighth Lesson 5. "Database connection, Cursor"