@@ -546,7 +546,6 @@ PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_
546546 int i ;
547547 sqlite3_value * cur_value ;
548548 PyObject * cur_py_value ;
549- const char * val_str ;
550549 Py_ssize_t buflen ;
551550
552551 args = PyTuple_New (argc );
@@ -563,16 +562,19 @@ PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_
563562 case SQLITE_FLOAT :
564563 cur_py_value = PyFloat_FromDouble (sqlite3_value_double (cur_value ));
565564 break ;
566- case SQLITE_TEXT :
567- val_str = (const char * )sqlite3_value_text (cur_value );
568- cur_py_value = PyUnicode_FromString (val_str );
569- /* TODO: have a way to show errors here */
570- if (!cur_py_value ) {
571- PyErr_Clear ();
572- Py_INCREF (Py_None );
573- cur_py_value = Py_None ;
565+ case SQLITE_TEXT : {
566+ sqlite3 * db = sqlite3_context_db_handle (context );
567+ const char * text = (const char * )sqlite3_value_text (cur_value );
568+
569+ if (text == NULL && sqlite3_errcode (db ) == SQLITE_NOMEM ) {
570+ PyErr_NoMemory ();
571+ goto error ;
574572 }
573+
574+ Py_ssize_t size = sqlite3_value_bytes (cur_value );
575+ cur_py_value = PyUnicode_FromStringAndSize (text , size );
575576 break ;
577+ }
576578 case SQLITE_BLOB :
577579 buflen = sqlite3_value_bytes (cur_value );
578580 cur_py_value = PyBytes_FromStringAndSize (
@@ -585,15 +587,18 @@ PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_
585587 }
586588
587589 if (!cur_py_value ) {
588- Py_DECREF (args );
589- return NULL ;
590+ goto error ;
590591 }
591592
592593 PyTuple_SetItem (args , i , cur_py_value );
593594
594595 }
595596
596597 return args ;
598+
599+ error :
600+ Py_DECREF (args );
601+ return NULL ;
597602}
598603
599604void _pysqlite_func_callback (sqlite3_context * context , int argc , sqlite3_value * * argv )
0 commit comments