mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 08:56:34 +03:00
parent
afd7c6c284
commit
1047af03da
|
@ -6,6 +6,5 @@ include doc/README.rst doc/SUCCESS doc/COPYING.LESSER doc/pep-0249.txt
|
|||
include doc/Makefile doc/requirements.txt
|
||||
recursive-include doc/src *.rst *.py *.css Makefile
|
||||
recursive-include scripts *.py *.sh
|
||||
include scripts/maketypes.sh scripts/buildtypes.py
|
||||
include AUTHORS README.rst INSTALL LICENSE NEWS
|
||||
include MANIFEST.in setup.py setup.cfg Makefile
|
||||
|
|
|
@ -97,8 +97,6 @@
|
|||
<None Include="psycopg\typecast.h" />
|
||||
<None Include="psycopg\typecast_binary.h" />
|
||||
<None Include="psycopg\win32_support.h" />
|
||||
<None Include="scripts\buildtypes.py" />
|
||||
<None Include="scripts\maketypes.sh" />
|
||||
<None Include="ZPsycopgDA\dtml\add.dtml" />
|
||||
<None Include="ZPsycopgDA\dtml\browse.dtml" />
|
||||
<None Include="ZPsycopgDA\dtml\edit.dtml" />
|
||||
|
|
|
@ -1,119 +0,0 @@
|
|||
# -*- python -*-
|
||||
#
|
||||
# Copyright (C) 2001-2003 Federico Di Gregorio <fog@debian.org>
|
||||
#
|
||||
# This file is part of the psycopg module.
|
||||
#
|
||||
# psycopg2 is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# psycopg2 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 Lesser General Public
|
||||
# License for more details.
|
||||
#
|
||||
# this a little script that analyze a file with (TYPE, NUMBER) tuples
|
||||
# and write out C code ready for inclusion in psycopg. the generated
|
||||
# code defines the DBAPITypeObject fundamental types and warns for
|
||||
# undefined types.
|
||||
|
||||
import sys
|
||||
from string import split, strip
|
||||
|
||||
|
||||
# here is the list of the foundamental types we want to import from
|
||||
# postgresql header files
|
||||
|
||||
basic_types = (['NUMBER', ['INT8', 'INT4', 'INT2', 'FLOAT8', 'FLOAT4',
|
||||
'NUMERIC']],
|
||||
['LONGINTEGER', ['INT8']],
|
||||
['INTEGER', ['INT4', 'INT2']],
|
||||
['FLOAT', ['FLOAT8', 'FLOAT4']],
|
||||
['DECIMAL', ['NUMERIC']],
|
||||
['UNICODE', ['NAME', 'CHAR', 'TEXT', 'BPCHAR',
|
||||
'VARCHAR']],
|
||||
['STRING', ['NAME', 'CHAR', 'TEXT', 'BPCHAR',
|
||||
'VARCHAR']],
|
||||
['BOOLEAN', ['BOOL']],
|
||||
['DATETIME', ['TIMESTAMP', 'TIMESTAMPTZ',
|
||||
'TINTERVAL', 'INTERVAL']],
|
||||
['TIME', ['TIME', 'TIMETZ']],
|
||||
['DATE', ['DATE']],
|
||||
['INTERVAL', ['TINTERVAL', 'INTERVAL']],
|
||||
['BINARY', ['BYTEA']],
|
||||
['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]],
|
||||
['FLOAT', [1017, 1021, 1022]],
|
||||
['DECIMAL', [1231]],
|
||||
['UNICODE', [1002, 1003, 1009, 1014, 1015]],
|
||||
['STRING', [1002, 1003, 1009, 1014, 1015]],
|
||||
['BOOLEAN', [1000]],
|
||||
['DATETIME', [1115, 1185]],
|
||||
['TIME', [1183, 1270]],
|
||||
['DATE', [1182]],
|
||||
['INTERVAL', [1187]],
|
||||
['BINARY', [1001]],
|
||||
['ROWID', [1028, 1013]])
|
||||
|
||||
# this is the header used to compile the data in the C module
|
||||
HEADER = """
|
||||
typecastObject_initlist typecast_builtins[] = {
|
||||
"""
|
||||
|
||||
# then comes the footer
|
||||
FOOTER = """ {NULL, NULL, NULL, NULL}\n};\n"""
|
||||
|
||||
|
||||
# useful error reporting function
|
||||
def error(msg):
|
||||
"""Report an error on stderr."""
|
||||
sys.stderr.write(msg + '\n')
|
||||
|
||||
# read couples from stdin and build list
|
||||
read_types = []
|
||||
for l in sys.stdin.readlines():
|
||||
oid, val = split(l)
|
||||
read_types.append((strip(oid)[:-3], strip(val)))
|
||||
|
||||
# look for the wanted types in the read touples
|
||||
found_types = {}
|
||||
|
||||
for t in basic_types:
|
||||
k = t[0]
|
||||
found_types[k] = []
|
||||
for v in t[1]:
|
||||
found = filter(lambda x, y=v: x[0] == y, read_types)
|
||||
if len(found) == 0:
|
||||
error(v + ': value not found')
|
||||
elif len(found) > 1:
|
||||
error(v + ': too many values')
|
||||
else:
|
||||
found_types[k].append(int(found[0][1]))
|
||||
|
||||
# now outputs to stdout the right C-style definitions
|
||||
stypes = sstruct = ""
|
||||
for t in basic_types:
|
||||
k = t[0]
|
||||
s = str(found_types[k])
|
||||
s = '{' + s[1:-1] + ', 0}'
|
||||
stypes = stypes + ('static long int typecast_%s_types[] = %s;\n' % (k, s))
|
||||
sstruct += (' {"%s", typecast_%s_types, typecast_%s_cast, NULL},\n'
|
||||
% (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
|
||||
|
||||
print stypes
|
||||
print sstruct
|
|
@ -1,39 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
SCRIPTSDIR="`dirname $0`"
|
||||
SRCDIR="`dirname $SCRIPTSDIR`/psycopg"
|
||||
|
||||
if [ -z "$1" ] ; then
|
||||
echo Usage: $0 '<postgresql include directory>'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -n checking for pg_type.h ...
|
||||
if [ -f "$1/catalog/pg_type.h" ] ; then
|
||||
PGTYPE="$1/catalog/pg_type.h"
|
||||
else
|
||||
if [ -f "$1/server/catalog/pg_type.h" ] ; then
|
||||
PGTYPE="$1/server/catalog/pg_type.h"
|
||||
else
|
||||
echo
|
||||
echo "error: can't find pg_type.h under $1"
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
echo " found"
|
||||
|
||||
PGVERSION="`sed -n -e 's/.*PG_VERSION \"\([0-9]\.[0-9]\).*\"/\1/p' $1/pg_config.h`"
|
||||
PGMAJOR="`echo $PGVERSION | cut -d. -f1`"
|
||||
PGMINOR="`echo $PGVERSION | cut -d. -f2`"
|
||||
|
||||
echo checking for postgresql major: $PGMAJOR
|
||||
echo checking for postgresql minor: $PGMINOR
|
||||
|
||||
echo -n generating pgtypes.h ...
|
||||
awk '/#define .+OID/ {print "#define " $2 " " $3}' "$PGTYPE" \
|
||||
> $SRCDIR/pgtypes.h
|
||||
echo " done"
|
||||
echo -n generating typecast_builtins.c ...
|
||||
awk '/#define .+OID/ {print $2 " " $3}' "$PGTYPE" | \
|
||||
python $SCRIPTSDIR/buildtypes.py >$SRCDIR/typecast_builtins.c
|
||||
echo " done"
|
Loading…
Reference in New Issue
Block a user