summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Di Gregorio <fog@initd.org>2010-05-15 19:34:56 +0200
committerFederico Di Gregorio <fog@initd.org>2010-05-15 19:34:56 +0200
commit6521fb5a445ff5bc32516b970297f9dad32a1c18 (patch)
tree56558e8be61c865cf11d0e3cd3d50069fc7c8107
parent36cbefdee1920ca2c2bbb0d3a5d98f70cbc86019 (diff)
downloadpsycopg2-6521fb5a445ff5bc32516b970297f9dad32a1c18.tar.gz
Fixed error related to calling C typecasters from Python ones
-rw-r--r--ChangeLog5
-rw-r--r--psycopg/typecast.c9
-rw-r--r--psycopg2.cproj1
-rw-r--r--sandbox/dec2float.py15
4 files changed, 30 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index f4a81e1..233aba3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-04-05 Federico Di Gregorio <fog@initd.org>
+
+ * typecast.c: Fixed problem related to receiving None from Python
+ when a string was expected.
+
2010-05-07 Daniele Varrazzo <daniele.varrazzo@gmail.com>
* psycopg/adapter_datetime.c: Fixed TimestampFromTicks for second
diff --git a/psycopg/typecast.c b/psycopg/typecast.c
index 7b303e2..3866dbf 100644
--- a/psycopg/typecast.c
+++ b/psycopg/typecast.c
@@ -435,6 +435,15 @@ typecast_call(PyObject *obj, PyObject *args, PyObject *kwargs)
return NULL;
}
+ // If the string is not a string but a None value we're being called
+ // from a Python-defined caster. There is no need to convert, just
+ // return it.
+
+ if (string == Py_None) {
+ Py_INCREF(string);
+ return string;
+ }
+
return typecast_cast(obj,
PyString_AsString(string), PyString_Size(string),
cursor);
diff --git a/psycopg2.cproj b/psycopg2.cproj
index 72bd11b..620858f 100644
--- a/psycopg2.cproj
+++ b/psycopg2.cproj
@@ -198,6 +198,7 @@
<None Include="sandbox\valgrind-python.supp" />
<None Include="psycopg\green.h" />
<None Include="doc\src\pool.rst" />
+ <None Include="sandbox\dec2float.py" />
</ItemGroup>
<ItemGroup>
<Compile Include="psycopg\adapter_asis.c" />
diff --git a/sandbox/dec2float.py b/sandbox/dec2float.py
new file mode 100644
index 0000000..2006e0a
--- /dev/null
+++ b/sandbox/dec2float.py
@@ -0,0 +1,15 @@
+import psycopg2
+import psycopg2.extensions
+
+DEC2FLOAT = psycopg2.extensions.new_type(
+ psycopg2._psycopg.DECIMAL.values,
+ 'DEC2FLOAT',
+ psycopg2.extensions.FLOAT)
+
+psycopg2.extensions.register_type(DEC2FLOAT)
+
+o = psycopg2.connect("dbname=test")
+c = o.cursor()
+c.execute("SELECT NULL::decimal(10,2)")
+n = c.fetchone()[0]
+print n, type(n)