mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 01:14:09 +03:00
Fixed error related to calling C typecasters from Python ones
This commit is contained in:
parent
36cbefdee1
commit
6521fb5a44
|
@ -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>
|
2010-05-07 Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
||||||
|
|
||||||
* psycopg/adapter_datetime.c: Fixed TimestampFromTicks for second
|
* psycopg/adapter_datetime.c: Fixed TimestampFromTicks for second
|
||||||
|
|
|
@ -435,6 +435,15 @@ typecast_call(PyObject *obj, PyObject *args, PyObject *kwargs)
|
||||||
return NULL;
|
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,
|
return typecast_cast(obj,
|
||||||
PyString_AsString(string), PyString_Size(string),
|
PyString_AsString(string), PyString_Size(string),
|
||||||
cursor);
|
cursor);
|
||||||
|
|
|
@ -198,6 +198,7 @@
|
||||||
<None Include="sandbox\valgrind-python.supp" />
|
<None Include="sandbox\valgrind-python.supp" />
|
||||||
<None Include="psycopg\green.h" />
|
<None Include="psycopg\green.h" />
|
||||||
<None Include="doc\src\pool.rst" />
|
<None Include="doc\src\pool.rst" />
|
||||||
|
<None Include="sandbox\dec2float.py" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="psycopg\adapter_asis.c" />
|
<Compile Include="psycopg\adapter_asis.c" />
|
||||||
|
|
15
sandbox/dec2float.py
Normal file
15
sandbox/dec2float.py
Normal file
|
@ -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)
|
Loading…
Reference in New Issue
Block a user