@@ -198,22 +198,31 @@ int pysqlite_build_row_cast_map(pysqlite_Cursor* self)
198198 return 0 ;
199199}
200200
201- PyObject * _pysqlite_build_column_name (const char * colname )
201+ static PyObject *
202+ _pysqlite_build_column_name (pysqlite_Cursor * self , const char * colname )
202203{
203204 const char * pos ;
205+ Py_ssize_t len ;
204206
205207 if (!colname ) {
206208 Py_RETURN_NONE ;
207209 }
208210
209- for (pos = colname ;; pos ++ ) {
210- if (* pos == 0 || * pos == '[' ) {
211- if ((* pos == '[' ) && (pos > colname ) && (* (pos - 1 ) == ' ' )) {
212- pos -- ;
211+ if (self -> connection -> detect_types & PARSE_COLNAMES ) {
212+ for (pos = colname ; * pos ; pos ++ ) {
213+ if (* pos == '[' ) {
214+ if ((pos != colname ) && (* (pos - 1 ) == ' ' )) {
215+ pos -- ;
216+ }
217+ break ;
213218 }
214- return PyUnicode_FromStringAndSize (colname , pos - colname );
215219 }
220+ len = pos - colname ;
221+ }
222+ else {
223+ len = strlen (colname );
216224 }
225+ return PyUnicode_FromStringAndSize (colname , len );
217226}
218227
219228/*
@@ -389,6 +398,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
389398 PyObject * result ;
390399 int numcols ;
391400 PyObject * descriptor ;
401+ PyObject * column_name ;
392402 PyObject * second_argument = NULL ;
393403 sqlite_int64 lastrowid ;
394404
@@ -569,7 +579,13 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
569579 if (!descriptor ) {
570580 goto error ;
571581 }
572- PyTuple_SetItem (descriptor , 0 , _pysqlite_build_column_name (sqlite3_column_name (self -> statement -> st , i )));
582+ column_name = _pysqlite_build_column_name (self ,
583+ sqlite3_column_name (self -> statement -> st , i ));
584+ if (!column_name ) {
585+ Py_DECREF (descriptor );
586+ goto error ;
587+ }
588+ PyTuple_SetItem (descriptor , 0 , column_name );
573589 Py_INCREF (Py_None ); PyTuple_SetItem (descriptor , 1 , Py_None );
574590 Py_INCREF (Py_None ); PyTuple_SetItem (descriptor , 2 , Py_None );
575591 Py_INCREF (Py_None ); PyTuple_SetItem (descriptor , 3 , Py_None );
0 commit comments