Module _mysql :: Class connection
[show private | hide private]
[frames | no frames]

Type connection

object --+
         |
        connection

Known Subclasses:
Connection

Returns a MYSQL connection object. Exclusive use of keyword parameters strongly recommended. Consult the MySQL C API documentation for more details.

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 (UNIX-ish only)
conv
mapping, maps MySQL FIELD_TYPE.* to Python functions which convert a string to the appropriate Python type
connect_timeout
number of seconds to wait before the connection attempt fails.
compress
if set, gzip compression is enabled
named_pipe
if set, connect to server via named pipe (Windows only)
init_command
command which is run once the connection is created
read_default_file
see the MySQL documentation for mysql_options()
read_default_group
see the MySQL documentation for mysql_options()
client_flag
client flags from MySQLdb.constants.CLIENT
load_infile
int, non-zero enables LOAD LOCAL INFILE, zero disables

Method Summary
  __init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __repr__(x)
x.__repr__() <==> repr(x)
  affected_rows(...)
Return number of rows affected by the last query.
  autocommit(...)
Set the autocommit mode.
  change_user(...)
Changes the user and causes the database specified by db to become the default (current) database on the connection specified by mysql.
  character_set_name(...)
Returns the default character set for the current connection.
  close(...)
Close the connection.
  commit(...)
Commits the current transaction
  dump_debug_info(...)
Instructs the server to write some debug information to the log.
  errno(...)
Returns the error code for the most recently invoked API function that can succeed or fail.
  error(...)
Returns the error message for the most recently invoked API function that can succeed or fail.
  escape(obj, dict)
using mapping dict to provide quoting functions for each type.
  escape_string(s)
Use connection.escape_string(s), if you use it at all.
  field_count(...)
Returns the number of columns for the most recent query on the connection.
  get_character_set_info(...)
Returns a dict with information about the current character set:
  get_host_info(...)
Returns a string that represents the MySQL client library version.
  get_proto_info(...)
Returns an unsigned integer representing the protocol version used by the current connection.
  get_server_info(...)
Returns a string that represents the server version number.
  info(...)
Retrieves a string providing information about the most recently executed query.
  insert_id(...)
Returns the ID generated for an AUTO_INCREMENT column by the previous query.
  kill(...)
Asks the server to kill the thread specified by pid.
  next_result(...)
If more query results exist, next_result() reads the next query results and returns the status back to application.
  ping(...)
Checks whether or not the connection to the server is working.
  query(...)
Execute a query.
  rollback(...)
Rolls backs the current transaction
  select_db(...)
Causes the database specified by db to become the default (current) database on the connection specified by mysql.
  set_character_set(...)
Sets the default character set for the current connection.
  set_server_option(option)
for the connection.
  shutdown(...)
Asks the database server to shut down.
  sqlstate(...)
Returns a string containing the SQLSTATE error code for the last error.
  stat(...)
Returns a character string containing information similar to that provided by the mysqladmin status command.
  store_result(...)
Returns a result object acquired by mysql_store_result (results stored in the client).
  string_literal(obj)
This means, any special SQL characters are escaped, and it is enclosed within single quotes.
  thread_id(...)
Returns the thread ID of the current connection.
  use_result(...)
Returns a result object acquired by mysql_use_result (results stored in the server).
  warning_count(...)
Returns the number of warnings generated during execution of the previous SQL statement.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Class Variable Summary
member_descriptor client_flag = <member 'client_flag' of '_mysql.connectio...
member_descriptor converter = <member 'converter' of '_mysql.connection' o...
member_descriptor open = <member 'open' of '_mysql.connection' objects>
member_descriptor port = <member 'port' of '_mysql.connection' objects>
member_descriptor server_capabilities = <member 'server_capabilities' of '...

Method Details

__init__(...)
(Constructor)

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides:
__builtin__.object.__init__

__new__(T, S, ...)

T.__new__(S, ...) -> a new object with type S, a subtype of T

Returns:
a new object with type S, a subtype of T
Overrides:
__builtin__.object.__new__

__repr__(x)
(Representation operator)

x.__repr__() <==> repr(x)

Returns:
repr(x)
Overrides:
__builtin__.object.__repr__

affected_rows(...)

Return number of rows affected by the last query. Non-standard. Use Cursor.rowcount.

autocommit(...)

Set the autocommit mode. True values enable; False value disable.

change_user(...)

Changes the user and causes the database specified by db to become the default (current) database on the connection specified by mysql. In subsequent queries, this database is the default for table references that do not include an explicit database specifier.

This function was introduced in MySQL Version 3.23.3.

Fails unless the connected user can be authenticated or if he doesn't have permission to use the database. In this case the user and database are not changed.

The db parameter may be set to None if you don't want to have a default database.

character_set_name(...)

Returns the default character set for the current connection. Non-standard.

close(...)

Close the connection. No further activity possible.

commit(...)

Commits the current transaction

dump_debug_info(...)

Instructs the server to write some debug information to the log. The connected user must have the process privilege for this to work. Non-standard.

errno(...)

Returns the error code for the most recently invoked API function that can succeed or fail. A return value of zero means that no error occurred.

error(...)

Returns the error message for the most recently invoked API function that can succeed or fail. An empty string () is returned if no error occurred.

escape(obj, dict)

using mapping dict to provide quoting functions for each type. Returns a SQL literal string.

escape_string(s)

