]> granicus.if.org Git - postgresql/commitdiff
http://archives.postgresql.org/pgsql-bugs/2002-06/msg00086.php and never
authorBruce Momjian <bruce@momjian.us>
Thu, 15 Aug 2002 03:31:45 +0000 (03:31 +0000)
committerBruce Momjian <bruce@momjian.us>
Thu, 15 Aug 2002 03:31:45 +0000 (03:31 +0000)
saw a fix offered up.  Since I'm gearing up to use Postgres and Python
soon, I figured I'd have a hand at trying to get this sucker addressed.
Apologies if this has already been plugged.  I looked in the archives
and never saw a response.

At any rate, I must admit I don't think I fully understand the
implications of some of the changes I made even though they appear to be
straight forward.  We all know the devil is in the details.  Anyone more
knowledgeable is requested to review my changes. :(

I also updated the advanced.py script in a somewhat nonsensical fashion
to make use of an int8 field in an effort to test this change.  It seems
to run okay, however, this is by no means an all exhaustive test.  So,
it's possible that a bumpy road may lay ahead for some.  On the other
hand...overflows (hopefully) previously lurked (long -> int conversion).

Greg Copeland

src/interfaces/python/pgmodule.c
src/interfaces/python/tutorial/advanced.py

index df685902531bd0ff5366e9b049209858c2daaff3..355c3e4725dac729464bcfa21f90275019193790 100644 (file)
@@ -289,23 +289,26 @@ get_type_array(PGresult *result, int nfields)
                {
                        case INT2OID:
                        case INT4OID:
-                       case INT8OID:
                        case OIDOID:
                                typ[j] = 1;
                                break;
 
+                       case INT8OID:
+                               typ[j] = 2;
+                               break;
+
                        case FLOAT4OID:
                        case FLOAT8OID:
                        case NUMERICOID:
-                               typ[j] = 2;
+                               typ[j] = 3;
                                break;
 
                        case CASHOID:
-                               typ[j] = 3;
+                               typ[j] = 4;
                                break;
 
                        default:
-                               typ[j] = 4;
+                               typ[j] = 5;
                                break;
                }
        }
@@ -1797,23 +1800,26 @@ pgquery_getresult(pgqueryobject * self, PyObject * args)
                {
                        case INT2OID:
                        case INT4OID:
-                       case INT8OID:
                        case OIDOID:
                                typ[j] = 1;
                                break;
 
+                       case INT8OID:
+                               typ[j] = 2;
+                               break;
+
                        case FLOAT4OID:
                        case FLOAT8OID:
                        case NUMERICOID:
-                               typ[j] = 2;
+                               typ[j] = 3;
                                break;
 
                        case CASHOID:
-                               typ[j] = 3;
+                               typ[j] = 4;
                                break;
 
                        default:
-                               typ[j] = 4;
+                               typ[j] = 5;
                                break;
                }
        }
@@ -1846,10 +1852,14 @@ pgquery_getresult(pgqueryobject * self, PyObject * args)
                                                break;
 
                                        case 2:
-                                               val = PyFloat_FromDouble(strtod(s, NULL));
+                                               val = PyLong_FromLong(strtol(s, NULL, 10));
                                                break;
 
                                        case 3:
