|
11 | 11 | #include "sqlwchar.h" |
12 | 12 | #include <datetime.h> |
13 | 13 |
|
14 | | -void Params_init() |
15 | | -{ |
16 | | - PyDateTime_IMPORT; |
17 | | -} |
18 | | - |
19 | 14 |
|
20 | 15 | inline Connection* GetConnection(Cursor* cursor) |
21 | 16 | { |
@@ -125,6 +120,17 @@ static bool GetNullInfo(Cursor* cur, Py_ssize_t index, ParamInfo& info) |
125 | 120 | return true; |
126 | 121 | } |
127 | 122 |
|
| 123 | +static bool GetNullBinaryInfo(Cursor* cur, Py_ssize_t index, ParamInfo& info) |
| 124 | +{ |
| 125 | + info.ValueType = SQL_C_BINARY; |
| 126 | + info.ParameterType = SQL_BINARY; |
| 127 | + info.ColumnSize = 1; |
| 128 | + info.ParameterValuePtr = 0; |
| 129 | + info.StrLen_or_Ind = SQL_NULL_DATA; |
| 130 | + return true; |
| 131 | +} |
| 132 | + |
| 133 | + |
128 | 134 | static bool GetBytesInfo(Cursor* cur, Py_ssize_t index, PyObject* param, ParamInfo& info) |
129 | 135 | { |
130 | 136 | // In Python 2, a bytes object (ANSI string) is passed as varchar. In Python 3, it is passed as binary. |
@@ -534,6 +540,9 @@ static bool GetParameterInfo(Cursor* cur, Py_ssize_t index, PyObject* param, Par |
534 | 540 | if (param == Py_None) |
535 | 541 | return GetNullInfo(cur, index, info); |
536 | 542 |
|
| 543 | + if (param == null_binary) |
| 544 | + return GetNullBinaryInfo(cur, index, info); |
| 545 | + |
537 | 546 | if (PyBytes_Check(param)) |
538 | 547 | return GetBytesInfo(cur, index, param, info); |
539 | 548 |
|
@@ -811,3 +820,50 @@ static bool GetParamType(Cursor* cur, Py_ssize_t index, SQLSMALLINT& type) |
811 | 820 | type = cur->paramtypes[index]; |
812 | 821 | return true; |
813 | 822 | } |
| 823 | + |
| 824 | +struct NullParam |
| 825 | +{ |
| 826 | + PyObject_HEAD |
| 827 | +}; |
| 828 | + |
| 829 | + |
| 830 | +PyTypeObject NullParamType = |
| 831 | +{ |
| 832 | + PyVarObject_HEAD_INIT(NULL, 0) |
| 833 | + "pyodbc.NullParam", // tp_name |
| 834 | + sizeof(NullParam), // tp_basicsize |
| 835 | + 0, // tp_itemsize |
| 836 | + 0, // destructor tp_dealloc |
| 837 | + 0, // tp_print |
| 838 | + 0, // tp_getattr |
| 839 | + 0, // tp_setattr |
| 840 | + 0, // tp_compare |
| 841 | + 0, // tp_repr |
| 842 | + 0, // tp_as_number |
| 843 | + 0, // tp_as_sequence |
| 844 | + 0, // tp_as_mapping |
| 845 | + 0, // tp_hash |
| 846 | + 0, // tp_call |
| 847 | + 0, // tp_str |
| 848 | + 0, // tp_getattro |
| 849 | + 0, // tp_setattro |
| 850 | + 0, // tp_as_buffer |
| 851 | + Py_TPFLAGS_DEFAULT, // tp_flags |
| 852 | +}; |
| 853 | + |
| 854 | +PyObject* null_binary; |
| 855 | + |
| 856 | +bool Params_init() |
| 857 | +{ |
| 858 | + if (PyType_Ready(&NullParamType) < 0) |
| 859 | + return false; |
| 860 | + |
| 861 | + null_binary = (PyObject*)PyObject_New(NullParam, &NullParamType); |
| 862 | + if (null_binary == 0) |
| 863 | + return false; |
| 864 | + |
| 865 | + PyDateTime_IMPORT; |
| 866 | + |
| 867 | + return true; |
| 868 | +} |
| 869 | + |
0 commit comments