mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 19:31:54 +08:00
Mostly documentation updates, and some code cleanups
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
prune CVS
|
prune CVS
|
||||||
recursive-include doc *
|
recursive-include doc *.html *.sgml
|
||||||
recursive-include examples *
|
recursive-include examples *
|
||||||
include README.MySQLmodule
|
include README.MySQLmodule
|
||||||
include license.py
|
include license.py
|
||||||
|
@ -19,8 +19,8 @@ version_info = (
|
|||||||
0,
|
0,
|
||||||
9,
|
9,
|
||||||
2,
|
2,
|
||||||
"beta",
|
"gamma",
|
||||||
2)
|
1)
|
||||||
if version_info[3] == "final": __version__ = "%d.%d.%d" % version_info[:3]
|
if version_info[3] == "final": __version__ = "%d.%d.%d" % version_info[:3]
|
||||||
else: __version__ = "%d.%d.%d%1.1s%d" % version_info[:5]
|
else: __version__ = "%d.%d.%d%1.1s%d" % version_info[:5]
|
||||||
|
|
||||||
|
@ -18,35 +18,34 @@ def defaulterrorhandler(connection, cursor, errorclass, errorvalue):
|
|||||||
connection.messages.append(errorvalue)
|
connection.messages.append(errorvalue)
|
||||||
raise errorclass, errorvalue
|
raise errorclass, errorvalue
|
||||||
|
|
||||||
|
|
||||||
class Connection:
|
class Connection:
|
||||||
|
|
||||||
"""Create a connection to the database. It is strongly recommended
|
"""
|
||||||
that you only use keyword parameters. "NULL pointer" indicates that
|
|
||||||
NULL will be passed to mysql_real_connect(); the value in parenthesis
|
Create a connection to the database. It is strongly recommended
|
||||||
indicates how MySQL interprets the NULL. Consult the MySQL C API
|
that you only use keyword parameters. Consult the MySQL C API
|
||||||
documentation for more information.
|
documentation for more information.
|
||||||
|
|
||||||
host -- string, host to connect to or NULL pointer (localhost)
|
host -- string, host to connect
|
||||||
user -- string, user to connect as or NULL pointer (your username)
|
user -- string, user to connect as
|
||||||
passwd -- string, password to use or NULL pointer (no password)
|
passwd -- string, password to use
|
||||||
db -- string, database to use or NULL (no DB selected)
|
db -- string, database to use
|
||||||
port -- integer, TCP/IP port to connect to or default MySQL port
|
port -- integer, TCP/IP port to connect to
|
||||||
unix_socket -- string, location of unix_socket to use or use TCP
|
unix_socket -- string, location of unix_socket to use
|
||||||
client_flags -- integer, flags to use or 0 (see MySQL docs)
|
|
||||||
conv -- conversion dictionary, see MySQLdb.converters
|
conv -- conversion dictionary, see MySQLdb.converters
|
||||||
connect_time -- number of seconds to wait before the connection
|
connect_time -- number of seconds to wait before the connection
|
||||||
attempt fails.
|
attempt fails.
|
||||||
compress -- if set, compression is enabled
|
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
|
init_command -- command which is run once the connection is created
|
||||||
read_default_file -- see the MySQL documentation for mysql_options()
|
read_default_file -- file from which default client values are read
|
||||||
read_default_group -- see the MySQL documentation for mysql_options()
|
read_default_group -- configuration group to use from the default file
|
||||||
cursorclass -- class object, used to create cursors or cursors.Cursor.
|
cursorclass -- class object, used to create cursors (keyword only)
|
||||||
This parameter MUST be specified as a keyword parameter.
|
|
||||||
|
|
||||||
Returns a Connection object.
|
|
||||||
|
|
||||||
There are a number of undocumented, non-standard methods. See the
|
There are a number of undocumented, non-standard methods. See the
|
||||||
documentation for the MySQL C API for some hints on what they do.
|
documentation for the MySQL C API for some hints on what they do.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
default_cursor = cursors.Cursor
|
default_cursor = cursors.Cursor
|
||||||
@ -74,82 +73,56 @@ class Connection:
|
|||||||
def __del__(self):
|
def __del__(self):
|
||||||
if hasattr(self, '_db'): self.close()
|
if hasattr(self, '_db'): self.close()
|
||||||
|
|
||||||
def close(self):
|
def __getattr__(self, attr):
|
||||||
"""Close the connection. No further activity possible."""
|
return getattr(self._db, attr)
|
||||||
self._db.close()
|
|
||||||
|
|
||||||
def begin(self):
|
def begin(self):
|
||||||
"""Explicitly begin a transaction. Non-standard."""
|
"""Explicitly begin a transaction. Non-standard."""
|
||||||
self._db.query("BEGIN")
|
self.query("BEGIN")
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
"""Commit the current transaction."""
|
"""Commit the current transaction."""
|
||||||
if self._transactional:
|
if self._transactional:
|
||||||
self._db.query("COMMIT")
|
self.query("COMMIT")
|
||||||
|
|
||||||
def rollback(self):
|
def rollback(self):
|
||||||
"""Rollback the current transaction."""
|
"""Rollback the current transaction."""
|
||||||
if self._transactional:
|
if self._transactional:
|
||||||
self._db.query("ROLLBACK")
|
self.query("ROLLBACK")
|
||||||
else:
|
else:
|
||||||
raise NotSupportedError, "Not supported by server"
|
raise NotSupportedError, "Not supported by server"
|
||||||
|
|
||||||
def cursor(self, cursorclass=None):
|
def cursor(self, cursorclass=None):
|
||||||
|
"""
|
||||||
|
|
||||||
"""Create a cursor on which queries may be performed. The
|
Create a cursor on which queries may be performed. The
|
||||||
optional cursorclass parameter is used to create the
|
optional cursorclass parameter is used to create the
|
||||||
Cursor. By default, self.cursorclass=cursors.Cursor is
|
Cursor. By default, self.cursorclass=cursors.Cursor is
|
||||||
used."""
|
used.
|
||||||
|
|
||||||
|
"""
|
||||||
return (cursorclass or self.cursorclass)(self)
|
return (cursorclass or self.cursorclass)(self)
|
||||||
|
|
||||||
# Non-portable MySQL-specific stuff
|
|
||||||
# Methods not included on purpose (use Cursors instead):
|
|
||||||
# query, store_result, use_result
|
|
||||||
|
|
||||||
def literal(self, o):
|
def literal(self, o):
|
||||||
"""If o is a single object, returns an SQL literal as a string.
|
"""
|
||||||
If o is a non-string sequences, the items of the sequence are
|
|
||||||
converted and returned as a sequence."""
|
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.
|
||||||
|
|
||||||
|
"""
|
||||||
import _mysql
|
import _mysql
|
||||||
return _mysql.escape(o, self._db.converter)
|
return _mysql.escape(o, self._db.converter)
|
||||||
|
|
||||||
def unicode_literal(self, u, dummy=None):
|
def unicode_literal(self, u, dummy=None):
|
||||||
"""Convert a unicode object u to a string using the current
|
"""
|
||||||
|
|
||||||
|
Convert a unicode object u to a string using the current
|
||||||
character set as the encoding. If that's not available,
|
character set as the encoding. If that's not available,
|
||||||
use latin1."""
|
latin1 is used.
|
||||||
try: charset = self.character_set_name()
|
|
||||||
except: charset = 'latin1'
|
|
||||||
return self.literal(u.encode(charset))
|
|
||||||
|
|
||||||
def affected_rows(self): return self._db.affected_rows()
|
"""
|
||||||
def dump_debug_info(self): return self._db.dump_debug_info()
|
return self.literal(u.encode(self.character_set_name()))
|
||||||
def escape_string(self, s): return self._db.escape_string(s)
|
|
||||||
def get_host_info(self): return self._db.get_host_info()
|
|
||||||
def get_proto_info(self): return self._db.get_proto_info()
|
|
||||||
def get_server_info(self): return self._db.get_server_info()
|
|
||||||
def info(self): return self._db.info()
|
|
||||||
def kill(self, p): return self._db.kill(p)
|
|
||||||
def field_count(self): return self._db.field_count()
|
|
||||||
num_fields = field_count # used prior to MySQL-3.22.24
|
|
||||||
def ping(self): return self._db.ping()
|
|
||||||
def row_tell(self): return self._db.row_tell()
|
|
||||||
def select_db(self, db): return self._db.select_db(db)
|
|
||||||
def shutdown(self): return self._db.shutdown()
|
|
||||||
def stat(self): return self._db.stat()
|
|
||||||
def string_literal(self, s): return self._db.string_literal(s)
|
|
||||||
def thread_id(self): return self._db.thread_id()
|
|
||||||
|
|
||||||
def _try_feature(self, feature, *args, **kwargs):
|
|
||||||
try:
|
|
||||||
return apply(getattr(self._db, feature), args, kwargs)
|
|
||||||
except AttributeError:
|
|
||||||
self.errorhandler(self, None, NotSupportedError,
|
|
||||||
"not supported by MySQL library")
|
|
||||||
def character_set_name(self):
|
|
||||||
return self._try_feature('character_set_name')
|
|
||||||
def change_user(self, *args, **kwargs):
|
|
||||||
return apply(self._try_feature, ('change_user',)+args, kwargs)
|
|
||||||
|
|
||||||
Warning = Warning
|
Warning = Warning
|
||||||
Error = Error
|
Error = Error
|
||||||
|
@ -66,22 +66,34 @@ def Thing2Literal(o, d):
|
|||||||
|
|
||||||
return string_literal(o, d)
|
return string_literal(o, d)
|
||||||
|
|
||||||
|
|
||||||
def Instance2Str(o, d):
|
def Instance2Str(o, d):
|
||||||
|
|
||||||
"""Convert an Instance to a string representation. If the
|
"""
|
||||||
__str__() method produces acceptable output, then you don't need
|
|
||||||
to add the class to conversions; it will be handled by the default
|
|
||||||
converter. If the exact class is not found in d, it will use the
|
|
||||||
first class it can find for which o is an instance."""
|
|
||||||
|
|
||||||
if d.has_key(o.__class__): return d[o.__class__](o, d)
|
Convert an Instance to a string representation. If the __str__()
|
||||||
|
method produces acceptable output, then you don't need to add the
|
||||||
|
class to conversions; it will be handled by the default
|
||||||
|
converter. If the exact class is not found in d, it will use the
|
||||||
|
first class it can find for which o is an instance.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if d.has_key(o.__class__):
|
||||||
|
return d[o.__class__](o, d)
|
||||||
cl = filter(lambda x,o=o:
|
cl = filter(lambda x,o=o:
|
||||||
type(x)==types.ClassType and isinstance(o,x), d.keys())
|
type(x) is types.ClassType
|
||||||
|
and isinstance(o, x), d.keys())
|
||||||
|
if not cl and hasattr(types, 'ObjectType'):
|
||||||
|
cl = filter(lambda x,o=o:
|
||||||
|
type(x) is types.TypeType
|
||||||
|
and isinstance(o, x), d.keys())
|
||||||
if not cl:
|
if not cl:
|
||||||
return d[types.StringType](o,d)
|
return d[types.StringType](o,d)
|
||||||
d[o.__class__] = d[cl[0]]
|
d[o.__class__] = d[cl[0]]
|
||||||
return d[cl[0]](o, d)
|
return d[cl[0]](o, d)
|
||||||
|
|
||||||
|
|
||||||
conversions = {
|
conversions = {
|
||||||
types.IntType: Thing2Str,
|
types.IntType: Thing2Str,
|
||||||
types.LongType: Long2Int,
|
types.LongType: Long2Int,
|
||||||
@ -110,6 +122,9 @@ conversions = {
|
|||||||
FIELD_TYPE.DATE: Date_or_None,
|
FIELD_TYPE.DATE: Date_or_None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if hasattr(types, 'UnicodeType'):
|
if hasattr(types, 'UnicodeType'):
|
||||||
conversions[types.UnicodeType] = Unicode2Str
|
conversions[types.UnicodeType] = Unicode2Str
|
||||||
|
|
||||||
|
if hasattr(types, 'ObjectType'):
|
||||||
|
conversions[types.ObjectType] = Instance2Str
|
||||||
|
334
MySQLdb/_mysql.c
334
MySQLdb/_mysql.c
@ -201,22 +201,22 @@ _mysql_ResultObject_New(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char _mysql_connect__doc__[] =
|
static char _mysql_connect__doc__[] =
|
||||||
"connect() -- returns a MYSQL connection object. Exclusive use of\n\
|
"Returns a MYSQL connection object. Exclusive use of\n\
|
||||||
keyword parameters strongly recommended. Consult the\n\
|
keyword parameters strongly recommended. Consult the\n\
|
||||||
MySQL C API documentation for more details.\n\
|
MySQL C API documentation for more details.\n\
|
||||||
\n\
|
\n\
|
||||||
host -- string, host to connect to or NULL pointer (localhost)\n\
|
host -- string, host to connect\n\
|
||||||
user -- string, user to connect as or NULL (your username)\n\
|
user -- string, user to connect as\n\
|
||||||
passwd -- string, password to use or NULL (no password)\n\
|
passwd -- string, password to use\n\
|
||||||
db -- string, database to use or NULL (no DB selected)\n\
|
db -- string, database to use\n\
|
||||||
port -- integer, TCP/IP port to connect to or default MySQL port\n\
|
port -- integer, TCP/IP port to connect to\n\
|
||||||
unix_socket -- string, location of unix_socket to use or use TCP\n\
|
unix_socket -- string, location of unix_socket (UNIX-ish only)\n\
|
||||||
client_flags -- integer, flags to use or 0 (see MySQL docs)\n\
|
conv -- mapping, maps MySQL FIELD_TYPE.* to Python functions which\n\
|
||||||
conv -- dictionary, maps MySQL FIELD_TYPE.* to Python functions which\n\
|
|
||||||
convert a string to the appropriate Python type\n\
|
convert a string to the appropriate Python type\n\
|
||||||
connect_time -- number of seconds to wait before the connection\n\
|
connect_timeout -- number of seconds to wait before the connection\n\
|
||||||
attempt fails.\n\
|
attempt fails.\n\
|
||||||
compress -- if set, compression is enabled\n\
|
compress -- if set, gzip compression is enabled\n\
|
||||||
|
named_pipe -- if set, connect to server via named pipe (Windows only)\n\
|
||||||
init_command -- command which is run once the connection is created\n\
|
init_command -- command which is run once the connection is created\n\
|
||||||
read_default_file -- see the MySQL documentation for mysql_options()\n\
|
read_default_file -- see the MySQL documentation for mysql_options()\n\
|
||||||
read_default_group -- see the MySQL documentation for mysql_options()\n\
|
read_default_group -- see the MySQL documentation for mysql_options()\n\
|
||||||
@ -308,6 +308,9 @@ _mysql_connect(
|
|||||||
return (PyObject *) c;
|
return (PyObject *) c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_close__doc__[] =
|
||||||
|
"Close the connection. No further activity possible.";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_close(
|
_mysql_ConnectionObject_close(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -326,6 +329,11 @@ _mysql_ConnectionObject_close(
|
|||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_affected_rows__doc__ [] =
|
||||||
|
"Return number of rows affected by the last query.\n\
|
||||||
|
Non-standard. Use Cursor.rowcount.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_affected_rows(
|
_mysql_ConnectionObject_affected_rows(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -337,7 +345,7 @@ _mysql_ConnectionObject_affected_rows(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char _mysql_debug__doc__[] =
|
static char _mysql_debug__doc__[] =
|
||||||
"debug(s) -- Does a DBUG_PUSH with the given string.\n\
|
"Does a DBUG_PUSH with the given string.\n\
|
||||||
mysql_debug() uses the Fred Fish debug library.\n\
|
mysql_debug() uses the Fred Fish debug library.\n\
|
||||||
To use this function, you must compile the client library to\n\
|
To use this function, you must compile the client library to\n\
|
||||||
support debugging.\n\
|
support debugging.\n\
|
||||||
@ -354,6 +362,12 @@ _mysql_debug(
|
|||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_dump_debug_info__doc__[] =
|
||||||
|
"Instructs the server to write some debug information to the\n\
|
||||||
|
log. The connected user must have the process privilege for\n\
|
||||||
|
this to work. Non-standard.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_dump_debug_info(
|
_mysql_ConnectionObject_dump_debug_info(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -370,6 +384,12 @@ _mysql_ConnectionObject_dump_debug_info(
|
|||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_errno__doc__[] =
|
||||||
|
"Returns the error code for the most recently invoked API function\n\
|
||||||
|
that can succeed or fail. A return value of zero means that no error\n\
|
||||||
|
occurred.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_errno(
|
_mysql_ConnectionObject_errno(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -380,6 +400,12 @@ _mysql_ConnectionObject_errno(
|
|||||||
return PyInt_FromLong((long)mysql_errno(&(self->connection)));
|
return PyInt_FromLong((long)mysql_errno(&(self->connection)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_error__doc__[] =
|
||||||
|
"Returns the error message for the most recently invoked API function\n\
|
||||||
|
that can succeed or fail. An empty string ("") is returned if no error\n\
|
||||||
|
occurred.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_error(
|
_mysql_ConnectionObject_error(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -878,6 +904,24 @@ _mysql_ResultObject_fetch_row(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if MYSQL_VERSION_ID >= 32303
|
#if MYSQL_VERSION_ID >= 32303
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_change_user__doc__[] =
|
||||||
|
"Changes the user and causes the database specified by db to\n\
|
||||||
|
become the default (current) database on the connection\n\
|
||||||
|
specified by mysql. In subsequent queries, this database is\n\
|
||||||
|
the default for table references that do not include an\n\
|
||||||
|
explicit database specifier.\n\
|
||||||
|
\n\
|
||||||
|
This function was introduced in MySQL Version 3.23.3.\n\
|
||||||
|
\n\
|
||||||
|
Fails unless the connected user can be authenticated or if he\n\
|
||||||
|
doesn't have permission to use the database. In this case the\n\
|
||||||
|
user and database are not changed.\n\
|
||||||
|
\n\
|
||||||
|
The db parameter may be set to None if you don't want to have\n\
|
||||||
|
a default database.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_change_user(
|
_mysql_ConnectionObject_change_user(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -901,7 +945,11 @@ _mysql_ConnectionObject_change_user(
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MYSQL_VERSION_ID >= 32321
|
static char _mysql_ConnectionObject_character_set_name__doc__[] =
|
||||||
|
"Returns the default character set for the current connection.\n\
|
||||||
|
Non-standard.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_character_set_name(
|
_mysql_ConnectionObject_character_set_name(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -910,10 +958,13 @@ _mysql_ConnectionObject_character_set_name(
|
|||||||
const char *s;
|
const char *s;
|
||||||
if (!PyArg_NoArgs(args)) return NULL;
|
if (!PyArg_NoArgs(args)) return NULL;
|
||||||
check_connection(self);
|
check_connection(self);
|
||||||
|
#if MYSQL_VERSION_ID >= 32321
|
||||||
s = mysql_character_set_name(&(self->connection));
|
s = mysql_character_set_name(&(self->connection));
|
||||||
|
#else
|
||||||
|
s = "latin1";
|
||||||
|
#endif
|
||||||
return PyString_FromString(s);
|
return PyString_FromString(s);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static char _mysql_get_client_info__doc__[] =
|
static char _mysql_get_client_info__doc__[] =
|
||||||
"get_client_info() -- Returns a string that represents\n\
|
"get_client_info() -- Returns a string that represents\n\
|
||||||
@ -927,6 +978,11 @@ _mysql_get_client_info(
|
|||||||
return PyString_FromString(mysql_get_client_info());
|
return PyString_FromString(mysql_get_client_info());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_get_host_info__doc__[] =
|
||||||
|
"Returns a string that represents the MySQL client library\n\
|
||||||
|
version. Non-standard.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_get_host_info(
|
_mysql_ConnectionObject_get_host_info(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -937,6 +993,11 @@ _mysql_ConnectionObject_get_host_info(
|
|||||||
return PyString_FromString(mysql_get_host_info(&(self->connection)));
|
return PyString_FromString(mysql_get_host_info(&(self->connection)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_get_proto_info__doc__[] =
|
||||||
|
"Returns an unsigned integer representing the protocol version\n\
|
||||||
|
used by the current connection. Non-standard.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_get_proto_info(
|
_mysql_ConnectionObject_get_proto_info(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -947,6 +1008,11 @@ _mysql_ConnectionObject_get_proto_info(
|
|||||||
return PyInt_FromLong((long)mysql_get_proto_info(&(self->connection)));
|
return PyInt_FromLong((long)mysql_get_proto_info(&(self->connection)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_get_server_info__doc__[] =
|
||||||
|
"Returns a string that represents the server version number.\n\
|
||||||
|
Non-standard.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_get_server_info(
|
_mysql_ConnectionObject_get_server_info(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -957,6 +1023,12 @@ _mysql_ConnectionObject_get_server_info(
|
|||||||
return PyString_FromString(mysql_get_server_info(&(self->connection)));
|
return PyString_FromString(mysql_get_server_info(&(self->connection)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_info__doc__[] =
|
||||||
|
"Retrieves a string providing information about the most\n\
|
||||||
|
recently executed query. Non-standard. Use messages or\n\
|
||||||
|
Cursor.messages.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_info(
|
_mysql_ConnectionObject_info(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -971,6 +1043,27 @@ _mysql_ConnectionObject_info(
|
|||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_insert_id__doc__[] =
|
||||||
|
"Returns the ID generated for an AUTO_INCREMENT column by the previous\n\
|
||||||
|
query. Use this function after you have performed an INSERT query into a\n\
|
||||||
|
table that contains an AUTO_INCREMENT field.\n\
|
||||||
|
\n\
|
||||||
|
Note that this returns 0 if the previous query does not\n\
|
||||||
|
generate an AUTO_INCREMENT value. If you need to save the value for\n\
|
||||||
|
later, be sure to call this immediately after the query\n\
|
||||||
|
that generates the value.\n\
|
||||||
|
\n\
|
||||||
|
The ID is updated after INSERT and UPDATE statements that generate\n\
|
||||||
|
an AUTO_INCREMENT value or that set a column value to\n\
|
||||||
|
LAST_INSERT_ID(expr). See section 6.3.5.2 Miscellaneous Functions\n\
|
||||||
|
in the MySQL documentation.\n\
|
||||||
|
\n\
|
||||||
|
Also note that the value of the SQL LAST_INSERT_ID() function always\n\
|
||||||
|
contains the most recently generated AUTO_INCREMENT value, and is not\n\
|
||||||
|
reset between queries because the value of that function is maintained\n\
|
||||||
|
in the server.\n\
|
||||||
|
" ;
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_insert_id(
|
_mysql_ConnectionObject_insert_id(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -985,6 +1078,9 @@ _mysql_ConnectionObject_insert_id(
|
|||||||
return PyLong_FromUnsignedLongLong(r);
|
return PyLong_FromUnsignedLongLong(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_kill__doc__[] =
|
||||||
|
"Asks the server to kill the thread specified by pid.\n";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_kill(
|
_mysql_ConnectionObject_kill(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -1002,6 +1098,12 @@ _mysql_ConnectionObject_kill(
|
|||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_field_count__doc__[] =
|
||||||
|
"Returns the number of columns for the most recent query on the\n\
|
||||||
|
connection. Non-standard. Will probably give you bogus results\n\
|
||||||
|
on most cursor classes. Use Cursor.rowcount.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_field_count(
|
_mysql_ConnectionObject_field_count(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -1036,6 +1138,18 @@ _mysql_ResultObject_num_rows(
|
|||||||
return PyLong_FromUnsignedLongLong(mysql_num_rows(self->result));
|
return PyLong_FromUnsignedLongLong(mysql_num_rows(self->result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_ping__doc__[] =
|
||||||
|
"Checks whether or not the connection to the server is\n\
|
||||||
|
working. If it has gone down, an automatic reconnection is\n\
|
||||||
|
attempted.\n\
|
||||||
|
\n\
|
||||||
|
This function can be used by clients that remain idle for a\n\
|
||||||
|
long while, to check whether or not the server has closed the\n\
|
||||||
|
connection and reconnect if necessary.\n\
|
||||||
|
\n\
|
||||||
|
Non-standard.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_ping(
|
_mysql_ConnectionObject_ping(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -1069,6 +1183,19 @@ _mysql_ConnectionObject_query(
|
|||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_select_db__doc__[] =
|
||||||
|
"Causes the database specified by db to become the default\n\
|
||||||
|
(current) database on the connection specified by mysql. In subsequent\n\
|
||||||
|
queries, this database is the default for table references that do not\n\
|
||||||
|
include an explicit database specifier.\n\
|
||||||
|
\n\
|
||||||
|
Fails unless the connected user can be authenticated as having\n\
|
||||||
|
permission to use the database.\n\
|
||||||
|
\n\
|
||||||
|
Non-standard.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_select_db(
|
_mysql_ConnectionObject_select_db(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -1086,6 +1213,11 @@ _mysql_ConnectionObject_select_db(
|
|||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_shutdown__doc__[] =
|
||||||
|
"Asks the database server to shut down. The connected user must\n\
|
||||||
|
have shutdown privileges.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_shutdown(
|
_mysql_ConnectionObject_shutdown(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -1102,6 +1234,13 @@ _mysql_ConnectionObject_shutdown(
|
|||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_stat__doc__[] =
|
||||||
|
"Returns a character string containing information similar to\n\
|
||||||
|
that provided by the mysqladmin status command. This includes\n\
|
||||||
|
uptime in seconds and the number of running threads,\n\
|
||||||
|
questions, reloads, and open tables. Non-standard.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_stat(
|
_mysql_ConnectionObject_stat(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -1137,6 +1276,16 @@ _mysql_ConnectionObject_store_result(
|
|||||||
self->converter);
|
self->converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char _mysql_ConnectionObject_thread_id__doc__[] =
|
||||||
|
"Returns the thread ID of the current connection. This value\n\
|
||||||
|
can be used as an argument to kill() to kill the thread.\n\
|
||||||
|
\n\
|
||||||
|
If the connection is lost and you reconnect with ping(), the\n\
|
||||||
|
thread ID will change. This means you should not get the\n\
|
||||||
|
thread ID and store it for later. You should get it when you\n\
|
||||||
|
need it.\n\
|
||||||
|
";
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_thread_id(
|
_mysql_ConnectionObject_thread_id(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -1266,34 +1415,141 @@ _mysql_ResultObject_repr(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static PyMethodDef _mysql_ConnectionObject_methods[] = {
|
static PyMethodDef _mysql_ConnectionObject_methods[] = {
|
||||||
{"affected_rows", (PyCFunction)_mysql_ConnectionObject_affected_rows, 0},
|
{
|
||||||
|
"affected_rows",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_affected_rows,
|
||||||
|
0,
|
||||||
|
_mysql_ConnectionObject_affected_rows__doc__
|
||||||
|
},
|
||||||
#if MYSQL_VERSION_ID >= 32303
|
#if MYSQL_VERSION_ID >= 32303
|
||||||
{"change_user", (PyCFunction)_mysql_ConnectionObject_change_user, METH_VARARGS | METH_KEYWORDS},
|
{
|
||||||
|
"change_user",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_change_user,
|
||||||
|
METH_VARARGS | METH_KEYWORDS,
|
||||||
|
_mysql_ConnectionObject_change_user__doc__
|
||||||
|
},
|
||||||
#endif
|
#endif
|
||||||
#if MYSQL_VERSION_ID >= 32321
|
{
|
||||||
{"character_set_name", (PyCFunction)_mysql_ConnectionObject_character_set_name, 0},
|
"character_set_name",
|
||||||
#endif
|
(PyCFunction)_mysql_ConnectionObject_character_set_name,
|
||||||
{"close", (PyCFunction)_mysql_ConnectionObject_close, 0},
|
METH_VARARGS,
|
||||||
{"dump_debug_info", (PyCFunction)_mysql_ConnectionObject_dump_debug_info, 0},
|
_mysql_ConnectionObject_character_set_name__doc__
|
||||||
{"escape", (PyCFunction)_mysql_escape, 1},
|
},
|
||||||
{"escape_string", (PyCFunction)_mysql_escape_string, 1},
|
{
|
||||||
{"error", (PyCFunction)_mysql_ConnectionObject_error, 0},
|
"close",
|
||||||
{"errno", (PyCFunction)_mysql_ConnectionObject_errno, 0},
|
(PyCFunction)_mysql_ConnectionObject_close,
|
||||||
{"field_count", (PyCFunction)_mysql_ConnectionObject_field_count, 0},
|
METH_VARARGS,
|
||||||
{"get_host_info", (PyCFunction)_mysql_ConnectionObject_get_host_info, 0},
|
_mysql_ConnectionObject_close__doc__
|
||||||
{"get_proto_info", (PyCFunction)_mysql_ConnectionObject_get_proto_info, 0},
|
},
|
||||||
{"get_server_info", (PyCFunction)_mysql_ConnectionObject_get_server_info, 0},
|
{
|
||||||
{"info", (PyCFunction)_mysql_ConnectionObject_info, 0},
|
"dump_debug_info",
|
||||||
{"insert_id", (PyCFunction)_mysql_ConnectionObject_insert_id, 0},
|
(PyCFunction)_mysql_ConnectionObject_dump_debug_info,
|
||||||
{"kill", (PyCFunction)_mysql_ConnectionObject_kill, 1},
|
METH_VARARGS,
|
||||||
{"ping", (PyCFunction)_mysql_ConnectionObject_ping, 0},
|
_mysql_ConnectionObject_dump_debug_info__doc__
|
||||||
{"query", (PyCFunction)_mysql_ConnectionObject_query, 1},
|
},
|
||||||
{"select_db", (PyCFunction)_mysql_ConnectionObject_select_db, 1},
|
{
|
||||||
{"shutdown", (PyCFunction)_mysql_ConnectionObject_shutdown, 0},
|
"escape",
|
||||||
{"stat", (PyCFunction)_mysql_ConnectionObject_stat, 0},
|
(PyCFunction)_mysql_escape,
|
||||||
|
METH_VARARGS,
|
||||||
|
_mysql_escape__doc__
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"escape_string",
|
||||||
|
(PyCFunction)_mysql_escape_string,
|
||||||
|
METH_VARARGS,
|
||||||
|
_mysql_escape_string__doc__
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"error",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_error,
|
||||||
|
METH_VARARGS,
|
||||||
|
_mysql_ConnectionObject_error__doc__
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"errno",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_errno,
|
||||||
|
METH_VARARGS,
|
||||||
|
_mysql_ConnectionObject_errno__doc__
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"field_count",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_field_count,
|
||||||
|
METH_VARARGS,
|
||||||
|
_mysql_ConnectionObject_field_count__doc__
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"get_host_info",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_get_host_info,
|
||||||
|
METH_VARARGS,
|
||||||
|
_mysql_ConnectionObject_get_host_info__doc__
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"get_proto_info",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_get_proto_info,
|
||||||
|
METH_VARARGS,
|
||||||
|
_mysql_ConnectionObject_get_proto_info__doc__
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"get_server_info",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_get_server_info,
|
||||||
|
METH_VARARGS,
|
||||||
|
_mysql_ConnectionObject_get_server_info__doc__
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"info",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_info,
|
||||||
|
METH_VARARGS,
|
||||||
|
_mysql_ConnectionObject_info__doc__
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"insert_id",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_insert_id,
|
||||||
|
METH_VARARGS,
|
||||||
|
_mysql_ConnectionObject_insert_id__doc__
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kill",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_kill,
|
||||||
|
1,
|
||||||
|
_mysql_ConnectionObject_kill__doc__
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ping",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_ping,
|
||||||
|
0,
|
||||||
|
_mysql_ConnectionObject_ping__doc__
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"query",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_query,
|
||||||
|
1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"select_db",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_select_db,
|
||||||
|
1,
|
||||||
|
_mysql_ConnectionObject_select_db__doc__
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"shutdown",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_shutdown,
|
||||||
|
0,
|
||||||
|
_mysql_ConnectionObject_shutdown__doc__
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"stat",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_stat,
|
||||||
|
METH_VARARGS,
|
||||||
|
_mysql_ConnectionObject_stat__doc__
|
||||||
|
},
|
||||||
{"store_result", (PyCFunction)_mysql_ConnectionObject_store_result, 0},
|
{"store_result", (PyCFunction)_mysql_ConnectionObject_store_result, 0},
|
||||||
{"string_literal", (PyCFunction)_mysql_string_literal, 1},
|
{"string_literal", (PyCFunction)_mysql_string_literal, 1},
|
||||||
{"thread_id", (PyCFunction)_mysql_ConnectionObject_thread_id, 0},
|
{
|
||||||
|
"thread_id",
|
||||||
|
(PyCFunction)_mysql_ConnectionObject_thread_id,
|
||||||
|
METH_VARARGS,
|
||||||
|
_mysql_ConnectionObject_thread_id__doc__
|
||||||
|
},
|
||||||
{"use_result", (PyCFunction)_mysql_ConnectionObject_use_result, 0},
|
{"use_result", (PyCFunction)_mysql_ConnectionObject_use_result, 0},
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
@ -1485,7 +1741,7 @@ _mysql_NewException(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char _mysql___doc__[] =
|
static char _mysql___doc__[] =
|
||||||
"_mysql: an adaptation of the MySQL C API (mostly)\n\
|
"an adaptation of the MySQL C API (mostly)\n\
|
||||||
\n\
|
\n\
|
||||||
You probably are better off using MySQLdb instead of using this\n\
|
You probably are better off using MySQLdb instead of using this\n\
|
||||||
module directly.\n\
|
module directly.\n\
|
||||||
|
Reference in New Issue
Block a user