+                                               val = PyFloat_FromDouble(strtod(s, NULL));
+                                               break;
+
+                                       case 4:
                                                {
                                                        int                     mult = 1;
 
@@ -1946,11 +1956,14 @@ pgquery_dictresult(pgqueryobject * self, PyObject * args)
                {
                        case INT2OID:
                        case INT4OID:
-                       case INT8OID:
                        case OIDOID:
                                typ[j] = 1;
                                break;
 
+                       case INT8OID:
+                               typ[j] = 2;
+                               break;
+
                        case FLOAT4OID:
                        case FLOAT8OID:
                        case NUMERICOID:
@@ -1995,10 +2008,14 @@ pgquery_dictresult(pgqueryobject * self, PyObject * args)
                                                break;
 
                                        case 2:
-                                               val = PyFloat_FromDouble(strtod(s, NULL));
+                                               val = PyLong_FromLong(strtol(s, NULL, 10));
                                                break;
 
                                        case 3:
+                                               val = PyFloat_FromDouble(strtod(s, NULL));
+                                               break;
+
+                                       case 4:
                                                {
                                                        int                     mult = 1;
 
index 49e6e436e8cab7799b541a3d1299e0978491ef6c..41a5bc457a3341acb85b7f32a8db441a63bef46b 100755 (executable)
@@ -109,11 +109,13 @@ def array_demo(pgcnx):
        print "CREATE TABLE sal_emp ("
        print "    name            text,"
        print "    pay_by_quarter  int4[],"
+       print "    pay_by_extra_quarter  int8[],"
        print "    schedule        text[][]"
        print ")"
        pgcnx.query("""CREATE TABLE sal_emp (
         name              text,
         pay_by_quarter    int4[],
+        pay_by_extra_quarter    int8[],
         schedule          text[][])""")
        wait_key()
        print
@@ -123,18 +125,22 @@ def array_demo(pgcnx):
        print "INSERT INTO sal_emp VALUES ("
        print "    'Bill',"
        print "    '{10000,10000,10000,10000}',"
+       print "    '{9223372036854775800,9223372036854775800,9223372036854775800}',"
        print "    '{{\"meeting\", \"lunch\"}, {}}')"
        print
        print "INSERT INTO sal_emp VALUES ("
        print "    'Carol',"
        print "    '{20000,25000,25000,25000}',"
+       print "    '{9223372036854775807,9223372036854775807,9223372036854775807}',"
        print "    '{{\"talk\", \"consult\"}, {\"meeting\"}}')"
        print
        pgcnx.query("""INSERT INTO sal_emp VALUES (
         'Bill', '{10000,10000,10000,10000}',
+       '{9223372036854775800,9223372036854775800,9223372036854775800}',
         '{{\"meeting\", \"lunch\"}, {}}')""")
        pgcnx.query("""INSERT INTO sal_emp VALUES (
         'Carol', '{20000,25000,25000,25000}',
+       '{9223372036854775807,9223372036854775807,9223372036854775807}',
         '{{\"talk\", \"consult\"}, {\"meeting\"}}')""")
        wait_key()
        print
@@ -148,12 +154,26 @@ def array_demo(pgcnx):
        print pgcnx.query("""SELECT name FROM sal_emp WHERE
         sal_emp.pay_by_quarter[1] <> sal_emp.pay_by_quarter[2]""")
        print
+       print pgcnx.query("""SELECT name FROM sal_emp WHERE
+        sal_emp.pay_by_extra_quarter[1] <> sal_emp.pay_by_extra_quarter[2]""")
+       print
        print "-- retrieve third quarter pay of all employees"
        print 
        print "SELECT sal_emp.pay_by_quarter[3] FROM sal_emp"
        print
        print pgcnx.query("SELECT sal_emp.pay_by_quarter[3] FROM sal_emp")
        print
+       print "-- retrieve third quarter extra pay of all employees"
+       print 
+       print "SELECT sal_emp.pay_by_extra_quarter[3] FROM sal_emp"
+       print pgcnx.query("SELECT sal_emp.pay_by_extra_quarter[3] FROM sal_emp")
+       print 
+       print "-- retrieve first two quarters of extra quarter pay of all employees"
+       print 
+       print "SELECT sal_emp.pay_by_extra_quarter[1:2] FROM sal_emp"
+       print
+       print pgcnx.query("SELECT sal_emp.pay_by_extra_quarter[1:2] FROM sal_emp")
+       print
        print "-- select subarrays"
        print 
        print "SELECT sal_emp.schedule[1:2][1:1] FROM sal_emp WHERE"