mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-26 02:43:43 +03:00
Starting array work.
This commit is contained in:
parent
30b2ba6ebf
commit
07a38c31cd
|
@ -1,3 +1,10 @@
|
||||||
|
2005-03-22 Federico Di Gregorio <fog@debian.org>
|
||||||
|
|
||||||
|
* psycopg/typecast_array.c: added some more structure to implement
|
||||||
|
array typecasting.
|
||||||
|
|
||||||
|
* scripts/buildtypes.py: new version to include array data.
|
||||||
|
|
||||||
2005-03-12 Federico Di Gregorio <fog@debian.org>
|
2005-03-12 Federico Di Gregorio <fog@debian.org>
|
||||||
|
|
||||||
* psycopg/cursor_type.c (psyco_curs_executemany): implemented as a
|
* psycopg/cursor_type.c (psyco_curs_executemany): implemented as a
|
||||||
|
|
|
@ -50,6 +50,8 @@ skip_until_space(char *s)
|
||||||
#include "psycopg/typecast_datetime.c"
|
#include "psycopg/typecast_datetime.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "psycopg/typecast_array.c"
|
||||||
|
|
||||||
#include "psycopg/typecast_builtins.c"
|
#include "psycopg/typecast_builtins.c"
|
||||||
|
|
||||||
/* a list of initializers, used to make the typecasters accessible anyway */
|
/* a list of initializers, used to make the typecasters accessible anyway */
|
||||||
|
|
|
@ -51,6 +51,9 @@ typedef struct {
|
||||||
char *name;
|
char *name;
|
||||||
long int *values;
|
long int *values;
|
||||||
typecast_function cast;
|
typecast_function cast;
|
||||||
|
|
||||||
|
/* base is the base typecaster for arrays */
|
||||||
|
char *base;
|
||||||
} typecastObject_initlist;
|
} typecastObject_initlist;
|
||||||
|
|
||||||
/* the type dictionary, much faster to access it globally */
|
/* the type dictionary, much faster to access it globally */
|
||||||
|
|
55
psycopg/typecast_array.c
Normal file
55
psycopg/typecast_array.c
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/* typecast_array.c - array typecasters
|
||||||
|
*
|
||||||
|
* Copyright (C) 2005 Federico Di Gregorio <fog@debian.org>
|
||||||
|
*
|
||||||
|
* This file is part of the psycopg module.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* the pointer to the datetime module API is initialized by the module init
|
||||||
|
code, we just need to grab it */
|
||||||
|
extern PyObject* pyDateTimeModuleP;
|
||||||
|
extern PyObject *pyDateTypeP;
|
||||||
|
extern PyObject *pyTimeTypeP;
|
||||||
|
extern PyObject *pyDateTimeTypeP;
|
||||||
|
extern PyObject *pyDeltaTypeP;
|
||||||
|
|
||||||
|
/** LONGINTEGERARRAY and INTEGERARRAY - cast integers arrays **/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
typecast_INTEGERARRAY_cast(unsigned char *str, int len, PyObject *curs)
|
||||||
|
{
|
||||||
|
PyObject* obj = NULL;
|
||||||
|
|
||||||
|
if (str == NULL) {Py_INCREF(Py_None); return Py_None;}
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define typecast_LONGINTEGERARRAY_cast typecast_INTEGERARRAY_cast
|
||||||
|
|
||||||
|
/** STRINGARRAY - cast integers arrays **/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
typecast_STRINGARRAY_cast(unsigned char *str, int len, PyObject *curs)
|
||||||
|
{
|
||||||
|
PyObject* obj = NULL;
|
||||||
|
|
||||||
|
if (str == NULL) {Py_INCREF(Py_None); return Py_None;}
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
|
@ -12,23 +12,29 @@ static long int typecast_DATE_types[] = {1082, 0};
|
||||||
static long int typecast_INTERVAL_types[] = {704, 1186, 0};
|
static long int typecast_INTERVAL_types[] = {704, 1186, 0};
|
||||||
static long int typecast_BINARY_types[] = {17, 0};
|
static long int typecast_BINARY_types[] = {17, 0};
|
||||||
static long int typecast_ROWID_types[] = {26, 0};
|
static long int typecast_ROWID_types[] = {26, 0};
|
||||||
|
static long int typecast_LONGINTEGERARRAY_types[] = {1016, 0};
|
||||||
|
static long int typecast_INTEGERARRAY_types[] = {1005, 1006, 1007, 0};
|
||||||
|
static long int typecast_STRINGARRAY_types[] = {1002, 1003, 1009, 1014, 1015, 0};
|
||||||
|
|
||||||
|
|
||||||
typecastObject_initlist typecast_builtins[] = {
|
typecastObject_initlist typecast_builtins[] = {
|
||||||
{"NUMBER", typecast_NUMBER_types, typecast_NUMBER_cast},
|
{"NUMBER", typecast_NUMBER_types, typecast_NUMBER_cast, NULL},
|
||||||
{"LONGINTEGER", typecast_LONGINTEGER_types, typecast_LONGINTEGER_cast},
|
{"LONGINTEGER", typecast_LONGINTEGER_types, typecast_LONGINTEGER_cast, NULL},
|
||||||
{"INTEGER", typecast_INTEGER_types, typecast_INTEGER_cast},
|
{"INTEGER", typecast_INTEGER_types, typecast_INTEGER_cast, NULL},
|
||||||
{"FLOAT", typecast_FLOAT_types, typecast_FLOAT_cast},
|
{"FLOAT", typecast_FLOAT_types, typecast_FLOAT_cast, NULL},
|
||||||
{"DECIMAL", typecast_DECIMAL_types, typecast_DECIMAL_cast},
|
{"DECIMAL", typecast_DECIMAL_types, typecast_DECIMAL_cast, NULL},
|
||||||
{"UNICODE", typecast_UNICODE_types, typecast_UNICODE_cast},
|
{"UNICODE", typecast_UNICODE_types, typecast_UNICODE_cast, NULL},
|
||||||
{"STRING", typecast_STRING_types, typecast_STRING_cast},
|
{"STRING", typecast_STRING_types, typecast_STRING_cast, NULL},
|
||||||
{"BOOLEAN", typecast_BOOLEAN_types, typecast_BOOLEAN_cast},
|
{"BOOLEAN", typecast_BOOLEAN_types, typecast_BOOLEAN_cast, NULL},
|
||||||
{"DATETIME", typecast_DATETIME_types, typecast_DATETIME_cast},
|
{"DATETIME", typecast_DATETIME_types, typecast_DATETIME_cast, NULL},
|
||||||
{"TIME", typecast_TIME_types, typecast_TIME_cast},
|
{"TIME", typecast_TIME_types, typecast_TIME_cast, NULL},
|
||||||
{"DATE", typecast_DATE_types, typecast_DATE_cast},
|
{"DATE", typecast_DATE_types, typecast_DATE_cast, NULL},
|
||||||
{"INTERVAL", typecast_INTERVAL_types, typecast_INTERVAL_cast},
|
{"INTERVAL", typecast_INTERVAL_types, typecast_INTERVAL_cast, NULL},
|
||||||
{"BINARY", typecast_BINARY_types, typecast_BINARY_cast},
|
{"BINARY", typecast_BINARY_types, typecast_BINARY_cast, NULL},
|
||||||
{"ROWID", typecast_ROWID_types, typecast_ROWID_cast},
|
{"ROWID", typecast_ROWID_types, typecast_ROWID_cast, NULL},
|
||||||
{NULL, NULL, NULL}
|
{"LONGINTEGERARRAY", typecast_LONGINTEGERARRAY_types, typecast_LONGINTEGERARRAY_cast, "LONGINTEGER"},
|
||||||
|
{"INTEGERARRAY", typecast_INTEGERARRAY_types, typecast_INTEGERARRAY_cast, "INTEGER"},
|
||||||
|
{"STRINGARRAY", typecast_STRINGARRAY_types, typecast_STRINGARRAY_cast, "STRING"},
|
||||||
|
{NULL, NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -49,13 +49,19 @@ basic_types = (['NUMBER', ['INT8', 'INT4', 'INT2', 'FLOAT8', 'FLOAT4',
|
||||||
['BINARY', ['BYTEA']],
|
['BINARY', ['BYTEA']],
|
||||||
['ROWID', ['OID']])
|
['ROWID', ['OID']])
|
||||||
|
|
||||||
|
# unfortunately we don't have a nice way to extract array information
|
||||||
|
# from postgresql headers; we'll have to do it hard-coding :/
|
||||||
|
array_types = (['LONGINTEGER', [1016]],
|
||||||
|
['INTEGER', [1005, 1006, 1007]],
|
||||||
|
['STRING', [1002, 1003, 1009, 1014, 1015]])
|
||||||
|
|
||||||
# this is the header used to compile the data in the C module
|
# this is the header used to compile the data in the C module
|
||||||
HEADER = """
|
HEADER = """
|
||||||
typecastObject_initlist typecast_builtins[] = {
|
typecastObject_initlist typecast_builtins[] = {
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# then comes the footer
|
# then comes the footer
|
||||||
FOOTER = """ {NULL, NULL, NULL}\n};\n"""
|
FOOTER = """ {NULL, NULL, NULL, NULL}\n};\n"""
|
||||||
|
|
||||||
|
|
||||||
# usefull error reporting function
|
# usefull error reporting function
|
||||||
|
@ -92,8 +98,16 @@ for t in basic_types:
|
||||||
s = str(found_types[k])
|
s = str(found_types[k])
|
||||||
s = '{' + s[1:-1] + ', 0}'
|
s = '{' + s[1:-1] + ', 0}'
|
||||||
stypes = stypes + ('static long int typecast_%s_types[] = %s;\n' % (k, s))
|
stypes = stypes + ('static long int typecast_%s_types[] = %s;\n' % (k, s))
|
||||||
sstruct = sstruct + (' {"%s", typecast_%s_types, typecast_%s_cast},\n'
|
sstruct += (' {"%s", typecast_%s_types, typecast_%s_cast, NULL},\n'
|
||||||
% (k, k, k))
|
% (k, k, k))
|
||||||
|
for t in array_types:
|
||||||
|
kt = t[0]
|
||||||
|
ka = t[0]+'ARRAY'
|
||||||
|
s = str(t[1])
|
||||||
|
s = '{' + s[1:-1] + ', 0}'
|
||||||
|
stypes = stypes + ('static long int typecast_%s_types[] = %s;\n' % (ka, s))
|
||||||
|
sstruct += (' {"%s", typecast_%s_types, typecast_%s_cast, "%s"},\n'
|
||||||
|
% (ka, ka, ka, kt))
|
||||||
sstruct = HEADER + sstruct + FOOTER
|
sstruct = HEADER + sstruct + FOOTER
|
||||||
|
|
||||||
print stypes
|
print stypes
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[build_ext]
|
[build_ext]
|
||||||
define=PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3,PSYCOPG_DEBUG
|
define=PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3
|
||||||
# PSYCOPG_DEBUG can be added to enable verbose debug information
|
# PSYCOPG_DEBUG can be added to enable verbose debug information
|
||||||
# PSYCOPG_OWN_QUOTING can be added above but it is deprecated
|
# PSYCOPG_OWN_QUOTING can be added above but it is deprecated
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user