Use connection.escape_string(s), if you use it at all. _mysql.escape_string(s) cannot handle character sets. You are probably better off using connection.escape(o) instead, since it will escape entire sequences as well as strings.

field_count(...)

Returns the number of columns for the most recent query on the connection. Non-standard. Will probably give you bogus results on most cursor classes. Use Cursor.rowcount.

get_character_set_info(...)

Returns a dict with information about the current character set:

collation
collation name
name
character set name
comment
comment or descriptive name
dir
character set directory
mbminlen
min. length for multibyte string
mbmaxlen
max. length for multibyte string

Not all keys may be present, particularly dir.

Non-standard.

get_host_info(...)

Returns a string that represents the MySQL client library version. Non-standard.

get_proto_info(...)

Returns an unsigned integer representing the protocol version used by the current connection. Non-standard.

get_server_info(...)

Returns a string that represents the server version number. Non-standard.

info(...)

Retrieves a string providing information about the most recently executed query. Non-standard. Use messages or Cursor.messages.

insert_id(...)

Returns the ID generated for an AUTO_INCREMENT column by the previous query. Use this function after you have performed an INSERT query into a table that contains an AUTO_INCREMENT field.

Note that this returns 0 if the previous query does not generate an AUTO_INCREMENT value. If you need to save the value for later, be sure to call this immediately after the query that generates the value.

The ID is updated after INSERT and UPDATE statements that generate an AUTO_INCREMENT value or that set a column value to LAST_INSERT_ID(expr). See section 6.3.5.2 Miscellaneous Functions in the MySQL documentation.

Also note that the value of the SQL LAST_INSERT_ID() function always contains the most recently generated AUTO_INCREMENT value, and is not reset between queries because the value of that function is maintained in the server.

kill(...)

Asks the server to kill the thread specified by pid. Non-standard.

next_result(...)

If more query results exist, next_result() reads the next query results and returns the status back to application.

After calling next_result() the state of the connection is as if you had called query() for the next query. This means that you can now call store_result(), warning_count(), affected_rows() , and so forth.

Returns 0 if there are more results; -1 if there are no more results

Non-standard.

ping(...)

Checks whether or not the connection to the server is working. If it has gone down, an automatic reconnection is attempted.

This function can be used by clients that remain idle for a long while, to check whether or not the server has closed the connection and reconnect if necessary.

New in 1.2.2: Accepts an optional reconnect parameter. If True, then the client will attempt reconnection. Note that this setting is persistent. By default, this is on in MySQL<5.0.3, and off thereafter.

Non-standard. You should assume that ping() performs an implicit rollback; use only when starting a new transaction. You have been warned.

query(...)

Execute a query. store_result() or use_result() will get the result set, if any. Non-standard. Use cursor() to create a cursor, then cursor.execute().

rollback(...)

Rolls backs the current transaction

select_db(...)

Causes the database specified by db to become the default (current) database on the connection specified by mysql. In subsequent queries, this database is the default for table references that do not include an explicit database specifier.

Fails unless the connected user can be authenticated as having permission to use the database.

Non-standard.

set_character_set(...)

Sets the default character set for the current connection. Non-standard.

set_server_option(option)

for the connection.

Non-standard.

shutdown(...)

Asks the database server to shut down. The connected user must have shutdown privileges. Non-standard.

sqlstate(...)

Returns a string containing the SQLSTATE error code for the last error. The error code consists of five characters. '00000' means "no error." The values are specified by ANSI SQL and ODBC. For a list of possible values, see section 23 Error Handling in MySQL in the MySQL Manual.

Note that not all MySQL errors are yet mapped to SQLSTATE's. The value 'HY000' (general error) is used for unmapped errors.

Non-standard.

stat(...)

Returns a character string containing information similar to that provided by the mysqladmin status command. This includes uptime in seconds and the number of running threads, questions, reloads, and open tables. Non-standard.

store_result(...)

Returns a result object acquired by mysql_store_result (results stored in the client). If no results are available, None is returned. Non-standard.

string_literal(obj)

This means, any special SQL characters are escaped, and it is enclosed within single quotes. In other words, it performs:

"'%s'" % escape_string(str(obj))

Use connection.string_literal(obj), if you use it at all. _mysql.string_literal(obj) cannot handle character sets.

thread_id(...)

Returns the thread ID of the current connection. This value can be used as an argument to kill() to kill the thread.

If the connection is lost and you reconnect with ping(), the thread ID will change. This means you should not get the thread ID and store it for later. You should get it when you need it.

Non-standard.

use_result(...)

Returns a result object acquired by mysql_use_result (results stored in the server). If no results are available, None is returned. Non-standard.

warning_count(...)

Returns the number of warnings generated during execution of the previous SQL statement.

Non-standard.


Class Variable Details

client_flag

Type:
member_descriptor
Value:
<member 'client_flag' of '_mysql.connection' objects>                  

converter

Type:
member_descriptor
Value:
<member 'converter' of '_mysql.connection' objects>                    

open

Type:
member_descriptor
Value:
<member 'open' of '_mysql.connection' objects>                         

port

Type:
member_descriptor
Value:
<member 'port' of '_mysql.connection' objects>                         

server_capabilities

Type:
member_descriptor
Value:
<member 'server_capabilities' of '_mysql.connection' objects>          

Generated by Epydoc 2.1 on Sat Mar 3 21:14:16 2007 http://epydoc.sf.net