comparison _mysql_fields.c @ 43:e36420b7ae6e MySQLdb

Member stuff is stable post py2.2, so remove the MyMember* workarounds
author kylev
date Tue, 17 Feb 2009 05:55:48 +0000
parents c3ecc32aea27
children 28e9be1ca559
comparison
equal deleted inserted replaced
42:fdf0cabb27be 43:e36420b7ae6e
1 /* -*- mode: C; indent-tabs-mode: t; c-basic-offset: 8; -*- */
2
1 #include "_mysql.h" 3 #include "_mysql.h"
2 4
3 static char _mysql_FieldObject__doc__[] = 5 static char _mysql_FieldObject__doc__[] =
4 ""; 6 "";
5 7
66 68
67 static PyMethodDef _mysql_FieldObject_methods[] = { 69 static PyMethodDef _mysql_FieldObject_methods[] = {
68 {NULL, NULL} /* sentinel */ 70 {NULL, NULL} /* sentinel */
69 }; 71 };
70 72
71 static MyMemberlist(_mysql_FieldObject_memberlist)[] = { 73 static struct PyMemberDef _mysql_FieldObject_memberlist[] = {
72 MyMember( 74 {
73 "result", 75 "result",
74 T_OBJECT, 76 T_OBJECT,
75 offsetof(_mysql_FieldObject,result), 77 offsetof(_mysql_FieldObject, result),
76 RO, 78 RO,
77 "Result set" 79 "Result set"
78 ), 80 },
79 MyMember( 81 {
80 "name", 82 "name",
81 T_STRING, 83 T_STRING,
82 offsetof(_mysql_FieldObject,field.name), 84 offsetof(_mysql_FieldObject, field.name),
83 RO, 85 RO,
84 "The name of the field. If the field was given\n\ 86 "The name of the field. If the field was given\n\
85 an alias with an AS clause, the value of name is the alias." 87 an alias with an AS clause, the value of name is the alias."
86 ), 88 },
87 MyMember( 89 {
88 "org_name", 90 "org_name",
89 T_STRING, 91 T_STRING,
90 offsetof(_mysql_FieldObject,field.org_name), 92 offsetof(_mysql_FieldObject, field.org_name),
91 RO, 93 RO,
92 "The name of the field. Aliases are ignored." 94 "The name of the field. Aliases are ignored."
93 ), 95 },
94 MyMember( 96 {
95 "table", 97 "table",
96 T_STRING, 98 T_STRING,
97 offsetof(_mysql_FieldObject,field.table), 99 offsetof(_mysql_FieldObject, field.table),
98 RO, 100 RO,
99 "The name of the table containing this field,\n\ 101 "The name of the table containing this field,\n\
100 if it isn't a calculated field. For calculated fields,\n\ 102 if it isn't a calculated field. For calculated fields,\n\
101 the table value is an empty string. If the column is selected from a view,\n\ 103 the table value is an empty string. If the column is selected from a view,\n\
102 table names the view. If the table or view was given an alias with an AS clause,\n\ 104 table names the view. If the table or view was given an alias with an AS clause,\n\
103 the value of table is the alias.\n" 105 the value of table is the alias.\n"
104 ), 106 },
105 MyMember( 107 {
106 "org_table", 108 "org_table",
107 T_STRING, 109 T_STRING,
108 offsetof(_mysql_FieldObject,field.org_table), 110 offsetof(_mysql_FieldObject, field.org_table),
109 RO, 111 RO,
110 "The name of the table. Aliases are ignored.\n\ 112 "The name of the table. Aliases are ignored.\n\
111 If the column is selected from a view, org_table names the underlying table.\n" 113 If the column is selected from a view, org_table names the underlying table.\n"
112 ), 114 },
113 MyMember( 115 {
114 "db", 116 "db",
115 T_STRING, 117 T_STRING,
116 offsetof(_mysql_FieldObject,field.db), 118 offsetof(_mysql_FieldObject, field.db),
117 RO, 119 RO,
118 "The name of the database that the field comes from.\n\ 120 "The name of the database that the field comes from.\n\
119 If the field is a calculated field, db is an empty string." 121 If the field is a calculated field, db is an empty string."
120 ), 122 },
121 MyMember( 123 {
122 "catalog", 124 "catalog",
123 T_STRING, 125 T_STRING,
124 offsetof(_mysql_FieldObject,field.catalog), 126 offsetof(_mysql_FieldObject, field.catalog),
125 RO, 127 RO,
126 "The catalog name. This value is always \"def\"." 128 "The catalog name. This value is always \"def\"."
127 ), 129 },
128 MyMember( 130 {
129 "length", 131 "length",
130 T_ULONG, 132 T_ULONG,
131 offsetof(_mysql_FieldObject,field.length), 133 offsetof(_mysql_FieldObject, field.length),
132 RO, 134 RO,
133 "The width of the field.\n\ 135 "The width of the field.\n\
134 as specified in the table definition.\n" 136 as specified in the table definition.\n"
135 ), 137 },
136 MyMember( 138 {
137 "max_length", 139 "max_length",
138 T_ULONG, 140 T_ULONG,
139 offsetof(_mysql_FieldObject,field.max_length), 141 offsetof(_mysql_FieldObject, field.max_length),
140 RO, 142 RO,
141 "The maximum width of the field for the result set\n\ 143 "The maximum width of the field for the result set\n\
142 (the length of the longest field value for the rows actually in the\n\ 144 (the length of the longest field value for the rows actually in the\n\
143 result set). If you use conn.store_result(), this contains the\n\ 145 result set). If you use conn.store_result(), this contains the\n\
144 maximum length for the field. If you use conn.use_result(),\n\ 146 maximum length for the field. If you use conn.use_result(),\n\
145 the value of this variable is zero.\n" 147 the value of this variable is zero.\n"
146 ), 148 },
147 MyMember( 149 {
148 "decimals", 150 "decimals",
149 T_UINT, 151 T_UINT,
150 offsetof(_mysql_FieldObject,field.decimals), 152 offsetof(_mysql_FieldObject, field.decimals),
151 RO, 153 RO,
152 "The number of decimals for numeric fields.\n" 154 "The number of decimals for numeric fields.\n"
153 ), 155 },
154 MyMember( 156 {
155 "charsetnr", 157 "charsetnr",
156 T_UINT, 158 T_UINT,
157 offsetof(_mysql_FieldObject,field.charsetnr), 159 offsetof(_mysql_FieldObject, field.charsetnr),
158 RO, 160 RO,
159 "The character set number for the field." 161 "The character set number for the field."
160 ), 162 },
161 MyMember( 163 {
162 "flags", 164 "flags",
163 T_UINT, 165 T_UINT,
164 offsetof(_mysql_FieldObject,field.flags), 166 offsetof(_mysql_FieldObject, field.flags),
165 RO, 167 RO,
166 "Different bit-flags for the field.\n\ 168 "Different bit-flags for the field.\n\
167 The bits are enumerated in MySQLdb.constants.FLAG.\n\ 169 The bits are enumerated in MySQLdb.constants.FLAG.\n\
168 The flags value may have zero or more of these bits set.\n" 170 The flags value may have zero or more of these bits set.\n"
169 ), 171 },
170 MyMember( 172 {
171 "type", 173 "type",
172 T_UINT, 174 T_UINT,
173 offsetof(_mysql_FieldObject,field.type), 175 offsetof(_mysql_FieldObject, field.type),
174 RO, 176 RO,
175 "The type of the field. The type values\n\ 177 "The type of the field. The type values\n\
176 are enumerated in MySQLdb.constants.FIELD_TYPE.\n" 178 are enumerated in MySQLdb.constants.FIELD_TYPE.\n"
177 ), 179 },
178 {NULL} /* Sentinel */ 180 {NULL} /* Sentinel */
179 }; 181 };
180 182
181 static PyObject * 183 static PyObject *
182 _mysql_FieldObject_getattr( 184 _mysql_FieldObject_getattr(
183 _mysql_FieldObject *self, 185 _mysql_FieldObject *self,
184 char *name) 186 char *name)
185 { 187 {
186 PyObject *res; 188 PyObject *res;
189 struct PyMemberDef *l;
187 190
188 res = Py_FindMethod(_mysql_FieldObject_methods, (PyObject *)self, name); 191 res = Py_FindMethod(_mysql_FieldObject_methods, (PyObject *)self, name);
189 if (res != NULL) 192 if (res != NULL)
190 return res; 193 return res;
191 PyErr_Clear(); 194 PyErr_Clear();
192 #if PY_VERSION_HEX < 0x02020000 195
193 return PyMember_Get((char *)self, _mysql_FieldObject_memberlist, name); 196 for (l = _mysql_FieldObject_memberlist; l->name != NULL; l++) {
194 #else 197 if (strcmp(l->name, name) == 0)
195 { 198 return PyMember_GetOne((char *)self, l);
196 MyMemberlist(*l);
197 for (l = _mysql_FieldObject_memberlist; l->name != NULL; l++) {
198 if (strcmp(l->name, name) == 0)
199 return PyMember_GetOne((char *)self, l);
200 }
201 PyErr_SetString(PyExc_AttributeError, name);
202 return NULL;
203 } 199 }
204 #endif 200
201 PyErr_SetString(PyExc_AttributeError, name);
202 return NULL;
205 } 203 }
206 204
207 static int 205 static int
208 _mysql_FieldObject_setattr( 206 _mysql_FieldObject_setattr(
209 _mysql_FieldObject *self, 207 _mysql_FieldObject *self,
210 char *name, 208 char *name,
211 PyObject *v) 209 PyObject *v)
212 { 210 {
211 struct PyMemberDef *l;
212
213 if (v == NULL) { 213 if (v == NULL) {
214 PyErr_SetString(PyExc_AttributeError, 214 PyErr_SetString(PyExc_AttributeError,
215 "can't delete attributes"); 215 "can't delete attributes");
216 return -1; 216 return -1;
217 } 217 }
218 #if PY_VERSION_HEX < 0x02020000 218
219 return PyMember_Set((char *)self, _mysql_FieldObject_memberlist, name, v); 219
220 #else 220 for (l = _mysql_FieldObject_memberlist; l->name != NULL; l++)
221 { 221 if (strcmp(l->name, name) == 0)
222 MyMemberlist(*l); 222 return PyMember_SetOne((char *)self, l, v);
223 for (l = _mysql_FieldObject_memberlist; l->name != NULL; l++) 223
224 if (strcmp(l->name, name) == 0)
225 return PyMember_SetOne((char *)self, l, v);
226 }
227 PyErr_SetString(PyExc_AttributeError, name); 224 PyErr_SetString(PyExc_AttributeError, name);
228 return -1; 225 return -1;
229 #endif
230 } 226 }
231 227
232 PyTypeObject _mysql_FieldObject_Type = { 228 PyTypeObject _mysql_FieldObject_Type = {
233 PyObject_HEAD_INIT(NULL) 229 PyObject_HEAD_INIT(NULL)
234 0, 230 0,
290 #if PY_VERSION_HEX >= 0x02020000 286 #if PY_VERSION_HEX >= 0x02020000
291 /* Added in release 2.2 */ 287 /* Added in release 2.2 */
292 /* Iterators */ 288 /* Iterators */
293 0, /* (getiterfunc) tp_iter */ 289 0, /* (getiterfunc) tp_iter */
294 0, /* (iternextfunc) tp_iternext */ 290 0, /* (iternextfunc) tp_iternext */
295 291
296 /* Attribute descriptor and subclassing stuff */ 292 /* Attribute descriptor and subclassing stuff */
297 (struct PyMethodDef *) _mysql_FieldObject_methods, /* tp_methods */ 293 (struct PyMethodDef *)_mysql_FieldObject_methods, /* tp_methods */
298 (MyMemberlist(*)) _mysql_FieldObject_memberlist, /*tp_members */ 294 (struct PyMemberDef *)_mysql_FieldObject_memberlist, /*tp_members */
299 0, /* (struct getsetlist *) tp_getset; */ 295 0, /* (struct getsetlist *) tp_getset; */
300 0, /* (struct _typeobject *) tp_base; */ 296 0, /* (struct _typeobject *) tp_base; */
301 0, /* (PyObject *) tp_dict */ 297 0, /* (PyObject *) tp_dict */
302 0, /* (descrgetfunc) tp_descr_get */ 298 0, /* (descrgetfunc) tp_descr_get */
303 0, /* (descrsetfunc) tp_descr_set */ 299 0, /* (descrsetfunc) tp_descr_set */