annotate _mysql.c @ 48:f4fd8c20511c MySQLdb

Read a default file in the test setUp. Since Python 2.4, int() will return longs if needed so make all long references int as in Python 3.0 there is no more long due to int/long unification (new ints are old longs).
author adustman
date Sun, 22 Feb 2009 20:01:31 +0000
parents e80676c3505f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
1 /* -*- mode: C; indent-tabs-mode: t; c-basic-offset: 8; -*- */
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
2
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
3 #include "_mysql.h"
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
4
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
5 PyObject *_mysql_MySQLError;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
6 PyObject *_mysql_Warning;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
7 PyObject *_mysql_Error;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
8 PyObject *_mysql_DatabaseError;
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
9 PyObject *_mysql_InterfaceError;
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
10 PyObject *_mysql_DataError;
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
11 PyObject *_mysql_OperationalError;
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
12 PyObject *_mysql_IntegrityError;
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
13 PyObject *_mysql_InternalError;
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
14 PyObject *_mysql_ProgrammingError;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
15 PyObject *_mysql_NotSupportedError;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
16 PyObject *_mysql_error_map;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
17
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
18 int _mysql_server_init_done = 0;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
19
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
20 PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
21 _mysql_Exception(_mysql_ConnectionObject *c)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
22 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
23 PyObject *t, *e;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
24 int merr;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
25
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
26 if (!(t = PyTuple_New(2))) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
27 if (!_mysql_server_init_done) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
28 e = _mysql_InternalError;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
29 PyTuple_SET_ITEM(t, 0, PyInt_FromLong(-1L));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
30 PyTuple_SET_ITEM(t, 1, PyString_FromString("server not initialized"));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
31 PyErr_SetObject(e, t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
32 Py_DECREF(t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
33 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
34 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
35 merr = mysql_errno(&(c->connection));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
36 if (!merr)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
37 e = _mysql_InterfaceError;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
38 else if (merr > CR_MAX_ERROR) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
39 PyTuple_SET_ITEM(t, 0, PyInt_FromLong(-1L));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
40 PyTuple_SET_ITEM(t, 1, PyString_FromString("error totally whack"));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
41 PyErr_SetObject(_mysql_InterfaceError, t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
42 Py_DECREF(t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
43 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
44 }
8
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
45 else {
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
46 PyObject *py_merr = PyInt_FromLong(merr);
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
47 e = PyDict_GetItem(_mysql_error_map, py_merr);
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
48 Py_DECREF(py_merr);
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
49 if (!e) {
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
50 if (merr < 1000) e = _mysql_InternalError;
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
51 else e = _mysql_OperationalError;
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
52 }
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
53 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
54 PyTuple_SET_ITEM(t, 0, PyInt_FromLong((long)merr));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
55 PyTuple_SET_ITEM(t, 1, PyString_FromString(mysql_error(&(c->connection))));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
56 PyErr_SetObject(e, t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
57 Py_DECREF(t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
58 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
59 }
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
60
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
61 static char _mysql_server_init__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
62 "Initialize embedded server. If this client is not linked against\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
63 the embedded server library, this function does nothing.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
64 \n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
65 args -- sequence of command-line arguments\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
66 groups -- sequence of groups to use in defaults files\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
67 ";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
68
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
69 static PyObject *_mysql_server_init(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
70 PyObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
71 PyObject *args,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
72 PyObject *kwargs) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
73 static char *kwlist[] = {"args", "groups", NULL};
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
74 char **cmd_args_c=NULL, **groups_c=NULL, *s;
27
d301c95d8fd7 Apply missing Py_ssize_t conversion caught by spektrum.
kylev
parents: 18
diff changeset
75 Py_ssize_t cmd_argc=0, i, groupc;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
76 PyObject *cmd_args=NULL, *groups=NULL, *ret=NULL, *item;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
77
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
78 if (_mysql_server_init_done) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
79 PyErr_SetString(_mysql_ProgrammingError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
80 "already initialized");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
81 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
82 }
27
d301c95d8fd7 Apply missing Py_ssize_t conversion caught by spektrum.
kylev
parents: 18
diff changeset
83
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
84 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", kwlist,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
85 &cmd_args, &groups))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
86 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
87
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
88 #if MYSQL_VERSION_ID >= 40000
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
89 if (cmd_args) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
90 if (!PySequence_Check(cmd_args)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
91 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
92 "args must be a sequence");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
93 goto finish;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
94 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
95 cmd_argc = PySequence_Size(cmd_args);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
96 if (cmd_argc == -1) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
97 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
98 "args could not be sized");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
99 goto finish;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
100 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
101 cmd_args_c = (char **) PyMem_Malloc(cmd_argc*sizeof(char *));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
102 for (i=0; i< cmd_argc; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
103 item = PySequence_GetItem(cmd_args, i);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
104 s = PyString_AsString(item);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
105 Py_DECREF(item);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
106 if (!s) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
107 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
108 "args must contain strings");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
109 goto finish;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
110 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
111 cmd_args_c[i] = s;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
112 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
113 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
114 if (groups) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
115 if (!PySequence_Check(groups)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
116 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
117 "groups must be a sequence");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
118 goto finish;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
119 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
120 groupc = PySequence_Size(groups);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
121 if (groupc == -1) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
122 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
123 "groups could not be sized");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
124 goto finish;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
125 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
126 groups_c = (char **) PyMem_Malloc((1+groupc)*sizeof(char *));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
127 for (i=0; i< groupc; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
128 item = PySequence_GetItem(groups, i);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
129 s = PyString_AsString(item);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
130 Py_DECREF(item);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
131 if (!s) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
132 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
133 "groups must contain strings");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
134 goto finish;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
135 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
136 groups_c[i] = s;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
137 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
138 groups_c[groupc] = (char *)NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
139 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
140 /* even though this may block, don't give up the interpreter lock
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
141 so that the server can't be initialized multiple times. */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
142 if (mysql_server_init(cmd_argc, cmd_args_c, groups_c)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
143 _mysql_Exception(NULL);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
144 goto finish;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
145 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
146 #endif
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
147 ret = Py_None;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
148 Py_INCREF(Py_None);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
149 _mysql_server_init_done = 1;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
150 finish:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
151 PyMem_Free(groups_c);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
152 PyMem_Free(cmd_args_c);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
153 return ret;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
154 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
155
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
156 static char _mysql_server_end__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
157 "Shut down embedded server. If not using an embedded server, this\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
158 does nothing.";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
159
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
160 static PyObject *_mysql_server_end(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
161 PyObject *self,
41
e80676c3505f More NOARGS, with test coverage
kylev
parents: 39
diff changeset
162 PyObject *unused) {
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
163 if (_mysql_server_init_done) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
164 #if MYSQL_VERSION_ID >= 40000
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
165 mysql_server_end();
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
166 #endif
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
167 _mysql_server_init_done = 0;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
168 Py_INCREF(Py_None);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
169 return Py_None;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
170 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
171 return _mysql_Exception(NULL);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
172 }
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
173
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
174 #if MYSQL_VERSION_ID >= 32314
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
175 static char _mysql_thread_safe__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
176 "Indicates whether the client is compiled as thread-safe.";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
177
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
178 static PyObject *_mysql_thread_safe(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
179 PyObject *self,
41
e80676c3505f More NOARGS, with test coverage
kylev
parents: 39
diff changeset
180 PyObject *unused) {
e80676c3505f More NOARGS, with test coverage
kylev
parents: 39
diff changeset
181
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
182 check_server_init(NULL);
41
e80676c3505f More NOARGS, with test coverage
kylev
parents: 39
diff changeset
183 return PyInt_FromLong((long)mysql_thread_safe());
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
184 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
185 #endif
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
186
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
187 extern char _mysql_connect__doc__[];
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
188 PyObject *
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
189 _mysql_connect(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
190 PyObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
191 PyObject *args,
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
192 PyObject *kwargs);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
193
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
194 static char _mysql_debug__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
195 "Does a DBUG_PUSH with the given string.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
196 mysql_debug() uses the Fred Fish debug library.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
197 To use this function, you must compile the client library to\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
198 support debugging.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
199 ";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
200 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
201 _mysql_debug(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
202 PyObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
203 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
204 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
205 char *debug;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
206 if (!PyArg_ParseTuple(args, "s", &debug)) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
207 mysql_debug(debug);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
208 Py_INCREF(Py_None);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
209 return Py_None;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
210 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
211
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
212 extern char _mysql_escape_string__doc__[];
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
213 PyObject *
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
214 _mysql_escape_string(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
215 _mysql_ConnectionObject *self,
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
216 PyObject *args);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
217
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
218 extern char _mysql_string_literal__doc__[];
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
219 PyObject *
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
220 _mysql_string_literal(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
221 _mysql_ConnectionObject *self,
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
222 PyObject *args);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
223
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
224 static PyObject *_mysql_NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
225
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
226 PyObject *
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
227 _escape_item(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
228 PyObject *item,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
229 PyObject *d)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
230 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
231 PyObject *quoted=NULL, *itemtype, *itemconv;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
232 if (!(itemtype = PyObject_Type(item)))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
233 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
234 itemconv = PyObject_GetItem(d, itemtype);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
235 Py_DECREF(itemtype);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
236 if (!itemconv) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
237 PyErr_Clear();
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
238 itemconv = PyObject_GetItem(d,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
239 (PyObject *) &PyString_Type);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
240 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
241 if (!itemconv) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
242 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
243 "no default type converter defined");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
244 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
245 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
246 quoted = PyObject_CallFunction(itemconv, "OO", item, d);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
247 Py_DECREF(itemconv);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
248 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
249 return quoted;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
250 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
251
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
252 extern char _mysql_escape__doc__[];
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
253 PyObject *
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
254 _mysql_escape(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
255 PyObject *self,
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
256 PyObject *args);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
257
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
258 static char _mysql_escape_sequence__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
259 "escape_sequence(seq, dict) -- escape any special characters in sequence\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
260 seq using mapping dict to provide quoting functions for each type.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
261 Returns a tuple of escaped items.";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
262 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
263 _mysql_escape_sequence(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
264 PyObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
265 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
266 {
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
267 PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
268 int i, n;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
269 if (!PyArg_ParseTuple(args, "OO:escape_sequence", &o, &d))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
270 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
271 if (!PyMapping_Check(d)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
272 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
273 "argument 2 must be a mapping");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
274 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
275 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
276 if ((n = PyObject_Length(o)) == -1) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
277 if (!(r = PyTuple_New(n))) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
278 for (i=0; i<n; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
279 item = PySequence_GetItem(o, i);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
280 if (!item) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
281 quoted = _escape_item(item, d);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
282 Py_DECREF(item);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
283 if (!quoted) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
284 PyTuple_SET_ITEM(r, i, quoted);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
285 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
286 return r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
287 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
288 Py_XDECREF(r);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
289 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
290 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
291
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
292 static char _mysql_escape_dict__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
293 "escape_sequence(d, dict) -- escape any special characters in\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
294 dictionary d using mapping dict to provide quoting functions for each type.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
295 Returns a dictionary of escaped items.";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
296 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
297 _mysql_escape_dict(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
298 PyObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
299 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
300 {
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
301 PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted, *pkey;
5
b70cce9bd065 Merge changes from 1.2 branch r456-468
adustman
parents: 4
diff changeset
302 Py_ssize_t ppos = 0;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
303 if (!PyArg_ParseTuple(args, "O!O:escape_dict", &PyDict_Type, &o, &d))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
304 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
305 if (!PyMapping_Check(d)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
306 PyErr_SetString(PyExc_TypeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
307 "argument 2 must be a mapping");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
308 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
309 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
310 if (!(r = PyDict_New())) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
311 while (PyDict_Next(o, &ppos, &pkey, &item)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
312 quoted = _escape_item(item, d);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
313 if (!quoted) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
314 if (PyDict_SetItem(r, pkey, quoted)==-1) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
315 Py_DECREF(quoted);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
316 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
317 return r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
318 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
319 Py_XDECREF(r);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
320 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
321 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
322
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
323 static char _mysql_get_client_info__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
324 "get_client_info() -- Returns a string that represents\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
325 the client library version.";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
326 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
327 _mysql_get_client_info(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
328 PyObject *self,
41
e80676c3505f More NOARGS, with test coverage
kylev
parents: 39
diff changeset
329 PyObject *unused)
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
330 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
331 check_server_init(NULL);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
332 return PyString_FromString(mysql_get_client_info());
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
333 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
334
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
335 extern PyTypeObject _mysql_ConnectionObject_Type;
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
336 extern PyTypeObject _mysql_ResultObject_Type;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
337
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
338 static PyMethodDef
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
339 _mysql_methods[] = {
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
340 {
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
341 "connect",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
342 (PyCFunction)_mysql_connect,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
343 METH_VARARGS | METH_KEYWORDS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
344 _mysql_connect__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
345 },
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
346 {
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
347 "debug",
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
348 (PyCFunction)_mysql_debug,
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
349 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
350 _mysql_debug__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
351 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
352 {
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
353 "escape",
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
354 (PyCFunction)_mysql_escape,
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
355 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
356 _mysql_escape__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
357 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
358 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
359 "escape_sequence",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
360 (PyCFunction)_mysql_escape_sequence,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
361 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
362 _mysql_escape_sequence__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
363 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
364 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
365 "escape_dict",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
366 (PyCFunction)_mysql_escape_dict,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
367 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
368 _mysql_escape_dict__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
369 },
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
370 {
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
371 "escape_string",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
372 (PyCFunction)_mysql_escape_string,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
373 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
374 _mysql_escape_string__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
375 },
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
376 {
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
377 "string_literal",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
378 (PyCFunction)_mysql_string_literal,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
379 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
380 _mysql_string_literal__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
381 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
382 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
383 "get_client_info",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
384 (PyCFunction)_mysql_get_client_info,
41
e80676c3505f More NOARGS, with test coverage
kylev
parents: 39
diff changeset
385 METH_NOARGS,
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
386 _mysql_get_client_info__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
387 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
388 #if MYSQL_VERSION_ID >= 32314
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
389 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
390 "thread_safe",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
391 (PyCFunction)_mysql_thread_safe,
41
e80676c3505f More NOARGS, with test coverage
kylev
parents: 39
diff changeset
392 METH_NOARGS,
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
393 _mysql_thread_safe__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
394 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
395 #endif
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
396 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
397 "server_init",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
398 (PyCFunction)_mysql_server_init,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
399 METH_VARARGS | METH_KEYWORDS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
400 _mysql_server_init__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
401 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
402 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
403 "server_end",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
404 (PyCFunction)_mysql_server_end,
41
e80676c3505f More NOARGS, with test coverage
kylev
parents: 39
diff changeset
405 METH_NOARGS,
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
406 _mysql_server_end__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
407 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
408 {NULL, NULL} /* sentinel */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
409 };
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
410
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
411 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
412 _mysql_NewException(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
413 PyObject *dict,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
414 PyObject *edict,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
415 char *name)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
416 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
417 PyObject *e;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
418
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
419 if (!(e = PyDict_GetItemString(edict, name)))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
420 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
421 if (PyDict_SetItemString(dict, name, e)) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
422 return e;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
423 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
424
4
b5a377255eea Merge changes from MySQLdb-1.2 branch (448-455)
adustman
parents: 2
diff changeset
425 #define QUOTE(X) _QUOTE(X)
b5a377255eea Merge changes from MySQLdb-1.2 branch (448-455)
adustman
parents: 2
diff changeset
426 #define _QUOTE(X) #X
b5a377255eea Merge changes from MySQLdb-1.2 branch (448-455)
adustman
parents: 2
diff changeset
427
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
428 static char _mysql___doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
429 "an adaptation of the MySQL C API (mostly)\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
430 \n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
431 You probably are better off using MySQLdb instead of using this\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
432 module directly.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
433 \n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
434 In general, renaming goes from mysql_* to _mysql.*. _mysql.connect()\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
435 returns a connection object (MYSQL). Functions which expect MYSQL * as\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
436 an argument are now methods of the connection object. A number of things\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
437 return result objects (MYSQL_RES). Functions which expect MYSQL_RES * as\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
438 an argument are now methods of the result object. Deprecated functions\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
439 (as of 3.23) are NOT implemented.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
440 ";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
441
39
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
442 PyMODINIT_FUNC
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
443 init_mysql(void)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
444 {
39
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
445 PyObject *dict, *module, *emod, *edict, *version_tuple;
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
446
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
447 module = Py_InitModule3("_mysql", _mysql_methods, _mysql___doc__);
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
448 if (!module)
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
449 return; /* this really should never happen */
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
450
39
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
451 /* Populate final object settings */
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
452 _mysql_ConnectionObject_Type.ob_type = &PyType_Type;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
453 _mysql_ResultObject_Type.ob_type = &PyType_Type;
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
454 _mysql_FieldObject_Type.ob_type = &PyType_Type;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
455 _mysql_ConnectionObject_Type.tp_alloc = PyType_GenericAlloc;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
456 _mysql_ConnectionObject_Type.tp_new = PyType_GenericNew;
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
457 _mysql_ConnectionObject_Type.tp_free = _PyObject_GC_Del;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
458 _mysql_ResultObject_Type.tp_alloc = PyType_GenericAlloc;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
459 _mysql_ResultObject_Type.tp_new = PyType_GenericNew;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
460 _mysql_ResultObject_Type.tp_free = _PyObject_GC_Del;
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
461 _mysql_FieldObject_Type.tp_alloc = PyType_GenericAlloc;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
462 _mysql_FieldObject_Type.tp_new = PyType_GenericNew;
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
463 _mysql_FieldObject_Type.tp_free = _PyObject_GC_Del;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
464
39
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
465 if (!(dict = PyModule_GetDict(module)))
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
466 goto error;
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
467
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
468 /* Module constants */
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
469 version_tuple = PyRun_String(QUOTE(version_info), Py_eval_input,
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
470 dict, dict);
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
471 if (PyModule_AddObject(module, "version_info", version_tuple) < 0)
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
472 goto error;
39
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
473 if (PyModule_AddStringConstant(module, "__version__",
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
474 QUOTE(__version__)) < 0)
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
475 goto error;
39
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
476 if (PyModule_AddStringConstant(module, "NULL", "NULL") < 0)
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
477 goto error;
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
478
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
479
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
480 /* Register types */
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
481 if (PyDict_SetItemString(dict, "connection",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
482 (PyObject *)&_mysql_ConnectionObject_Type))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
483 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
484 Py_INCREF(&_mysql_ConnectionObject_Type);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
485 if (PyDict_SetItemString(dict, "result",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
486 (PyObject *)&_mysql_ResultObject_Type))
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
487 goto error;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
488 Py_INCREF(&_mysql_ResultObject_Type);
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
489 if (PyDict_SetItemString(dict, "field",
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
490 (PyObject *)&_mysql_FieldObject_Type))
38
0da42144a012 Use Py_InitModule3 since we were were doing the same as the #define for the
kylev
parents: 27
diff changeset
491 goto error;
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
492 Py_INCREF(&_mysql_FieldObject_Type);
39
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
493
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
494 /* Reach into the exceptions module. */
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 8
diff changeset
495 if (!(emod = PyImport_ImportModule("MySQLdb.exceptions")))
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
496 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
497 if (!(edict = PyModule_GetDict(emod))) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
498 if (!(_mysql_MySQLError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
499 _mysql_NewException(dict, edict, "MySQLError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
500 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
501 if (!(_mysql_Warning =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
502 _mysql_NewException(dict, edict, "Warning")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
503 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
504 if (!(_mysql_Error =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
505 _mysql_NewException(dict, edict, "Error")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
506 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
507 if (!(_mysql_InterfaceError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
508 _mysql_NewException(dict, edict, "InterfaceError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
509 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
510 if (!(_mysql_DatabaseError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
511 _mysql_NewException(dict, edict, "DatabaseError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
512 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
513 if (!(_mysql_DataError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
514 _mysql_NewException(dict, edict, "DataError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
515 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
516 if (!(_mysql_OperationalError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
517 _mysql_NewException(dict, edict, "OperationalError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
518 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
519 if (!(_mysql_IntegrityError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
520 _mysql_NewException(dict, edict, "IntegrityError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
521 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
522 if (!(_mysql_InternalError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
523 _mysql_NewException(dict, edict, "InternalError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
524 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
525 if (!(_mysql_ProgrammingError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
526 _mysql_NewException(dict, edict, "ProgrammingError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
527 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
528 if (!(_mysql_NotSupportedError =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
529 _mysql_NewException(dict, edict, "NotSupportedError")))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
530 goto error;
8
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
531 if (!(_mysql_error_map = PyDict_GetItemString(edict, "error_map")))
fa8974a41c76 New error handling code, plus some small fixes from 1.2
adustman
parents: 5
diff changeset
532 goto error;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
533 Py_DECREF(emod);
39
78e810705b3d Update some of the constants and declarations to post python-2.0
kylev
parents: 38
diff changeset
534
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
535 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
536 if (PyErr_Occurred())
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
537 PyErr_SetString(PyExc_ImportError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
538 "_mysql: init failed");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
539 return;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
540 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
541
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
542