Represents a connection to the MySQL server. All parameters which are not provided will use MySQL’s defaults. For the exact semantics, see the documentation for the mysql_real_connect() and mysql_options() functions.
Parameters: |
|
---|
Create a cursor associated with this connection.
Parameters: |
|
---|
Extra options can be passed to the cursor by keyword:
Parameters: |
|
---|
Connections can also be used as context managers:
with some_connection as cursor:
do_something_with(cursor)
This behaves the same way as using a cursor as a context manager.
Cursors of any sort should never be instantiated directly. Currently, the only real difference between cursor classes is how they return fetched rows. Iterating over a cursor is the same as repeatedly calling fetchone():
curs.execute('SELECT a, b FROM `some_table`')
curs.execute('SELECT c, d FROM `some_other_table`')
# result set one:
for a, b in curs:
do_whatever_with(a, b)
# result set two:
for c, d in curs:
do_whatever_with(a, b)
Cursors can also be used as context managers:
with some_connection.cursor() as cursor:
do_something_with(cursor)
Is equivalent to:
cursor = some_connection.cursor()
try:
do_something_with(cursor)
except:
some_connection.rollback()
raise
else:
some_connection.commit()
finally:
cursor.close()
Cursor instances represent rows as tuples.
Execute a query. If plain_query is true, run a plain, unparameterized query. MySQL cannot parameterize all kinds of statements, which makes it sometimes necessary to execute a plain query. If plain_query is true and params is true, an exception will be raised as plain queries cannot be parameterized.
Plain queries also have some associated caveats:
The rowid of the last inserted or updated row. For a full discussion of the semantics, see the documentation for the mysql_insert_id() function.
If executemany() was called, lastrowid will reflect the rowid for the last set of parameters that were passed.
FileWrapper is a wrapper class for file-like objects so that their contents can be streamed over the wire as a bound parameter for a query. Strings read from the wrapped file are assumed to be text and not arbitrary bytes.
Strings will be read by calling the read() method on the file object with chunksize as the only parameter parameter until it returns the empty string. If doclose is true, the file will have its close() method called once it has been exhausted.
Some exception descriptions are lovingly stolen from PEP 249.
This is the base class for all the oursql-defined error exceptions.