mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 19:31:54 +08:00
Remove threadsafe and embedded build options
This commit is contained in:
23
INSTALL.rst
23
INSTALL.rst
@ -42,20 +42,10 @@ Depending on which version of MySQL you have, you may have the option
|
|||||||
of using three different client libraries. To select the client library,
|
of using three different client libraries. To select the client library,
|
||||||
edit the [options] section of site.cfg:
|
edit the [options] section of site.cfg:
|
||||||
|
|
||||||
embedded
|
|
||||||
use embedded server library (libmysqld) if True; otherwise use
|
|
||||||
one of the client libraries (default).
|
|
||||||
|
|
||||||
threadsafe
|
|
||||||
thread-safe client library (libmysqlclient_r) if True (default);
|
|
||||||
otherwise use non-thread-safe (libmysqlclient). You should
|
|
||||||
always use the thread-safe library if you have the option;
|
|
||||||
otherwise you *may* have problems.
|
|
||||||
|
|
||||||
static
|
static
|
||||||
if True, try to link against a static library; otherwise link
|
if True, try to link against a static library; otherwise link
|
||||||
against dynamic libraries (default). You may need static linking
|
against dynamic libraries (default). You may need static linking
|
||||||
to use the embedded server.
|
to use the embedded server.
|
||||||
This option doesn't work for MySQL>5.6 since libmysqlclient
|
This option doesn't work for MySQL>5.6 since libmysqlclient
|
||||||
requires libstdc++. If you want to use, add `-lstdc++` to
|
requires libstdc++. If you want to use, add `-lstdc++` to
|
||||||
mysql_config manually.
|
mysql_config manually.
|
||||||
@ -130,7 +120,7 @@ Debian GNU/Linux
|
|||||||
|
|
||||||
Packaged as `python-mysqldb`_::
|
Packaged as `python-mysqldb`_::
|
||||||
|
|
||||||
# apt-get install python-mysqldb
|
# apt-get install python-mysqldb
|
||||||
|
|
||||||
Or use Synaptic.
|
Or use Synaptic.
|
||||||
|
|
||||||
@ -148,9 +138,9 @@ Gentoo Linux
|
|||||||
|
|
||||||
Packaged as `mysql-python`_. ::
|
Packaged as `mysql-python`_. ::
|
||||||
|
|
||||||
# emerge sync
|
# emerge sync
|
||||||
# emerge mysql-python
|
# emerge mysql-python
|
||||||
# emerge zmysqlda # if you use Zope
|
# emerge zmysqlda # if you use Zope
|
||||||
|
|
||||||
.. _`mysql-python`: https://packages.gentoo.org/packages/search?q=mysql-python
|
.. _`mysql-python`: https://packages.gentoo.org/packages/search?q=mysql-python
|
||||||
|
|
||||||
@ -169,4 +159,3 @@ GPL or the original license based on Python 1.5.2's license.
|
|||||||
|
|
||||||
|
|
||||||
:Author: Andy Dustman <andy@dustman.net>
|
:Author: Andy Dustman <andy@dustman.net>
|
||||||
:Revision: $Id$
|
|
||||||
|
149
_mysql.c
149
_mysql.c
@ -91,8 +91,6 @@ typedef struct {
|
|||||||
|
|
||||||
extern PyTypeObject _mysql_ResultObject_Type;
|
extern PyTypeObject _mysql_ResultObject_Type;
|
||||||
|
|
||||||
static int _mysql_server_init_done = 0;
|
|
||||||
#define check_server_init(x) if (!_mysql_server_init_done) { if (mysql_server_init(0, NULL, NULL)) { _mysql_Exception(NULL); return x; } else { _mysql_server_init_done = 1;} }
|
|
||||||
|
|
||||||
/* According to https://dev.mysql.com/doc/refman/5.1/en/mysql-options.html
|
/* According to https://dev.mysql.com/doc/refman/5.1/en/mysql-options.html
|
||||||
The MYSQL_OPT_READ_TIMEOUT appear in the version 5.1.12 */
|
The MYSQL_OPT_READ_TIMEOUT appear in the version 5.1.12 */
|
||||||
@ -107,14 +105,6 @@ _mysql_Exception(_mysql_ConnectionObject *c)
|
|||||||
int merr;
|
int merr;
|
||||||
|
|
||||||
if (!(t = PyTuple_New(2))) return NULL;
|
if (!(t = PyTuple_New(2))) return NULL;
|
||||||
if (!_mysql_server_init_done) {
|
|
||||||
e = _mysql_InternalError;
|
|
||||||
PyTuple_SET_ITEM(t, 0, PyInt_FromLong(-1L));
|
|
||||||
PyTuple_SET_ITEM(t, 1, PyString_FromString("server not initialized"));
|
|
||||||
PyErr_SetObject(e, t);
|
|
||||||
Py_DECREF(t);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (!(c->open)) {
|
if (!(c->open)) {
|
||||||
/* GH-270: When connection is closed, accessing the c->connection
|
/* GH-270: When connection is closed, accessing the c->connection
|
||||||
* object may cause SEGV.
|
* object may cause SEGV.
|
||||||
@ -219,124 +209,6 @@ _mysql_Exception(_mysql_ConnectionObject *c)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char _mysql_server_init__doc__[] =
|
|
||||||
"Initialize embedded server. If this client is not linked against\n\
|
|
||||||
the embedded server library, this function does nothing.\n\
|
|
||||||
\n\
|
|
||||||
args -- sequence of command-line arguments\n\
|
|
||||||
groups -- sequence of groups to use in defaults files\n\
|
|
||||||
";
|
|
||||||
|
|
||||||
static PyObject *_mysql_server_init(
|
|
||||||
PyObject *self,
|
|
||||||
PyObject *args,
|
|
||||||
PyObject *kwargs) {
|
|
||||||
static char *kwlist[] = {"args", "groups", NULL};
|
|
||||||
char **cmd_args_c=NULL, **groups_c=NULL, *s;
|
|
||||||
int cmd_argc=0, i, groupc;
|
|
||||||
PyObject *cmd_args=NULL, *groups=NULL, *ret=NULL, *item;
|
|
||||||
|
|
||||||
if (_mysql_server_init_done) {
|
|
||||||
PyErr_SetString(_mysql_ProgrammingError,
|
|
||||||
"already initialized");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", kwlist,
|
|
||||||
&cmd_args, &groups))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (cmd_args) {
|
|
||||||
if (!PySequence_Check(cmd_args)) {
|
|
||||||
PyErr_SetString(PyExc_TypeError,
|
|
||||||
"args must be a sequence");
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
cmd_argc = PySequence_Size(cmd_args);
|
|
||||||
if (cmd_argc == -1) {
|
|
||||||
PyErr_SetString(PyExc_TypeError,
|
|
||||||
"args could not be sized");
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
cmd_args_c = (char **) PyMem_Malloc(cmd_argc*sizeof(char *));
|
|
||||||
for (i=0; i< cmd_argc; i++) {
|
|
||||||
item = PySequence_GetItem(cmd_args, i);
|
|
||||||
#ifdef IS_PY3K
|
|
||||||
s = PyUnicode_AsUTF8(item);
|
|
||||||
#else
|
|
||||||
s = PyString_AsString(item);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Py_DECREF(item);
|
|
||||||
if (!s) {
|
|
||||||
PyErr_SetString(PyExc_TypeError,
|
|
||||||
"args must contain strings");
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
cmd_args_c[i] = s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (groups) {
|
|
||||||
if (!PySequence_Check(groups)) {
|
|
||||||
PyErr_SetString(PyExc_TypeError,
|
|
||||||
"groups must be a sequence");
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
groupc = PySequence_Size(groups);
|
|
||||||
if (groupc == -1) {
|
|
||||||
PyErr_SetString(PyExc_TypeError,
|
|
||||||
"groups could not be sized");
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
groups_c = (char **) PyMem_Malloc((1+groupc)*sizeof(char *));
|
|
||||||
for (i=0; i< groupc; i++) {
|
|
||||||
item = PySequence_GetItem(groups, i);
|
|
||||||
#ifdef IS_PY3K
|
|
||||||
s = PyUnicode_AsUTF8(item);
|
|
||||||
#else
|
|
||||||
s = PyString_AsString(item);
|
|
||||||
#endif
|
|
||||||
Py_DECREF(item);
|
|
||||||
if (!s) {
|
|
||||||
PyErr_SetString(PyExc_TypeError,
|
|
||||||
"groups must contain strings");
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
groups_c[i] = s;
|
|
||||||
}
|
|
||||||
groups_c[groupc] = (char *)NULL;
|
|
||||||
}
|
|
||||||
/* even though this may block, don't give up the interpreter lock
|
|
||||||
so that the server can't be initialized multiple times. */
|
|
||||||
if (mysql_server_init(cmd_argc, cmd_args_c, groups_c)) {
|
|
||||||
_mysql_Exception(NULL);
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
ret = Py_None;
|
|
||||||
Py_INCREF(Py_None);
|
|
||||||
_mysql_server_init_done = 1;
|
|
||||||
finish:
|
|
||||||
PyMem_Free(groups_c);
|
|
||||||
PyMem_Free(cmd_args_c);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char _mysql_server_end__doc__[] =
|
|
||||||
"Shut down embedded server. If not using an embedded server, this\n\
|
|
||||||
does nothing.";
|
|
||||||
|
|
||||||
static PyObject *_mysql_server_end(
|
|
||||||
PyObject *self,
|
|
||||||
PyObject *args) {
|
|
||||||
if (_mysql_server_init_done) {
|
|
||||||
mysql_server_end();
|
|
||||||
_mysql_server_init_done = 0;
|
|
||||||
Py_INCREF(Py_None);
|
|
||||||
return Py_None;
|
|
||||||
}
|
|
||||||
return _mysql_Exception(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char _mysql_thread_safe__doc__[] =
|
static char _mysql_thread_safe__doc__[] =
|
||||||
"Indicates whether the client is compiled as thread-safe.";
|
"Indicates whether the client is compiled as thread-safe.";
|
||||||
|
|
||||||
@ -344,10 +216,7 @@ static PyObject *_mysql_thread_safe(
|
|||||||
PyObject *self,
|
PyObject *self,
|
||||||
PyObject *noargs)
|
PyObject *noargs)
|
||||||
{
|
{
|
||||||
PyObject *flag;
|
return PyInt_FromLong((long)mysql_thread_safe());
|
||||||
check_server_init(NULL);
|
|
||||||
if (!(flag=PyInt_FromLong((long)mysql_thread_safe()))) return NULL;
|
|
||||||
return flag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char _mysql_ResultObject__doc__[] =
|
static char _mysql_ResultObject__doc__[] =
|
||||||
@ -530,7 +399,6 @@ _mysql_ConnectionObject_Initialize(
|
|||||||
|
|
||||||
self->converter = NULL;
|
self->converter = NULL;
|
||||||
self->open = 0;
|
self->open = 0;
|
||||||
check_server_init(-1);
|
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
|
||||||
#ifdef HAVE_MYSQL_OPT_TIMEOUTS
|
#ifdef HAVE_MYSQL_OPT_TIMEOUTS
|
||||||
@ -1029,7 +897,6 @@ _mysql_escape_string(
|
|||||||
str = PyBytes_FromStringAndSize((char *) NULL, size*2+1);
|
str = PyBytes_FromStringAndSize((char *) NULL, size*2+1);
|
||||||
if (!str) return PyErr_NoMemory();
|
if (!str) return PyErr_NoMemory();
|
||||||
out = PyBytes_AS_STRING(str);
|
out = PyBytes_AS_STRING(str);
|
||||||
check_server_init(NULL);
|
|
||||||
|
|
||||||
if (self && PyModule_Check((PyObject*)self))
|
if (self && PyModule_Check((PyObject*)self))
|
||||||
self = NULL;
|
self = NULL;
|
||||||
@ -1090,7 +957,6 @@ _mysql_string_literal(
|
|||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
out = PyBytes_AS_STRING(str);
|
out = PyBytes_AS_STRING(str);
|
||||||
check_server_init(NULL);
|
|
||||||
if (self && self->open) {
|
if (self && self->open) {
|
||||||
#if MYSQL_VERSION_ID >= 50707 && !defined(MARIADB_BASE_VERSION) && !defined(MARIADB_VERSION_ID)
|
#if MYSQL_VERSION_ID >= 50707 && !defined(MARIADB_BASE_VERSION) && !defined(MARIADB_VERSION_ID)
|
||||||
len = mysql_real_escape_string_quote(&(self->connection), out+1, in, size, '\'');
|
len = mysql_real_escape_string_quote(&(self->connection), out+1, in, size, '\'');
|
||||||
@ -1715,7 +1581,6 @@ _mysql_get_client_info(
|
|||||||
PyObject *self,
|
PyObject *self,
|
||||||
PyObject *noargs)
|
PyObject *noargs)
|
||||||
{
|
{
|
||||||
check_server_init(NULL);
|
|
||||||
return PyString_FromString(mysql_get_client_info());
|
return PyString_FromString(mysql_get_client_info());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2785,18 +2650,6 @@ _mysql_methods[] = {
|
|||||||
METH_NOARGS,
|
METH_NOARGS,
|
||||||
_mysql_thread_safe__doc__
|
_mysql_thread_safe__doc__
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"server_init",
|
|
||||||
(PyCFunction)_mysql_server_init,
|
|
||||||
METH_VARARGS | METH_KEYWORDS,
|
|
||||||
_mysql_server_init__doc__
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"server_end",
|
|
||||||
(PyCFunction)_mysql_server_end,
|
|
||||||
METH_VARARGS,
|
|
||||||
_mysql_server_end__doc__
|
|
||||||
},
|
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,13 +9,6 @@
|
|||||||
Build Errors
|
Build Errors
|
||||||
------------
|
------------
|
||||||
|
|
||||||
ld: fatal: library -lmysqlclient_r: not found
|
|
||||||
|
|
||||||
mysqlclient_r is the thread-safe library. It's not available on
|
|
||||||
all platforms, or all installations, apparently. You'll need to
|
|
||||||
reconfigure site.cfg (in MySQLdb-1.2.1 and newer) to have
|
|
||||||
threadsafe = False.
|
|
||||||
|
|
||||||
mysql.h: No such file or directory
|
mysql.h: No such file or directory
|
||||||
|
|
||||||
This almost always mean you don't have development packages
|
This almost always mean you don't have development packages
|
||||||
|
@ -680,33 +680,6 @@ SSDictCursor
|
|||||||
Like ``SSCursor`` except it returns rows as dictionaries.
|
Like ``SSCursor`` except it returns rows as dictionaries.
|
||||||
|
|
||||||
|
|
||||||
Embedded Server
|
|
||||||
---------------
|
|
||||||
|
|
||||||
Instead of connecting to a stand-alone server over the network,
|
|
||||||
the embedded server support lets you run a full server right in
|
|
||||||
your Python code or application server.
|
|
||||||
|
|
||||||
If you have built MySQLdb with embedded server support, there
|
|
||||||
are two additional functions you will need to make use of:
|
|
||||||
|
|
||||||
server_init(args, groups)
|
|
||||||
Initialize embedded server. If this client is not linked against
|
|
||||||
the embedded server library, this function does nothing.
|
|
||||||
|
|
||||||
args
|
|
||||||
sequence of command-line arguments
|
|
||||||
groups
|
|
||||||
sequence of groups to use in defaults files
|
|
||||||
|
|
||||||
server_end()
|
|
||||||
Shut down embedded server. If not using an embedded server, this
|
|
||||||
does nothing.
|
|
||||||
|
|
||||||
See the MySQL documentation for more information on the embedded
|
|
||||||
server.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
:Title: MySQLdb: a Python interface for MySQL
|
:Title: MySQLdb: a Python interface for MySQL
|
||||||
:Author: Andy Dustman
|
:Author: Andy Dustman
|
||||||
|
@ -2,7 +2,6 @@ import os, sys
|
|||||||
try:
|
try:
|
||||||
from ConfigParser import SafeConfigParser
|
from ConfigParser import SafeConfigParser
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# Probably running Python 3.x
|
|
||||||
from configparser import ConfigParser as SafeConfigParser
|
from configparser import ConfigParser as SafeConfigParser
|
||||||
|
|
||||||
# This dequote() business is required for some older versions
|
# This dequote() business is required for some older versions
|
||||||
@ -15,27 +14,29 @@ def dequote(s):
|
|||||||
s = s[1:-1]
|
s = s[1:-1]
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
_mysql_config_path = "mysql_config"
|
||||||
|
|
||||||
def mysql_config(what):
|
def mysql_config(what):
|
||||||
from os import popen
|
from os import popen
|
||||||
|
|
||||||
f = popen("%s --%s" % (mysql_config.path, what))
|
f = popen("%s --%s" % (_mysql_config_path, what))
|
||||||
data = f.read().strip().split()
|
data = f.read().strip().split()
|
||||||
ret = f.close()
|
ret = f.close()
|
||||||
if ret:
|
if ret:
|
||||||
if ret/256:
|
if ret/256:
|
||||||
data = []
|
data = []
|
||||||
if ret/256 > 1:
|
if ret/256 > 1:
|
||||||
raise EnvironmentError("%s not found" % (mysql_config.path,))
|
raise EnvironmentError("%s not found" % (_mysql_config_path,))
|
||||||
return data
|
return data
|
||||||
mysql_config.path = "mysql_config"
|
|
||||||
|
|
||||||
def get_config():
|
def get_config():
|
||||||
from setup_common import get_metadata_and_options, enabled, create_release_file
|
from setup_common import get_metadata_and_options, enabled, create_release_file
|
||||||
|
global _mysql_config_path
|
||||||
|
|
||||||
metadata, options = get_metadata_and_options()
|
metadata, options = get_metadata_and_options()
|
||||||
|
|
||||||
if 'mysql_config' in options:
|
if 'mysql_config' in options:
|
||||||
mysql_config.path = options['mysql_config']
|
_mysql_config_path = options['mysql_config']
|
||||||
|
|
||||||
extra_objects = []
|
extra_objects = []
|
||||||
static = enabled(options, 'static')
|
static = enabled(options, 'static')
|
||||||
@ -47,15 +48,7 @@ def get_config():
|
|||||||
static = True
|
static = True
|
||||||
sys.argv.remove('--static')
|
sys.argv.remove('--static')
|
||||||
|
|
||||||
if enabled(options, 'embedded'):
|
libs = mysql_config("libs")
|
||||||
libs = mysql_config("libmysqld-libs")
|
|
||||||
elif enabled(options, 'threadsafe'):
|
|
||||||
libs = mysql_config("libs_r")
|
|
||||||
if not libs:
|
|
||||||
libs = mysql_config("libs")
|
|
||||||
else:
|
|
||||||
libs = mysql_config("libs")
|
|
||||||
|
|
||||||
library_dirs = [dequote(i[2:]) for i in libs if i.startswith('-L')]
|
library_dirs = [dequote(i[2:]) for i in libs if i.startswith('-L')]
|
||||||
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
|
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
|
||||||
extra_link_args = [x for x in libs if not x.startswith(('-l', '-L'))]
|
extra_link_args = [x for x in libs if not x.startswith(('-l', '-L'))]
|
||||||
@ -92,8 +85,6 @@ def get_config():
|
|||||||
libraries.remove(client)
|
libraries.remove(client)
|
||||||
|
|
||||||
name = "mysqlclient"
|
name = "mysqlclient"
|
||||||
if enabled(options, 'embedded'):
|
|
||||||
name = name + "-embedded"
|
|
||||||
metadata['name'] = name
|
metadata['name'] = name
|
||||||
|
|
||||||
define_macros = [
|
define_macros = [
|
||||||
|
7
site.cfg
7
site.cfg
@ -1,10 +1,5 @@
|
|||||||
[options]
|
[options]
|
||||||
# embedded: link against the embedded server library
|
# static: link against a static library
|
||||||
# threadsafe: use the threadsafe client
|
|
||||||
# static: link against a static library (probably required for embedded)
|
|
||||||
|
|
||||||
embedded = False
|
|
||||||
threadsafe = True
|
|
||||||
static = False
|
static = False
|
||||||
|
|
||||||
# The path to mysql_config.
|
# The path to mysql_config.
|
||||||
|
Reference in New Issue
Block a user