annotate src/results.c @ 74:80164eb2f090 MySQLdb

This passes all test, yet is still broken and ugly in many ways. However, a lot of ugliness has been removed.
author adustman
date Sat, 20 Feb 2010 04:27:21 +0000
parents 24fa6a40c706
children 3b03cb566032
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
1 /* -*- mode: C; indent-tabs-mode: t; c-basic-offset: 8; -*- */
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
2
55
e606fd52e866 make things a little cleaner by moving to a src directory for the C code
kylev
parents: 53
diff changeset
3 #include "mysqlmod.h"
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
4
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
5 static PyObject *
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
6 _mysql_ResultObject_get_fields(
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
7 _mysql_ResultObject *self,
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
8 PyObject *unused)
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
9 {
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
10 PyObject *arglist=NULL, *kwarglist=NULL;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
11 PyObject *fields=NULL;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
12 _mysql_FieldObject *field=NULL;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
13 unsigned int i, n;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
14
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
15 check_result_connection(self);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
16 kwarglist = PyDict_New();
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
17 if (!kwarglist) goto error;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
18 n = mysql_num_fields(self->result);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
19 if (!(fields = PyTuple_New(n))) return NULL;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
20 for (i=0; i<n; i++) {
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
21 arglist = Py_BuildValue("(Oi)", self, i);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
22 if (!arglist) goto error;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
23 field = MyAlloc(_mysql_FieldObject, _mysql_FieldObject_Type);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
24 if (!field) goto error;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
25 if (_mysql_FieldObject_Initialize(field, arglist, kwarglist))
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
26 goto error;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
27 Py_DECREF(arglist);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
28 PyTuple_SET_ITEM(fields, i, (PyObject *) field);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
29 }
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
30 Py_DECREF(kwarglist);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
31 return fields;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
32 error:
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
33 Py_XDECREF(arglist);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
34 Py_XDECREF(kwarglist);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
35 Py_XDECREF(fields);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
36 return NULL;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
37 }
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
38
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
39 static char _mysql_ResultObject__doc__[] =
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
40 "result(connection, use=0, decoder_stack=[]) -- Result set from a query.\n\
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
41 \n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
42 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
43 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
44 use connection.store_result() or connection.use_result() instead.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
45 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
46 Just forget you ever saw this. Forget... FOR-GET...";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
47
2
c0d1fc0429ce Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents: 1
diff changeset
48 int
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
49 _mysql_ResultObject_Initialize(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
50 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
51 PyObject *args,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
52 PyObject *kwargs)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
53 {
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
54 static char *kwlist[] = {"connection", "use", "decoder_stack", NULL};
45
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
55 MYSQL_RES *result;
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
56 _mysql_ConnectionObject *conn = NULL;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
57 int use = 0;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
58 PyObject *decoder_stack = NULL;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
59 int n, ns, i, j;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
60
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
61 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iO", kwlist,
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
62 &conn, &use, &decoder_stack))
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
63 return -1;
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
64 if (!decoder_stack) decoder_stack = PyList_New(0);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
65 if (!decoder_stack) return -1;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
66 self->conn = (PyObject *) conn;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
67 Py_INCREF(conn);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
68 self->use = use;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
69 Py_BEGIN_ALLOW_THREADS ;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
70 if (use)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
71 result = mysql_use_result(&(conn->connection));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
72 else
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
73 result = mysql_store_result(&(conn->connection));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
74 self->result = result;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
75 Py_END_ALLOW_THREADS ;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
76 if (!result) {
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
77 self->decoders = PyTuple_New(0);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
78 return 0;
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 n = mysql_num_fields(result);
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
81 ns = PySequence_Length(decoder_stack);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
82 self->nfields = n;
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
83 if (!(self->decoders = PyTuple_New(n))) return -1;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
84 self->fields = _mysql_ResultObject_get_fields(self, NULL);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
85 for (i=0; i<n; i++) {
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
86 PyObject *field = PyTuple_GET_ITEM(self->fields, i);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
87 for (j=0; j<ns; j++) {
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
88 PyObject *df = PySequence_GetItem(decoder_stack, j);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
89 if (!df) goto error;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
90 PyObject *f = PyObject_CallFunctionObjArgs(df, field, NULL);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
91 Py_DECREF(df);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
92 if (!f) goto error;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
93 if (f != Py_None) {
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
94 PyTuple_SET_ITEM(self->decoders, i, f);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
95 break;
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
96 }
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
97 Py_DECREF(f);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
98 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
99 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
100 return 0;
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
101 error:
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
102 return -1;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
103 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
104
45
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
105 static int
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
106 _mysql_ResultObject_traverse(
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
107 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
108 visitproc visit,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
109 void *arg)
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 int r;
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
112 if (self->decoders) {
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
113 if (!(r = visit(self->decoders, arg))) return r;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
114 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
115 if (self->conn)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
116 return visit(self->conn, arg);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
117 return 0;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
118 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
119
45
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
120 static int
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
121 _mysql_ResultObject_clear(
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
122 _mysql_ResultObject *self)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
123 {
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
124 Py_XDECREF(self->decoders);
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
125 self->decoders = NULL;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
126 Py_XDECREF(self->conn);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
127 self->conn = NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
128 return 0;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
129 }
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
130
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
131 static char _mysql_ResultObject_describe__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
132 "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
133 the Cursor.description attribute.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
134 ";
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 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
137 _mysql_ResultObject_describe(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
138 _mysql_ResultObject *self,
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
139 PyObject *unused)
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
140 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
141 PyObject *d;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
142 MYSQL_FIELD *fields;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
143 unsigned int i, n;
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
144
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
145 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
146 n = mysql_num_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
147 fields = mysql_fetch_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
148 if (!(d = PyTuple_New(n))) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
149 for (i=0; i<n; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
150 PyObject *t;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
151 t = Py_BuildValue("(siiiiii)",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
152 fields[i].name,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
153 (long) fields[i].type,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
154 (long) fields[i].max_length,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
155 (long) fields[i].length,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
156 (long) fields[i].length,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
157 (long) fields[i].decimals,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
158 (long) !(IS_NOT_NULL(fields[i].flags)));
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
159 if (!t) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
160 PyTuple_SET_ITEM(d, i, t);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
161 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
162 return d;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
163 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
164 Py_XDECREF(d);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
165 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
166 }
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 2
diff changeset
167
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
168 static char _mysql_ResultObject_field_flags__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
169 "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
170 " ;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
171
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
172 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
173 _mysql_ResultObject_field_flags(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
174 _mysql_ResultObject *self,
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
175 PyObject *unused)
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
176 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
177 PyObject *d;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
178 MYSQL_FIELD *fields;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
179 unsigned int i, n;
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
180
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
181 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
182 n = mysql_num_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
183 fields = mysql_fetch_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
184 if (!(d = PyTuple_New(n))) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
185 for (i=0; i<n; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
186 PyObject *f;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
187 if (!(f = PyInt_FromLong((long)fields[i].flags))) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
188 PyTuple_SET_ITEM(d, i, f);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
189 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
190 return d;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
191 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
192 Py_XDECREF(d);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
193 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
194 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
195
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
196 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
197 _mysql_field_to_python(
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
198 PyObject *decoder,
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
199 char *rowitem,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
200 unsigned long length)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
201 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
202 PyObject *v;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
203 if (rowitem) {
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
204 if (decoder != Py_None)
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
205 v = PyObject_CallFunction(decoder,
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
206 "s#",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
207 rowitem,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
208 (int)length);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
209 else
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
210 v = PyString_FromStringAndSize(rowitem,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
211 (int)length);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
212 if (!v)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
213 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
214 } else {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
215 Py_INCREF(Py_None);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
216 v = Py_None;
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 return v;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
219 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
220
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
221 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
222 _mysql_row_to_tuple(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
223 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
224 MYSQL_ROW row)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
225 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
226 unsigned int n, i;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
227 unsigned long *length;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
228 PyObject *r, *c;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
229
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
230 n = mysql_num_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
231 if (!(r = PyTuple_New(n))) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
232 length = mysql_fetch_lengths(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
233 for (i=0; i<n; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
234 PyObject *v;
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
235 c = PyTuple_GET_ITEM(self->decoders, i);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
236 v = _mysql_field_to_python(c, row[i], length[i]);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
237 if (!v) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
238 PyTuple_SET_ITEM(r, i, v);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
239 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
240 return r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
241 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
242 Py_XDECREF(r);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
243 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
244 }
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 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
247 _mysql_row_to_dict(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
248 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
249 MYSQL_ROW row)
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 unsigned int n, i;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
252 unsigned long *length;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
253 PyObject *r, *c;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
254 MYSQL_FIELD *fields;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
255
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
256 n = mysql_num_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
257 if (!(r = PyDict_New())) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
258 length = mysql_fetch_lengths(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
259 fields = mysql_fetch_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
260 for (i=0; i<n; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
261 PyObject *v;
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
262 c = PyTuple_GET_ITEM(self->decoders, i);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
263 v = _mysql_field_to_python(c, row[i], length[i]);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
264 if (!v) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
265 if (!PyMapping_HasKeyString(r, fields[i].name)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
266 PyMapping_SetItemString(r, fields[i].name, v);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
267 } else {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
268 int len;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
269 char buf[256];
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
270 strncpy(buf, fields[i].table, 256);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
271 len = strlen(buf);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
272 strncat(buf, ".", 256-len);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
273 len = strlen(buf);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
274 strncat(buf, fields[i].name, 256-len);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
275 PyMapping_SetItemString(r, buf, v);
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 Py_DECREF(v);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
278 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
279 return r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
280 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
281 Py_XDECREF(r);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
282 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
283 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
284
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
285 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
286 _mysql_row_to_dict_old(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
287 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
288 MYSQL_ROW row)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
289 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
290 unsigned int n, i;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
291 unsigned long *length;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
292 PyObject *r, *c;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
293 MYSQL_FIELD *fields;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
294
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
295 n = mysql_num_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
296 if (!(r = PyDict_New())) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
297 length = mysql_fetch_lengths(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
298 fields = mysql_fetch_fields(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
299 for (i=0; i<n; i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
300 PyObject *v;
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
301 c = PyTuple_GET_ITEM(self->decoders, i);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
302 v = _mysql_field_to_python(c, row[i], length[i]);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
303 if (!v) goto error;
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 int len=0;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
306 char buf[256]="";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
307 if (strlen(fields[i].table)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
308 strncpy(buf, fields[i].table, 256);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
309 len = strlen(buf);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
310 strncat(buf, ".", 256-len);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
311 len = strlen(buf);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
312 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
313 strncat(buf, fields[i].name, 256-len);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
314 PyMapping_SetItemString(r, buf, v);
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 Py_DECREF(v);
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 return r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
319 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
320 Py_XDECREF(r);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
321 return NULL;
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
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
324 typedef PyObject *_PYFUNC(_mysql_ResultObject *, MYSQL_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 int
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
327 _mysql__fetch_row(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
328 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
329 PyObject **r,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
330 int skiprows,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
331 int maxrows,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
332 _PYFUNC *convert_row)
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 unsigned int i;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
335 MYSQL_ROW row;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
336
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
337 for (i = skiprows; i<(skiprows+maxrows); i++) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
338 PyObject *v;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
339 if (!self->use)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
340 row = mysql_fetch_row(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
341 else {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
342 Py_BEGIN_ALLOW_THREADS;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
343 row = mysql_fetch_row(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
344 Py_END_ALLOW_THREADS;
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 if (!row && mysql_errno(&(((_mysql_ConnectionObject *)(self->conn))->connection))) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
347 _mysql_Exception((_mysql_ConnectionObject *)self->conn);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
348 goto error;
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 if (!row) {
44
2b9a9814daab _PyTuple_Resize is stable since 2.2, so we don't need the macro MyTuple_Resize
kylev
parents: 42
diff changeset
351 if (_PyTuple_Resize(r, i) == -1) goto error;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
352 break;
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 v = convert_row(self, row);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
355 if (!v) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
356 PyTuple_SET_ITEM(*r, i, v);
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 return i-skiprows;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
359 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
360 return -1;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
361 }
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 static char _mysql_ResultObject_fetch_row__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
364 "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
365 The rows are formatted according to how:\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
366 \n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
367 0 -- tuples (default)\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
368 1 -- dictionaries, key=column or table.column if duplicated\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
369 2 -- dictionaries, key=table.column\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
370 ";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
371
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
372 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
373 _mysql_ResultObject_fetch_row(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
374 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
375 PyObject *args,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
376 PyObject *kwargs)
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 typedef PyObject *_PYFUNC(_mysql_ResultObject *, MYSQL_ROW);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
379 static char *kwlist[] = { "maxrows", "how", NULL };
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
380 static _PYFUNC *row_converters[] =
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 _mysql_row_to_tuple,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
383 _mysql_row_to_dict,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
384 _mysql_row_to_dict_old
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
385 };
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
386 _PYFUNC *convert_row;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
387 unsigned int maxrows=1, how=0, skiprows=0, rowsadded;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
388 PyObject *r=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 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ii:fetch_row", kwlist,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
391 &maxrows, &how))
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
392 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
393 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
394 if (how < 0 || how >= sizeof(row_converters)) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
395 PyErr_SetString(PyExc_ValueError, "how out of range");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
396 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
397 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
398 convert_row = row_converters[how];
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
399 if (maxrows) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
400 if (!(r = PyTuple_New(maxrows))) goto error;
44
2b9a9814daab _PyTuple_Resize is stable since 2.2, so we don't need the macro MyTuple_Resize
kylev
parents: 42
diff changeset
401 rowsadded = _mysql__fetch_row(self, &r, skiprows, maxrows,
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
402 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 } else {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
405 if (self->use) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
406 maxrows = 1000;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
407 if (!(r = PyTuple_New(maxrows))) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
408 while (1) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
409 rowsadded = _mysql__fetch_row(self, &r, skiprows,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
410 maxrows, convert_row);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
411 if (rowsadded == -1) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
412 skiprows += rowsadded;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
413 if (rowsadded < maxrows) break;
44
2b9a9814daab _PyTuple_Resize is stable since 2.2, so we don't need the macro MyTuple_Resize
kylev
parents: 42
diff changeset
414 if (_PyTuple_Resize(&r, skiprows + maxrows) == -1)
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
415 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 } else {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
418 /* XXX if overflow, maxrows<0? */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
419 maxrows = (int) mysql_num_rows(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
420 if (!(r = PyTuple_New(maxrows))) goto error;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
421 rowsadded = _mysql__fetch_row(self, &r, 0,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
422 maxrows, convert_row);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
423 if (rowsadded == -1) goto error;
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 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
426 return r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
427 error:
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
428 Py_XDECREF(r);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
429 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
430 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
431
73
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
432 static char _mysql_ResultObject_simple_fetch_row__doc__[] =
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
433 "simple_fetchrow()\n\
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
434 Fetches one row as a tuple of strings.\n\
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
435 NULL is returned as None.\n\
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
436 ";
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
437
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
438 static PyObject *
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
439 _mysql_ResultObject_simple_fetch_row(
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
440 _mysql_ResultObject *self,
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
441 PyObject *unused)
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
442 {
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
443 unsigned int n, i;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
444 unsigned long *length;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
445 PyObject *r=NULL;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
446 MYSQL_ROW row;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
447
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
448 check_result_connection(self);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
449
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
450 if (!self->use)
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
451 row = mysql_fetch_row(self->result);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
452 else {
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
453 Py_BEGIN_ALLOW_THREADS;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
454 row = mysql_fetch_row(self->result);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
455 Py_END_ALLOW_THREADS;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
456 }
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
457 if (!row && mysql_errno(&(((_mysql_ConnectionObject *)(self->conn))->connection))) {
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
458 _mysql_Exception((_mysql_ConnectionObject *)self->conn);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
459 goto error;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
460 }
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
461 if (!row) {
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
462 Py_INCREF(Py_None);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
463 return Py_None;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
464 }
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
465
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
466 n = mysql_num_fields(self->result);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
467 if (!(r = PyTuple_New(n))) return NULL;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
468 length = mysql_fetch_lengths(self->result);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
469 for (i=0; i<n; i++) {
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
470 PyObject *v;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
471 if (row[i]) {
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
472 v = PyString_FromStringAndSize(row[i], length[i]);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
473 if (!v) goto error;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
474 } else /* NULL */ {
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
475 v = Py_None;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
476 Py_INCREF(v);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
477 }
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
478 PyTuple_SET_ITEM(r, i, v);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
479 }
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
480 return r;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
481 error:
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
482 Py_XDECREF(r);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
483 return NULL;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
484 }
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
485
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
486 static PyObject *
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
487 _mysql_ResultObject__iter__(
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
488 _mysql_ResultObject *self,
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
489 PyObject *unused)
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
490 {
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
491 check_result_connection(self);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
492 Py_INCREF(self);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
493 return (PyObject *)self;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
494 }
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
495
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
496 static PyObject *
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
497 _mysql_ResultObject_next(
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
498 _mysql_ResultObject *self,
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
499 PyObject *unused)
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
500 {
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
501 PyObject *row;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
502 check_result_connection(self);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
503 row = _mysql_ResultObject_simple_fetch_row(self, NULL);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
504 if (row == Py_None) {
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
505 Py_DECREF(row);
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
506 PyErr_SetString(PyExc_StopIteration, "");
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
507 return NULL;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
508 }
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
509 return row;
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
510 }
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
511
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
512 static char _mysql_ResultObject_num_fields__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
513 "Returns the number of fields (column) in the result." ;
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 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
516 _mysql_ResultObject_num_fields(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
517 _mysql_ResultObject *self,
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
518 PyObject *unused)
0
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 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
521 return PyInt_FromLong((long)mysql_num_fields(self->result));
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
522 }
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
523
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
524 static char _mysql_ResultObject_num_rows__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
525 "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
526 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
527 set has been read.\n\
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
528 ";
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 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
531 _mysql_ResultObject_num_rows(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
532 _mysql_ResultObject *self,
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
533 PyObject *unused)
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
534 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
535 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
536 return PyLong_FromUnsignedLongLong(mysql_num_rows(self->result));
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
537 }
0
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
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
540 static char _mysql_ResultObject_data_seek__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
541 "data_seek(n) -- seek to row n of result set";
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
542 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
543 _mysql_ResultObject_data_seek(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
544 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
545 PyObject *args)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
546 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
547 unsigned int row;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
548 if (!PyArg_ParseTuple(args, "i:data_seek", &row)) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
549 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
550 mysql_data_seek(self->result, row);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
551 Py_INCREF(Py_None);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
552 return Py_None;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
553 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
554
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
555 static char _mysql_ResultObject_row_seek__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
556 "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
557 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
558 _mysql_ResultObject_row_seek(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
559 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
560 PyObject *args)
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 int offset;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
563 MYSQL_ROW_OFFSET r;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
564 if (!PyArg_ParseTuple(args, "i:row_seek", &offset)) return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
565 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
566 if (self->use) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
567 PyErr_SetString(_mysql_ProgrammingError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
568 "cannot be used with connection.use_result()");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
569 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
570 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
571 r = mysql_row_tell(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
572 mysql_row_seek(self->result, r+offset);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
573 Py_INCREF(Py_None);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
574 return Py_None;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
575 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
576
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
577 static char _mysql_ResultObject_row_tell__doc__[] =
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
578 "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
579 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
580 _mysql_ResultObject_row_tell(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
581 _mysql_ResultObject *self,
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
582 PyObject *unused)
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
583 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
584 MYSQL_ROW_OFFSET r;
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
585
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
586 check_result_connection(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
587 if (self->use) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
588 PyErr_SetString(_mysql_ProgrammingError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
589 "cannot be used with connection.use_result()");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
590 return NULL;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
591 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
592 r = mysql_row_tell(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
593 return PyInt_FromLong(r-self->result->data->data);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
594 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
595
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
596 static void
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
597 _mysql_ResultObject_dealloc(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
598 _mysql_ResultObject *self)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
599 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
600 PyObject_GC_UnTrack((PyObject *)self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
601 mysql_free_result(self->result);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
602 _mysql_ResultObject_clear(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
603 MyFree(self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
604 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
605
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
606 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
607 _mysql_ResultObject_repr(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
608 _mysql_ResultObject *self)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
609 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
610 char buf[300];
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
611 sprintf(buf, "<_mysql.result object at %lx>",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
612 (long)self);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
613 return PyString_FromString(buf);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
614 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
615
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
616 static PyMethodDef _mysql_ResultObject_methods[] = {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
617 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
618 "data_seek",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
619 (PyCFunction)_mysql_ResultObject_data_seek,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
620 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
621 _mysql_ResultObject_data_seek__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
622 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
623 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
624 "row_seek",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
625 (PyCFunction)_mysql_ResultObject_row_seek,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
626 METH_VARARGS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
627 _mysql_ResultObject_row_seek__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
628 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
629 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
630 "row_tell",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
631 (PyCFunction)_mysql_ResultObject_row_tell,
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
632 METH_NOARGS,
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
633 _mysql_ResultObject_row_tell__doc__
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 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
636 "describe",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
637 (PyCFunction)_mysql_ResultObject_describe,
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
638 METH_NOARGS,
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
639 _mysql_ResultObject_describe__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
640 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
641 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
642 "fetch_row",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
643 (PyCFunction)_mysql_ResultObject_fetch_row,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
644 METH_VARARGS | METH_KEYWORDS,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
645 _mysql_ResultObject_fetch_row__doc__
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
646 },
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
647 {
73
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
648 "simple_fetch_row",
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
649 (PyCFunction)_mysql_ResultObject_simple_fetch_row,
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
650 METH_VARARGS | METH_KEYWORDS,
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
651 _mysql_ResultObject_simple_fetch_row__doc__
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
652 },
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
653
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
654 {
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
655 "field_flags",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
656 (PyCFunction)_mysql_ResultObject_field_flags,
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
657 METH_NOARGS,
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
658 _mysql_ResultObject_field_flags__doc__
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 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
661 "num_fields",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
662 (PyCFunction)_mysql_ResultObject_num_fields,
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
663 METH_NOARGS,
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
664 _mysql_ResultObject_num_fields__doc__
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 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
667 "num_rows",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
668 (PyCFunction)_mysql_ResultObject_num_rows,
26
9863f08a337c Last of the METH_NOARGS conversions.
kylev
parents: 18
diff changeset
669 METH_NOARGS,
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
670 _mysql_ResultObject_num_rows__doc__
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 {NULL, NULL} /* sentinel */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
673 };
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
674
42
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
675 static struct PyMemberDef _mysql_ResultObject_memberlist[] = {
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
676 {
66
5a7c30cd9de2 By exposing connection on result, decoders can be simplified: Only the field object is needed. Turned on leak testing and found a leak writing BLOBs. removed one of the old stubs in Cursor.
adustman
parents: 55
diff changeset
677 "connection",
5a7c30cd9de2 By exposing connection on result, decoders can be simplified: Only the field object is needed. Turned on leak testing and found a leak writing BLOBs. removed one of the old stubs in Cursor.
adustman
parents: 55
diff changeset
678 T_OBJECT,
5a7c30cd9de2 By exposing connection on result, decoders can be simplified: Only the field object is needed. Turned on leak testing and found a leak writing BLOBs. removed one of the old stubs in Cursor.
adustman
parents: 55
diff changeset
679 offsetof(_mysql_ConnectionObject, connection),
5a7c30cd9de2 By exposing connection on result, decoders can be simplified: Only the field object is needed. Turned on leak testing and found a leak writing BLOBs. removed one of the old stubs in Cursor.
adustman
parents: 55
diff changeset
680 RO,
5a7c30cd9de2 By exposing connection on result, decoders can be simplified: Only the field object is needed. Turned on leak testing and found a leak writing BLOBs. removed one of the old stubs in Cursor.
adustman
parents: 55
diff changeset
681 "Connection associated with result"
5a7c30cd9de2 By exposing connection on result, decoders can be simplified: Only the field object is needed. Turned on leak testing and found a leak writing BLOBs. removed one of the old stubs in Cursor.
adustman
parents: 55
diff changeset
682 },
5a7c30cd9de2 By exposing connection on result, decoders can be simplified: Only the field object is needed. Turned on leak testing and found a leak writing BLOBs. removed one of the old stubs in Cursor.
adustman
parents: 55
diff changeset
683 {
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
684 "decoders",
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
685 T_OBJECT,
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
686 offsetof(_mysql_ResultObject, decoders),
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
687 RO,
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
688 "Field decoders for result set"
42
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
689 },
67
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
690 {
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
691 "fields",
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
692 T_OBJECT,
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
693 offsetof(_mysql_ResultObject, fields),
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
694 RO,
98d968f5af11 Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents: 66
diff changeset
695 "Field metadata for result set"
73
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
696 },
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
697 {
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
698 "use",
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
699 T_INT,
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
700 offsetof(_mysql_ResultObject, use),
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
701 RO,
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
702 "True if mysql_use_result() was used; False if mysql_store_result() was used"
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
703 },
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
704 {NULL} /* Sentinel */
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
705 };
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
706
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
707 static PyObject *
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
708 _mysql_ResultObject_getattr(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
709 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
710 char *name)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
711 {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
712 PyObject *res;
42
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
713 struct PyMemberDef *l;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
714
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
715 res = Py_FindMethod(_mysql_ResultObject_methods, (PyObject *)self, name);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
716 if (res != NULL)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
717 return res;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
718 PyErr_Clear();
42
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
719
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
720 for (l = _mysql_ResultObject_memberlist; l->name != NULL; l++) {
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
721 if (strcmp(l->name, name) == 0)
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
722 return PyMember_GetOne((char *)self, l);
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
723 }
42
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
724
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
725 PyErr_SetString(PyExc_AttributeError, name);
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
726 return NULL;
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
727 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
728
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
729 static int
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
730 _mysql_ResultObject_setattr(
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
731 _mysql_ResultObject *self,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
732 char *name,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
733 PyObject *v)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
734 {
42
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
735 struct PyMemberDef *l;
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
736
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
737 if (v == NULL) {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
738 PyErr_SetString(PyExc_AttributeError,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
739 "can't delete connection attributes");
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
740 return -1;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
741 }
42
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
742
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
743 for (l = _mysql_ResultObject_memberlist; l->name != NULL; l++)
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
744 if (strcmp(l->name, name) == 0)
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
745 return PyMember_SetOne((char *)self, l, v);
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
746
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
747 PyErr_SetString(PyExc_AttributeError, name);
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
748 return -1;
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
749 }
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
750
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
751 PyTypeObject _mysql_ResultObject_Type = {
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
752 PyObject_HEAD_INIT(NULL)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
753 0,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
754 "_mysql.result",
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
755 sizeof(_mysql_ResultObject),
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
756 0,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
757 (destructor)_mysql_ResultObject_dealloc, /* tp_dealloc */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
758 0, /*tp_print*/
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
759 (getattrfunc)_mysql_ResultObject_getattr, /* tp_getattr */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
760 (setattrfunc)_mysql_ResultObject_setattr, /* tp_setattr */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
761 0, /*tp_compare*/
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
762 (reprfunc)_mysql_ResultObject_repr, /* tp_repr */
45
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
763
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
764 /* Method suites for standard classes */
45
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
765
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
766 0, /* (PyNumberMethods *) tp_as_number */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
767 0, /* (PySequenceMethods *) tp_as_sequence */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
768 0, /* (PyMappingMethods *) tp_as_mapping */
45
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
769
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
770 /* More standard operations (here for binary compatibility) */
45
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
771
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
772 0, /* (hashfunc) tp_hash */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
773 0, /* (ternaryfunc) tp_call */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
774 0, /* (reprfunc) tp_str */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
775 0, /* (getattrofunc) tp_getattro */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
776 0, /* (setattrofunc) tp_setattro */
45
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
777
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
778 /* Functions to access object as input/output buffer */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
779 0, /* (PyBufferProcs *) tp_as_buffer */
45
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
780
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
781 /* Flags to define presence of optional/expanded features */
45
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
782 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /* (long) tp_flags */
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
783
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
784 _mysql_ResultObject__doc__, /* (char *) tp_doc Documentation string */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
785 /* call function for all accessible objects */
45
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
786 (traverseproc)_mysql_ResultObject_traverse, /* tp_traverse */
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
787 /* delete references to contained objects */
45
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
788 (inquiry)_mysql_ResultObject_clear, /* tp_clear */
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
789
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
790 /* rich comparisons */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
791 0, /* (richcmpfunc) tp_richcompare */
45
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
792
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
793 /* weak reference enabler */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
794 0, /* (long) tp_weaklistoffset */
45
28e9be1ca559 Remove more pre-py2.3 ifdef workarounds
kylev
parents: 44
diff changeset
795
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
796 /* Iterators */
73
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
797 (getiterfunc) _mysql_ResultObject__iter__, /* (getiterfunc) tp_iter */
24fa6a40c706 Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents: 67
diff changeset
798 (iternextfunc) _mysql_ResultObject_next, /* (iternextfunc) tp_iternext */
42
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
799
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
800 /* Attribute descriptor and subclassing stuff */
42
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
801 (struct PyMethodDef *)_mysql_ResultObject_methods, /* tp_methods */
fdf0cabb27be Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents: 26
diff changeset
802 (struct PyMemberDef *)_mysql_ResultObject_memberlist, /*tp_members */
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
803 0, /* (struct getsetlist *) tp_getset; */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
804 0, /* (struct _typeobject *) tp_base; */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
805 0, /* (PyObject *) tp_dict */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
806 0, /* (descrgetfunc) tp_descr_get */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
807 0, /* (descrsetfunc) tp_descr_set */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
808 0, /* (long) tp_dictoffset */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
809 (initproc)_mysql_ResultObject_Initialize, /* tp_init */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
810 NULL, /* tp_alloc */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
811 NULL, /* tp_new */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
812 NULL, /* tp_free Low-level free-memory routine */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
813 0, /* (PyObject *) tp_bases */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
814 0, /* (PyObject *) tp_mro method resolution order */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
815 0, /* (PyObject *) tp_defined */
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
816 };