annotate _mysql_results.c @ 17:7c7a89123d65 MySQLdb

egg names already include python versoin, so don't add it to package name.
author adustman
date Tue, 27 Feb 2007 00:58:49 +0000
parents c0d1fc0429ce
children d55bfb1a4701
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
1 #include "_mysql.h"
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
2
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
3 static char _mysql_ResultObject__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
4 "result(connection, use=0, converter={}) -- Result set from a query.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
5 \n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
6 Creating instances of this class directly is an excellent way to\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
7 shoot yourself in the foot. If using _mysql.connection directly,\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
8 use connection.store_result() or connection.use_result() instead.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
9 If using MySQLdb.Connection, this is done by the cursor class.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
10 Just forget you ever saw this. Forget... FOR-GET...";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
11
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
12 int
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
13 _mysql_ResultObject_Initialize(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
14 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
15 PyObject *args,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
16 PyObject *kwargs)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
17 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
18 static char *kwlist[] = {"connection", "use", "converter", NULL};
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
19 MYSQL_RES *result;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
20 _mysql_ConnectionObject *conn=NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
21 int use=0;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
22 PyObject *conv=NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
23 int n, i;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
24 MYSQL_FIELD *fields;
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 (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iO", kwlist,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
27 &conn, &use, &conv))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
28 return -1;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
29 if (!conv) conv = PyDict_New();
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
30 if (!conv) return -1;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
31 self->conn = (PyObject *) conn;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
32 Py_INCREF(conn);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
33 self->use = use;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
34 Py_BEGIN_ALLOW_THREADS ;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
35 if (use)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
36 result = mysql_use_result(&(conn->connection));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
37 else
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
38 result = mysql_store_result(&(conn->connection));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
39 self->result = result;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
40 Py_END_ALLOW_THREADS ;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
41 if (!result) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
42 self->converter = PyTuple_New(0);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
43 return 0;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
44 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
45 n = mysql_num_fields(result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
46 self->nfields = n;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
47 if (!(self->converter = PyTuple_New(n))) return -1;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
48 fields = mysql_fetch_fields(result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
49 for (i=0; i<n; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
50 PyObject *tmp, *fun;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
51 tmp = PyInt_FromLong((long) fields[i].type);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
52 if (!tmp) return -1;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
53 fun = PyObject_GetItem(conv, tmp);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
54 Py_DECREF(tmp);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
55 if (!fun) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
56 PyErr_Clear();
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
57 fun = Py_None;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
58 Py_INCREF(Py_None);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
59 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
60 if (PySequence_Check(fun)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
61 int j, n2=PySequence_Size(fun);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
62 PyObject *fun2=NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
63 for (j=0; j<n2; j++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
64 PyObject *t = PySequence_GetItem(fun, j);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
65 if (!t) continue;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
66 if (!PyTuple_Check(t)) goto cleanup;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
67 if (PyTuple_GET_SIZE(t) == 2) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
68 long mask;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
69 PyObject *pmask=NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
70 pmask = PyTuple_GET_ITEM(t, 0);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
71 fun2 = PyTuple_GET_ITEM(t, 1);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
72 if (PyInt_Check(pmask)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
73 mask = PyInt_AS_LONG(pmask);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
74 if (mask & fields[i].flags) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
75 break;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
76 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
77 else {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
78 continue;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
79 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
80 } else {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
81 break;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
82 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
83 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
84 cleanup:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
85 Py_DECREF(t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
86 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
87 if (!fun2) fun2 = Py_None;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
88 Py_INCREF(fun2);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
89 Py_DECREF(fun);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
90 fun = fun2;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
91 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
92 PyTuple_SET_ITEM(self->converter, i, fun);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
93 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
94 return 0;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
95 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
96
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
97 #if PY_VERSION_HEX >= 0x02020000
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
98 static int _mysql_ResultObject_traverse(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
99 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
100 visitproc visit,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
101 void *arg)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
102 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
103 int r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
104 if (self->converter) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
105 if (!(r = visit(self->converter, arg))) return r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
106 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
107 if (self->conn)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
108 return visit(self->conn, arg);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
109 return 0;
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 #endif
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 static int _mysql_ResultObject_clear(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
114 _mysql_ResultObject *self)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
115 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
116 Py_XDECREF(self->converter);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
117 self->converter = NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
118 Py_XDECREF(self->conn);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
119 self->conn = NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
120 return 0;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
121 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
122
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
123 static char _mysql_ResultObject_describe__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
124 "Returns the sequence of 7-tuples required by the DB-API for\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
125 the Cursor.description attribute.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
126 ";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
127
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
128 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
129 _mysql_ResultObject_describe(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
130 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
131 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
132 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
133 PyObject *d;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
134 MYSQL_FIELD *fields;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
135 unsigned int i, n;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
136 if (!PyArg_ParseTuple(args, "")) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
137 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
138 n = mysql_num_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
139 fields = mysql_fetch_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
140 if (!(d = PyTuple_New(n))) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
141 for (i=0; i<n; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
142 PyObject *t;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
143 t = Py_BuildValue("(siiiiii)",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
144 fields[i].name,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
145 (long) fields[i].type,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
146 (long) fields[i].max_length,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
147 (long) fields[i].length,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
148 (long) fields[i].length,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
149 (long) fields[i].decimals,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
150 (long) !(IS_NOT_NULL(fields[i].flags)));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
151 if (!t) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
152 PyTuple_SET_ITEM(d, i, t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
153 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
154 return d;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
155 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
156 Py_XDECREF(d);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
157 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
158 }
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 char _mysql_ResultObject_field_flags__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
161 "Returns a tuple of field flags, one for each column in the result.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
162 " ;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
163
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
164 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
165 _mysql_ResultObject_field_flags(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
166 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
167 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
168 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
169 PyObject *d;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
170 MYSQL_FIELD *fields;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
171 unsigned int i, n;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
172 if (!PyArg_ParseTuple(args, "")) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
173 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
174 n = mysql_num_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
175 fields = mysql_fetch_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
176 if (!(d = PyTuple_New(n))) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
177 for (i=0; i<n; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
178 PyObject *f;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
179 if (!(f = PyInt_FromLong((long)fields[i].flags))) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
180 PyTuple_SET_ITEM(d, i, f);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
181 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
182 return d;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
183 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
184 Py_XDECREF(d);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
185 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
186 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
187
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
188 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
189 _mysql_field_to_python(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
190 PyObject *converter,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
191 char *rowitem,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
192 unsigned long length)
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 PyObject *v;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
195 if (rowitem) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
196 if (converter != Py_None)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
197 v = PyObject_CallFunction(converter,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
198 "s#",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
199 rowitem,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
200 (int)length);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
201 else
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
202 v = PyString_FromStringAndSize(rowitem,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
203 (int)length);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
204 if (!v)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
205 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
206 } else {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
207 Py_INCREF(Py_None);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
208 v = Py_None;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
209 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
210 return v;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
211 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
212
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
213 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
214 _mysql_row_to_tuple(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
215 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
216 MYSQL_ROW row)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
217 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
218 unsigned int n, i;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
219 unsigned long *length;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
220 PyObject *r, *c;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
221
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
222 n = mysql_num_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
223 if (!(r = PyTuple_New(n))) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
224 length = mysql_fetch_lengths(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
225 for (i=0; i<n; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
226 PyObject *v;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
227 c = PyTuple_GET_ITEM(self->converter, i);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
228 v = _mysql_field_to_python(c, row[i], length[i]);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
229 if (!v) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
230 PyTuple_SET_ITEM(r, i, v);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
231 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
232 return r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
233 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
234 Py_XDECREF(r);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
235 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
236 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
237
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
238 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
239 _mysql_row_to_dict(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
240 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
241 MYSQL_ROW row)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
242 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
243 unsigned int n, i;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
244 unsigned long *length;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
245 PyObject *r, *c;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
246 MYSQL_FIELD *fields;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
247
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
248 n = mysql_num_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
249 if (!(r = PyDict_New())) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
250 length = mysql_fetch_lengths(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
251 fields = mysql_fetch_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
252 for (i=0; i<n; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
253 PyObject *v;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
254 c = PyTuple_GET_ITEM(self->converter, i);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
255 v = _mysql_field_to_python(c, row[i], length[i]);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
256 if (!v) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
257 if (!PyMapping_HasKeyString(r, fields[i].name)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
258 PyMapping_SetItemString(r, fields[i].name, v);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
259 } else {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
260 int len;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
261 char buf[256];
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
262 strncpy(buf, fields[i].table, 256);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
263 len = strlen(buf);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
264 strncat(buf, ".", 256-len);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
265 len = strlen(buf);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
266 strncat(buf, fields[i].name, 256-len);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
267 PyMapping_SetItemString(r, buf, v);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
268 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
269 Py_DECREF(v);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
270 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
271 return r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
272 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
273 Py_XDECREF(r);
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
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
277 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
278 _mysql_row_to_dict_old(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
279 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
280 MYSQL_ROW row)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
281 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
282 unsigned int n, i;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
283 unsigned long *length;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
284 PyObject *r, *c;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
285 MYSQL_FIELD *fields;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
286
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
287 n = mysql_num_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
288 if (!(r = PyDict_New())) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
289 length = mysql_fetch_lengths(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
290 fields = mysql_fetch_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
291 for (i=0; i<n; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
292 PyObject *v;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
293 c = PyTuple_GET_ITEM(self->converter, i);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
294 v = _mysql_field_to_python(c, row[i], length[i]);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
295 if (!v) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
296 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
297 int len=0;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
298 char buf[256]="";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
299 if (strlen(fields[i].table)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
300 strncpy(buf, fields[i].table, 256);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
301 len = strlen(buf);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
302 strncat(buf, ".", 256-len);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
303 len = strlen(buf);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
304 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
305 strncat(buf, fields[i].name, 256-len);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
306 PyMapping_SetItemString(r, buf, v);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
307 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
308 Py_DECREF(v);
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 return r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
311 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
312 Py_XDECREF(r);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
313 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
314 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
315
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
316 typedef PyObject *_PYFUNC(_mysql_ResultObject *, MYSQL_ROW);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
317
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
318 int
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
319 _mysql__fetch_row(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
320 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
321 PyObject **r,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
322 int skiprows,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
323 int maxrows,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
324 _PYFUNC *convert_row)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
325 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
326 unsigned int i;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
327 MYSQL_ROW row;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
328
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
329 for (i = skiprows; i<(skiprows+maxrows); i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
330 PyObject *v;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
331 if (!self->use)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
332 row = mysql_fetch_row(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
333 else {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
334 Py_BEGIN_ALLOW_THREADS;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
335 row = mysql_fetch_row(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
336 Py_END_ALLOW_THREADS;
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 if (!row && mysql_errno(&(((_mysql_ConnectionObject *)(self->conn))->connection))) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
339 _mysql_Exception((_mysql_ConnectionObject *)self->conn);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
340 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
341 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
342 if (!row) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
343 if (MyTuple_Resize(r, i, 0) == -1) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
344 break;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
345 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
346 v = convert_row(self, row);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
347 if (!v) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
348 PyTuple_SET_ITEM(*r, i, v);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
349 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
350 return i-skiprows;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
351 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
352 return -1;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
353 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
354
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
355 static char _mysql_ResultObject_fetch_row__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
356 "fetch_row([maxrows, how]) -- Fetches up to maxrows as a tuple.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
357 The rows are formatted according to how:\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
358 \n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
359 0 -- tuples (default)\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
360 1 -- dictionaries, key=column or table.column if duplicated\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
361 2 -- dictionaries, key=table.column\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
362 ";
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 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
365 _mysql_ResultObject_fetch_row(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
366 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
367 PyObject *args,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
368 PyObject *kwargs)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
369 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
370 typedef PyObject *_PYFUNC(_mysql_ResultObject *, MYSQL_ROW);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
371 static char *kwlist[] = { "maxrows", "how", NULL };
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
372 static _PYFUNC *row_converters[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
373 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
374 _mysql_row_to_tuple,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
375 _mysql_row_to_dict,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
376 _mysql_row_to_dict_old
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
377 };
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
378 _PYFUNC *convert_row;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
379 unsigned int maxrows=1, how=0, skiprows=0, rowsadded;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
380 PyObject *r=NULL;
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 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ii:fetch_row", kwlist,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
383 &maxrows, &how))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
384 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
385 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
386 if (how < 0 || how >= sizeof(row_converters)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
387 PyErr_SetString(PyExc_ValueError, "how out of range");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
388 return NULL;
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 convert_row = row_converters[how];
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
391 if (maxrows) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
392 if (!(r = PyTuple_New(maxrows))) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
393 rowsadded = _mysql__fetch_row(self, &r, skiprows, maxrows,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
394 convert_row);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
395 if (rowsadded == -1) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
396 } else {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
397 if (self->use) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
398 maxrows = 1000;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
399 if (!(r = PyTuple_New(maxrows))) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
400 while (1) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
401 rowsadded = _mysql__fetch_row(self, &r, skiprows,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
402 maxrows, convert_row);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
403 if (rowsadded == -1) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
404 skiprows += rowsadded;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
405 if (rowsadded < maxrows) break;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
406 if (MyTuple_Resize(&r, skiprows+maxrows, 0) == -1)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
407 goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
408 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
409 } else {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
410 /* XXX if overflow, maxrows<0? */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
411 maxrows = (int) mysql_num_rows(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
412 if (!(r = PyTuple_New(maxrows))) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
413 rowsadded = _mysql__fetch_row(self, &r, 0,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
414 maxrows, convert_row);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
415 if (rowsadded == -1) goto error;
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 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
418 return r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
419 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
420 Py_XDECREF(r);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
421 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
422 }
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
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
425 static char _mysql_ResultObject_num_fields__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
426 "Returns the number of fields (column) in the result." ;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
427
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
428 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
429 _mysql_ResultObject_num_fields(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
430 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
431 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
432 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
433 if (!PyArg_ParseTuple(args, "")) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
434 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
435 return PyInt_FromLong((long)mysql_num_fields(self->result));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
436 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
437
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
438 static char _mysql_ResultObject_num_rows__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
439 "Returns the number of rows in the result set. Note that if\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
440 use=1, this will not return a valid value until the entire result\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
441 set has been read.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
442 ";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
443
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
444 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
445 _mysql_ResultObject_num_rows(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
446 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
447 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
448 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
449 if (!PyArg_ParseTuple(args, "")) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
450 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
451 return PyLong_FromUnsignedLongLong(mysql_num_rows(self->result));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
452 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
453
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
454
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
455 static char _mysql_ResultObject_data_seek__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
456 "data_seek(n) -- seek to row n of result set";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
457 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
458 _mysql_ResultObject_data_seek(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
459 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
460 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
461 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
462 unsigned int row;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
463 if (!PyArg_ParseTuple(args, "i:data_seek", &row)) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
464 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
465 mysql_data_seek(self->result, row);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
466 Py_INCREF(Py_None);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
467 return Py_None;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
468 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
469
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
470 static char _mysql_ResultObject_row_seek__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
471 "row_seek(n) -- seek by offset n rows of result set";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
472 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
473 _mysql_ResultObject_row_seek(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
474 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
475 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
476 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
477 int offset;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
478 MYSQL_ROW_OFFSET r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
479 if (!PyArg_ParseTuple(args, "i:row_seek", &offset)) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
480 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
481 if (self->use) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
482 PyErr_SetString(_mysql_ProgrammingError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
483 "cannot be used with connection.use_result()");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
484 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
485 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
486 r = mysql_row_tell(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
487 mysql_row_seek(self->result, r+offset);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
488 Py_INCREF(Py_None);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
489 return Py_None;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
490 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
491
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
492 static char _mysql_ResultObject_row_tell__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
493 "row_tell() -- return the current row number of the result set.";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
494 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
495 _mysql_ResultObject_row_tell(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
496 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
497 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
498 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
499 MYSQL_ROW_OFFSET r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
500 if (!PyArg_ParseTuple(args, "")) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
501 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
502 if (self->use) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
503 PyErr_SetString(_mysql_ProgrammingError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
504 "cannot be used with connection.use_result()");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
505 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
506 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
507 r = mysql_row_tell(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
508 return PyInt_FromLong(r-self->result->data->data);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
509 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
510
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
511 static void
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
512 _mysql_ResultObject_dealloc(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
513 _mysql_ResultObject *self)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
514 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
515 PyObject_GC_UnTrack((PyObject *)self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
516 mysql_free_result(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
517 _mysql_ResultObject_clear(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
518 MyFree(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
519 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
520
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
521 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
522 _mysql_ResultObject_repr(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
523 _mysql_ResultObject *self)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
524 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
525 char buf[300];
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
526 sprintf(buf, "<_mysql.result object at %lx>",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
527 (long)self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
528 return PyString_FromString(buf);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
529 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
530
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
531 static PyMethodDef _mysql_ResultObject_methods[] = {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
532 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
533 "data_seek",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
534 (PyCFunction)_mysql_ResultObject_data_seek,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
535 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
536 _mysql_ResultObject_data_seek__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
537 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
538 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
539 "row_seek",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
540 (PyCFunction)_mysql_ResultObject_row_seek,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
541 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
542 _mysql_ResultObject_row_seek__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
543 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
544 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
545 "row_tell",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
546 (PyCFunction)_mysql_ResultObject_row_tell,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
547 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
548 _mysql_ResultObject_row_tell__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
549 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
550 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
551 "describe",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
552 (PyCFunction)_mysql_ResultObject_describe,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
553 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
554 _mysql_ResultObject_describe__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
555 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
556 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
557 "fetch_row",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
558 (PyCFunction)_mysql_ResultObject_fetch_row,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
559 METH_VARARGS | METH_KEYWORDS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
560 _mysql_ResultObject_fetch_row__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
561 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
562 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
563 "field_flags",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
564 (PyCFunction)_mysql_ResultObject_field_flags,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
565 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
566 _mysql_ResultObject_field_flags__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
567 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
568 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
569 "num_fields",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
570 (PyCFunction)_mysql_ResultObject_num_fields,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
571 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
572 _mysql_ResultObject_num_fields__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
573 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
574 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
575 "num_rows",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
576 (PyCFunction)_mysql_ResultObject_num_rows,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
577 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
578 _mysql_ResultObject_num_rows__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
579 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
580 {NULL, NULL} /* sentinel */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
581 };
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
582
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
583 static MyMemberlist(_mysql_ResultObject_memberlist)[] = {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
584 MyMember(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
585 "converter",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
586 T_OBJECT,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
587 offsetof(_mysql_ResultObject,converter),
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
588 RO,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
589 "Type conversion mapping"
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
590 ),
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
591 {NULL} /* Sentinel */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
592 };
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
593
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
594 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
595 _mysql_ResultObject_getattr(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
596 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
597 char *name)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
598 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
599 PyObject *res;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
600
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
601 res = Py_FindMethod(_mysql_ResultObject_methods, (PyObject *)self, name);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
602 if (res != NULL)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
603 return res;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
604 PyErr_Clear();
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
605 #if PY_VERSION_HEX < 0x02020000
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
606 return PyMember_Get((char *)self, _mysql_ResultObject_memberlist, name);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
607 #else
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
608 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
609 MyMemberlist(*l);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
610 for (l = _mysql_ResultObject_memberlist; l->name != NULL; l++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
611 if (strcmp(l->name, name) == 0)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
612 return PyMember_GetOne((char *)self, l);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
613 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
614 PyErr_SetString(PyExc_AttributeError, name);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
615 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
616 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
617 #endif
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
618 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
619
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
620 static int
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
621 _mysql_ResultObject_setattr(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
622 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
623 char *name,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
624 PyObject *v)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
625 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
626 if (v == NULL) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
627 PyErr_SetString(PyExc_AttributeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
628 "can't delete connection attributes");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
629 return -1;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
630 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
631 #if PY_VERSION_HEX < 0x02020000
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
632 return PyMember_Set((char *)self, _mysql_ResultObject_memberlist, name, v);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
633 #else
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
634 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
635 MyMemberlist(*l);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
636 for (l = _mysql_ResultObject_memberlist; l->name != NULL; l++)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
637 if (strcmp(l->name, name) == 0)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
638 return PyMember_SetOne((char *)self, l, v);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
639 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
640 PyErr_SetString(PyExc_AttributeError, name);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
641 return -1;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
642 #endif
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
643 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
644
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
645 PyTypeObject _mysql_ResultObject_Type = {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
646 PyObject_HEAD_INIT(NULL)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
647 0,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
648 "_mysql.result",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
649 sizeof(_mysql_ResultObject),
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
650 0,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
651 (destructor)_mysql_ResultObject_dealloc, /* tp_dealloc */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
652 0, /*tp_print*/
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
653 (getattrfunc)_mysql_ResultObject_getattr, /* tp_getattr */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
654 (setattrfunc)_mysql_ResultObject_setattr, /* tp_setattr */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
655 0, /*tp_compare*/
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
656 (reprfunc)_mysql_ResultObject_repr, /* tp_repr */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
657
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
658 /* Method suites for standard classes */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
659
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
660 0, /* (PyNumberMethods *) tp_as_number */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
661 0, /* (PySequenceMethods *) tp_as_sequence */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
662 0, /* (PyMappingMethods *) tp_as_mapping */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
663
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
664 /* More standard operations (here for binary compatibility) */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
665
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
666 0, /* (hashfunc) tp_hash */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
667 0, /* (ternaryfunc) tp_call */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
668 0, /* (reprfunc) tp_str */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
669 0, /* (getattrofunc) tp_getattro */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
670 0, /* (setattrofunc) tp_setattro */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
671
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
672 /* Functions to access object as input/output buffer */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
673 0, /* (PyBufferProcs *) tp_as_buffer */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
674
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
675 /* Flags to define presence of optional/expanded features */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
676 #if PY_VERSION_HEX < 0x02020000
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
677 Py_TPFLAGS_DEFAULT, /* (long) tp_flags */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
678 #else
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
679 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
680 #endif
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
681
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
682 _mysql_ResultObject__doc__, /* (char *) tp_doc Documentation string */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
683 #if PY_VERSION_HEX >= 0x02000000
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
684 /* Assigned meaning in release 2.0 */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
685 #if PY_VERSION_HEX >= 0x02020000
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
686 /* call function for all accessible objects */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
687 (traverseproc) _mysql_ResultObject_traverse, /* tp_traverse */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
688
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
689 /* delete references to contained objects */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
690 (inquiry) _mysql_ResultObject_clear, /* tp_clear */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
691 #else
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
692 /* not supporting pre-2.2 GC */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
693 0,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
694 0,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
695 #endif
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
696 #if PY_VERSION_HEX >= 0x02010000
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
697 /* Assigned meaning in release 2.1 */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
698 /* rich comparisons */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
699 0, /* (richcmpfunc) tp_richcompare */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
700
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
701 /* weak reference enabler */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
702 0, /* (long) tp_weaklistoffset */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
703 #if PY_VERSION_HEX >= 0x02020000
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
704 /* Added in release 2.2 */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
705 /* Iterators */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
706 0, /* (getiterfunc) tp_iter */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
707 0, /* (iternextfunc) tp_iternext */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
708
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
709 /* Attribute descriptor and subclassing stuff */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
710 (struct PyMethodDef *) _mysql_ResultObject_methods, /* tp_methods */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
711 (MyMemberlist(*)) _mysql_ResultObject_memberlist, /*tp_members */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
712 0, /* (struct getsetlist *) tp_getset; */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
713 0, /* (struct _typeobject *) tp_base; */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
714 0, /* (PyObject *) tp_dict */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
715 0, /* (descrgetfunc) tp_descr_get */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
716 0, /* (descrsetfunc) tp_descr_set */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
717 0, /* (long) tp_dictoffset */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
718 (initproc)_mysql_ResultObject_Initialize, /* tp_init */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
719 NULL, /* tp_alloc */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
720 NULL, /* tp_new */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
721 NULL, /* tp_free Low-level free-memory routine */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
722 0, /* (PyObject *) tp_bases */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
723 0, /* (PyObject *) tp_mro method resolution order */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
724 0, /* (PyObject *) tp_defined */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
725 #endif /* python 2.2 */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
726 #endif /* python 2.1 */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
727 #endif /* python 2.0 */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
728 };