Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit147aa84

Browse files
committed
saw a fix offered up. Since I'm gearing up to use Postgres and Pythonsoon, 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 archivesand never saw a response.At any rate, I must admit I don't think I fully understand theimplications of some of the changes I made even though they appear to bestraight forward. We all know the devil is in the details. Anyone moreknowledgeable is requested to review my changes. :(I also updated the advanced.py script in a somewhat nonsensical fashionto make use of an int8 field in an effort to test this change. It seemsto 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 otherhand...overflows (hopefully) previously lurked (long -> int conversion).Greg Copeland
1 parentdb14700 commit147aa84

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

‎src/interfaces/python/pgmodule.c‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,23 +289,26 @@ get_type_array(PGresult *result, int nfields)
289289
{
290290
caseINT2OID:
291291
caseINT4OID:
292-
caseINT8OID:
293292
caseOIDOID:
294293
typ[j]=1;
295294
break;
296295

296+
caseINT8OID:
297+
typ[j]=2;
298+
break;
299+
297300
caseFLOAT4OID:
298301
caseFLOAT8OID:
299302
caseNUMERICOID:
300-
typ[j]=2;
303+
typ[j]=3;
301304
break;
302305

303306
caseCASHOID:
304-
typ[j]=3;
307+
typ[j]=4;
305308
break;
306309

307310
default:
308-
typ[j]=4;
311+
typ[j]=5;
309312
break;
310313
}
311314
}
@@ -1797,23 +1800,26 @@ pgquery_getresult(pgqueryobject * self, PyObject * args)
17971800
{
17981801
caseINT2OID:
17991802
caseINT4OID:
1800-
caseINT8OID:
18011803
caseOIDOID:
18021804
typ[j]=1;
18031805
break;
18041806

1807+
caseINT8OID:
1808+
typ[j]=2;
1809+
break;
1810+
18051811
caseFLOAT4OID:
18061812
caseFLOAT8OID:
18071813
caseNUMERICOID:
1808-
typ[j]=2;
1814+
typ[j]=3;
18091815
break;
18101816

18111817
caseCASHOID:
1812-
typ[j]=3;
1818+
typ[j]=4;
18131819
break;
18141820

18151821
default:
1816-
typ[j]=4;
1822+
typ[j]=5;
18171823
break;
18181824
}
18191825
}
@@ -1846,10 +1852,14 @@ pgquery_getresult(pgqueryobject * self, PyObject * args)
18461852
break;
18471853

18481854
case2:
1849-
val=PyFloat_FromDouble(strtod(s,NULL));
1855+
val=PyLong_FromLong(strtol(s,NULL,10));
18501856
break;
18511857

18521858
case3:
1859+
val=PyFloat_FromDouble(strtod(s,NULL));
1860+
break;
1861+
1862+
case4:
18531863
{
18541864
intmult=1;
18551865

@@ -1946,11 +1956,14 @@ pgquery_dictresult(pgqueryobject * self, PyObject * args)
19461956
{
19471957
caseINT2OID:
19481958
caseINT4OID:
1949-
caseINT8OID:
19501959
caseOIDOID:
19511960
typ[j]=1;
19521961
break;
19531962

1963+
caseINT8OID:
1964+
typ[j]=2;
1965+
break;
1966+
19541967
caseFLOAT4OID:
19551968
caseFLOAT8OID:
19561969
caseNUMERICOID:
@@ -1995,10 +2008,14 @@ pgquery_dictresult(pgqueryobject * self, PyObject * args)
19952008
break;
19962009

19972010
case2:
1998-
val=PyFloat_FromDouble(strtod(s,NULL));
2011+
val=PyLong_FromLong(strtol(s,NULL,10));
19992012
break;
20002013

20012014
case3:
2015+
val=PyFloat_FromDouble(strtod(s,NULL));
2016+
break;
2017+
2018+
case4:
20022019
{
20032020
intmult=1;
20042021

‎src/interfaces/python/tutorial/advanced.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,13 @@ def array_demo(pgcnx):
109109
print"CREATE TABLE sal_emp ("
110110
print" name text,"
111111
print" pay_by_quarter int4[],"
112+
print" pay_by_extra_quarter int8[],"
112113
print" schedule text[][]"
113114
print")"
114115
pgcnx.query("""CREATE TABLE sal_emp (
115116
name text,
116117
pay_by_quarter int4[],
118+
pay_by_extra_quarter int8[],
117119
schedule text[][])""")
118120
wait_key()
119121
print
@@ -123,18 +125,22 @@ def array_demo(pgcnx):
123125
print"INSERT INTO sal_emp VALUES ("
124126
print" 'Bill',"
125127
print" '{10000,10000,10000,10000}',"
128+
print" '{9223372036854775800,9223372036854775800,9223372036854775800}',"
126129
print" '{{\"meeting\",\"lunch\"}, {}}')"
127130
print
128131
print"INSERT INTO sal_emp VALUES ("
129132
print" 'Carol',"
130133
print" '{20000,25000,25000,25000}',"
134+
print" '{9223372036854775807,9223372036854775807,9223372036854775807}',"
131135
print" '{{\"talk\",\"consult\"}, {\"meeting\"}}')"
132136
print
133137
pgcnx.query("""INSERT INTO sal_emp VALUES (
134138
'Bill', '{10000,10000,10000,10000}',
139+
'{9223372036854775800,9223372036854775800,9223372036854775800}',
135140
'{{\"meeting\",\"lunch\"}, {}}')""")
136141
pgcnx.query("""INSERT INTO sal_emp VALUES (
137142
'Carol', '{20000,25000,25000,25000}',
143+
'{9223372036854775807,9223372036854775807,9223372036854775807}',
138144
'{{\"talk\",\"consult\"}, {\"meeting\"}}')""")
139145
wait_key()
140146
print
@@ -148,12 +154,26 @@ def array_demo(pgcnx):
148154
printpgcnx.query("""SELECT name FROM sal_emp WHERE
149155
sal_emp.pay_by_quarter[1] <> sal_emp.pay_by_quarter[2]""")
150156
print
157+
printpgcnx.query("""SELECT name FROM sal_emp WHERE
158+
sal_emp.pay_by_extra_quarter[1] <> sal_emp.pay_by_extra_quarter[2]""")
159+
print
151160
print"-- retrieve third quarter pay of all employees"
152161
print
153162
print"SELECT sal_emp.pay_by_quarter[3] FROM sal_emp"
154163
print
155164
printpgcnx.query("SELECT sal_emp.pay_by_quarter[3] FROM sal_emp")
156165
print
166+
print"-- retrieve third quarter extra pay of all employees"
167+
print
168+
print"SELECT sal_emp.pay_by_extra_quarter[3] FROM sal_emp"
169+
printpgcnx.query("SELECT sal_emp.pay_by_extra_quarter[3] FROM sal_emp")
170+
print
171+
print"-- retrieve first two quarters of extra quarter pay of all employees"
172+
print
173+
print"SELECT sal_emp.pay_by_extra_quarter[1:2] FROM sal_emp"
174+
print
175+
printpgcnx.query("SELECT sal_emp.pay_by_extra_quarter[1:2] FROM sal_emp")
176+
print
157177
print"-- select subarrays"
158178
print
159179
print"SELECT sal_emp.schedule[1:2][1:1] FROM sal_emp WHERE"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp