Package MySQLdb :: Module connections :: Class Connection
[hide private]
[frames] | no frames]

Class Connection

source code

       object --+    
                |    
_mysql.connection --+
                    |
                   Connection

MySQL Database Connection Object

Nested Classes [hide private]
  default_cursor
This is the standard Cursor class that returns rows as tuples and stores the result set in the client.
  Warning
Exception raised for important warnings like data truncations while inserting, etc.
  Error
Exception that is the base class of all other error exceptions (not Warning).
  InterfaceError
Exception raised for errors that are related to the database interface rather than the database itself.
  DatabaseError
Exception raised for errors that are related to the database.
  DataError
Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range, etc.
  OperationalError
Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer, e.g.
  IntegrityError
Exception raised when the relational integrity of the database is affected, e.g.
  InternalError
Exception raised when the database encounters an internal error, e.g.
  ProgrammingError
Exception raised for programming errors, e.g.
  NotSupportedError
Exception raised in case a method or database API was used which is not supported by the database, e.g.
Instance Methods [hide private]
 
__init__(self, *args, **kwargs)
Create a connection to the database.
source code
 
cursor(self, cursorclass=None)
Create a cursor on which queries may be performed.
source code
 
__enter__(self) source code
 
__exit__(self, exc, value, tb) source code
 
literal(self, o)
If o is a single object, returns an SQL literal as a string.
source code
 
begin(self)
Explicitly begin a connection.
source code
 
warning_count(self)
Return the number of warnings generated from the last query.
source code
 
set_character_set(self, charset)
Set the connection character set to charset.
source code
 
set_sql_mode(self, sql_mode)
Set the connection sql_mode.
source code
 
show_warnings(self)
Return detailed information about warnings as a sequence of tuples of (Level, Code, Message).
source code
 
errorhandler(connection, cursor, errorclass, errorvalue)
If cursor is not None, (errorclass, errorvalue) is appended to cursor.messages; otherwise it is appended to connection.messages.
source code

Inherited from _mysql.connection: __new__, __repr__, affected_rows, autocommit, change_user, character_set_name, close, commit, dump_debug_info, errno, error, escape, escape_string, field_count, get_character_set_info, get_host_info, get_proto_info, get_server_info, info, insert_id, kill, next_result, ping, query, rollback, select_db, set_server_option, shutdown, sqlstate, stat, store_result, string_literal, thread_id, use_result

Inherited from object: __delattr__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __setattr__, __str__

Properties [hide private]

Inherited from _mysql.connection: client_flag, converter, open, port, server_capabilities

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args, **kwargs)
(Constructor)

source code 


Create a connection to the database. It is strongly recommended
that you only use keyword parameters. Consult the MySQL C API
documentation for more information.

host
  string, host to connect
  
user
  string, user to connect as

passwd
  string, password to use

db
  string, database to use

port
  integer, TCP/IP port to connect to

unix_socket
  string, location of unix_socket to use

conv
  conversion dictionary, see MySQLdb.converters

connect_timeout
  number of seconds to wait before the connection attempt
  fails.

compress
  if set, compression is enabled

named_pipe
  if set, a named pipe is used to connect (Windows only)

init_command
  command which is run once the connection is created

read_default_file
  file from which default client values are read

read_default_group
  configuration group to use from the default file

cursorclass
  class object, used to create cursors (keyword only)

use_unicode
  If True, text-like columns are returned as unicode objects
  using the connection's character set.  Otherwise, text-like
  columns are returned as strings.  columns are returned as
  normal strings. Unicode objects will always be encoded to
  the connection's character set regardless of this setting.

charset
  If supplied, the connection character set will be changed
  to this character set (MySQL-4.1 and newer). This implies
  use_unicode=True.

sql_mode
  If supplied, the session SQL mode will be changed to this
  setting (MySQL-4.1 and newer). For more details and legal
  values, see the MySQL documentation.
  
client_flag
  integer, flags to use or 0
  (see MySQL docs or constants/CLIENTS.py)

ssl
  dictionary or mapping, contains SSL connection parameters;
  see the MySQL documentation for more details
  (mysql_ssl_set()).  If this is set, and the client does not
  support SSL, NotSupportedError will be raised.

local_infile
  integer, non-zero enables LOAD LOCAL INFILE; zero disables

There are a number of undocumented, non-standard methods. See the
documentation for the MySQL C API for some hints on what they do.

Overrides: _mysql.connection.__init__

cursor(self, cursorclass=None)

source code 
Create a cursor on which queries may be performed. The optional cursorclass parameter is used to create the Cursor. By default, self.cursorclass=cursors.Cursor is used.

literal(self, o)

source code 

If o is a single object, returns an SQL literal as a string. If o is a non-string sequence, the items of the sequence are converted and returned as a sequence.

Non-standard. For internal use; do not use this in your applications.

begin(self)

source code 
Explicitly begin a connection. Non-standard. DEPRECATED: Will be removed in 1.3. Use an SQL BEGIN statement instead.

warning_count(self)

source code 
Return the number of warnings generated from the last query. This is derived from the info() method.
Overrides: _mysql.connection.warning_count

set_character_set(self, charset)

source code 
Set the connection character set to charset. The character set can only be changed in MySQL-4.1 and newer. If you try to change the character set from the current value in an older version, NotSupportedError will be raised.
Overrides: _mysql.connection.set_character_set

set_sql_mode(self, sql_mode)

source code 
Set the connection sql_mode. See MySQL documentation for legal values.

show_warnings(self)

source code 
Return detailed information about warnings as a sequence of tuples of (Level, Code, Message). This is only supported in MySQL-4.1 and up. If your server is an earlier version, an empty sequence is returned.

errorhandler(connection, cursor, errorclass, errorvalue)

source code 

If cursor is not None, (errorclass, errorvalue) is appended to cursor.messages; otherwise it is appended to connection.messages. Then errorclass is raised with errorvalue as the value.

You can override this with your own error handler by assigning it to the instance.