[Sqlrelay-discussion] loose type checking in the Python API's setBind
Brought to you by:
mused
|
From: Andrew L. <ala...@bo...> - 2005-11-10 18:47:52
|
In my code, object to PySQLRClient.sqlrcursor.inputBind that I
thought was a simple string, but had accidentally been upgraded to a
unicode string. To my surprise, there were no errors reported, but
the bind just was ignored entirely.
Looking at the C code for the Python CSQLRelay extension, I see that
inputBind is a long if/else if sequence with no default else clause.
if (value==Py_None) {
((sqlrcursor *)sqlrcur)->inputBind(variable, (char *)NULL);
} else if (PyString_Check(value)) {
((sqlrcursor *)sqlrcur)->inputBind(variable, PyString_AsString
(value));
} else if (PyInt_Check(value)) {
((sqlrcursor *)sqlrcur)->inputBind(variable, (long)PyInt_AsLong
(value));
} else if (PyFloat_Check(value)) {
((sqlrcursor *)sqlrcur)->inputBind(variable, (double)
PyFloat_AsDouble(value)
, (unsigned short)precision, (unsigned short)scale);
}
Should .inputBind return a status to say in bound correctly? Should
it through a TypeError? Should it try to coerce its input into one of
the four simple types it knows about?
Or should I just be more careful what I pass into it?
|