Permalink
Browse files

Fixed error related to calling C typecasters from Python ones

  • Loading branch information...
1 parent 36cbefd commit 6521fb5a445ff5bc32516b970297f9dad32a1c18 @fogzot fogzot committed May 15, 2010
Showing with 30 additions and 0 deletions.
  1. +5 −0 ChangeLog
  2. +9 −0 psycopg/typecast.c
  3. +1 −0 psycopg2.cproj
  4. +15 −0 sandbox/dec2float.py
View
@@ -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
View
@@ -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);
View
@@ -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" />
View
@@ -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)

0 comments on commit 6521fb5

Please sign in to comment.