mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-16 12:27:03 +08:00
A big (I hope) optimization and hooks for transaction support.
This commit is contained in:
@ -34,13 +34,13 @@ except ImportError:
|
|||||||
|
|
||||||
def Long2Int(l): return str(l)[:-1] # drop the trailing L
|
def Long2Int(l): return str(l)[:-1] # drop the trailing L
|
||||||
def None2NULL(d): return "NULL"
|
def None2NULL(d): return "NULL"
|
||||||
def String2literal(s): return "'%s'" % escape_string(str(s))
|
String2Literal = string_literal
|
||||||
|
|
||||||
quote_conv = { types.IntType: str,
|
quote_conv = { types.IntType: str,
|
||||||
types.LongType: Long2Int,
|
types.LongType: Long2Int,
|
||||||
types.FloatType: str,
|
types.FloatType: str,
|
||||||
types.NoneType: None2NULL,
|
types.NoneType: None2NULL,
|
||||||
types.StringType: String2literal }
|
types.StringType: String2Literal }
|
||||||
|
|
||||||
type_conv = { FIELD_TYPE.TINY: int,
|
type_conv = { FIELD_TYPE.TINY: int,
|
||||||
FIELD_TYPE.SHORT: int,
|
FIELD_TYPE.SHORT: int,
|
||||||
@ -260,7 +260,7 @@ class CursorStoreResultMixIn:
|
|||||||
self.connection._acquire()
|
self.connection._acquire()
|
||||||
try:
|
try:
|
||||||
BaseCursor._do_query(self, q)
|
BaseCursor._do_query(self, q)
|
||||||
self.__rows = self.result and self._fetch_all_rows() or ((),)
|
self.__rows = self.result and self._fetch_all_rows() or ()
|
||||||
self.__pos = 0
|
self.__pos = 0
|
||||||
del self.result
|
del self.result
|
||||||
finally:
|
finally:
|
||||||
@ -423,7 +423,7 @@ class Connection:
|
|||||||
"""Close the connection. No further activity possible."""
|
"""Close the connection. No further activity possible."""
|
||||||
self.db.close()
|
self.db.close()
|
||||||
|
|
||||||
if hasattr(_mysql, 'transactions'):
|
if hasattr(_mysql, 'rollback'):
|
||||||
def commit(self):
|
def commit(self):
|
||||||
"""Commit the current transaction."""
|
"""Commit the current transaction."""
|
||||||
return self.db.commit()
|
return self.db.commit()
|
||||||
|
@ -550,6 +550,24 @@ _mysql_escape_string(self, args)
|
|||||||
return (str);
|
return (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_mysql_string_literal(self, args)
|
||||||
|
PyObject *self;
|
||||||
|
PyObject *args;
|
||||||
|
{
|
||||||
|
PyObject *str;
|
||||||
|
char *in, *out;
|
||||||
|
int len, size;
|
||||||
|
if (!PyArg_ParseTuple(args, "s#:string_literal", &in, &size)) return NULL;
|
||||||
|
str = PyString_FromStringAndSize((char *) NULL, size*2+3);
|
||||||
|
if (!str) return PyErr_NoMemory();
|
||||||
|
out = PyString_AS_STRING(str);
|
||||||
|
len = mysql_escape_string(out+1, in, size);
|
||||||
|
*out = *(out+len+1) = '\'';
|
||||||
|
if (_PyString_Resize(&str, len+2) < 0) return NULL;
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *_mysql_NULL;
|
static PyObject *_mysql_NULL;
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
@ -907,6 +925,16 @@ _mysql_get_client_info(self, args)
|
|||||||
return PyString_FromString(mysql_get_client_info());
|
return PyString_FromString(mysql_get_client_info());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_mysql_ConnectionObject_commit(self, args)
|
||||||
|
_mysql_ConnectionObject *self;
|
||||||
|
PyObject *args;
|
||||||
|
{
|
||||||
|
if (!PyArg_NoArgs(args)) return NULL;
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
return Py_None;
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_get_host_info(self, args)
|
_mysql_ConnectionObject_get_host_info(self, args)
|
||||||
_mysql_ConnectionObject *self;
|
_mysql_ConnectionObject *self;
|
||||||
@ -1289,6 +1317,7 @@ static PyMethodDef _mysql_ConnectionObject_methods[] = {
|
|||||||
{"change_user", (PyCFunction)_mysql_ConnectionObject_change_user, METH_VARARGS | METH_KEYWORDS},
|
{"change_user", (PyCFunction)_mysql_ConnectionObject_change_user, METH_VARARGS | METH_KEYWORDS},
|
||||||
#endif
|
#endif
|
||||||
{"close", (PyCFunction)_mysql_ConnectionObject_close, 0},
|
{"close", (PyCFunction)_mysql_ConnectionObject_close, 0},
|
||||||
|
{"commit", (PyCFunction)_mysql_ConnectionObject_commit, 0},
|
||||||
{"dump_debug_info", (PyCFunction)_mysql_ConnectionObject_dump_debug_info, 0},
|
{"dump_debug_info", (PyCFunction)_mysql_ConnectionObject_dump_debug_info, 0},
|
||||||
{"error", (PyCFunction)_mysql_ConnectionObject_error, 0},
|
{"error", (PyCFunction)_mysql_ConnectionObject_error, 0},
|
||||||
{"errno", (PyCFunction)_mysql_ConnectionObject_errno, 0},
|
{"errno", (PyCFunction)_mysql_ConnectionObject_errno, 0},
|
||||||
@ -1445,6 +1474,7 @@ _mysql_methods[] = {
|
|||||||
{ "debug", _mysql_debug, METH_VARARGS },
|
{ "debug", _mysql_debug, METH_VARARGS },
|
||||||
{ "escape_row", _mysql_escape_row, METH_VARARGS },
|
{ "escape_row", _mysql_escape_row, METH_VARARGS },
|
||||||
{ "escape_string", _mysql_escape_string, METH_VARARGS },
|
{ "escape_string", _mysql_escape_string, METH_VARARGS },
|
||||||
|
{ "string_literal", _mysql_string_literal, METH_VARARGS },
|
||||||
{ "get_client_info", _mysql_get_client_info },
|
{ "get_client_info", _mysql_get_client_info },
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user