@@ -810,24 +810,48 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
810810
811811PyObject * pysqlite_connection_create_function (pysqlite_Connection * self , PyObject * args , PyObject * kwargs )
812812{
813- static char * kwlist [] = {"name" , "narg" , "func" , NULL , NULL };
813+ static char * kwlist [] = {"name" , "narg" , "func" , "deterministic" , NULL };
814814
815815 PyObject * func ;
816816 char * name ;
817817 int narg ;
818818 int rc ;
819+ int deterministic = 0 ;
820+ int flags = SQLITE_UTF8 ;
819821
820822 if (!pysqlite_check_thread (self ) || !pysqlite_check_connection (self )) {
821823 return NULL ;
822824 }
823825
824- if (!PyArg_ParseTupleAndKeywords (args , kwargs , "siO" , kwlist ,
825- & name , & narg , & func ))
826+ if (!PyArg_ParseTupleAndKeywords (args , kwargs , "siO|$p " , kwlist ,
827+ & name , & narg , & func , & deterministic ))
826828 {
827829 return NULL ;
828830 }
829831
830- rc = sqlite3_create_function (self -> db , name , narg , SQLITE_UTF8 , (void * )func , _pysqlite_func_callback , NULL , NULL );
832+ if (deterministic ) {
833+ #if SQLITE_VERSION_NUMBER < 3008003
834+ PyErr_SetString (pysqlite_NotSupportedError ,
835+ "deterministic=True requires SQLite 3.8.3 or higher" );
836+ return NULL ;
837+ #else
838+ if (sqlite3_libversion_number () < 3008003 ) {
839+ PyErr_SetString (pysqlite_NotSupportedError ,
840+ "deterministic=True requires SQLite 3.8.3 or higher" );
841+ return NULL ;
842+ }
843+ flags |= SQLITE_DETERMINISTIC ;
844+ #endif
845+ }
846+
847+ rc = sqlite3_create_function (self -> db ,
848+ name ,
849+ narg ,
850+ flags ,
851+ (void * )func ,
852+ _pysqlite_func_callback ,
853+ NULL ,
854+ NULL );
831855
832856 if (rc != SQLITE_OK ) {
833857 /* Workaround for SQLite bug: no error code or string is available here */
0 commit comments