@@ -59,6 +59,7 @@ mod _sqlite {
5959 builtins:: {
6060 PyBaseException , PyBaseExceptionRef , PyByteArray , PyBytes , PyDict , PyDictRef , PyFloat ,
6161 PyInt , PyIntRef , PySlice , PyStr , PyStrRef , PyTuple , PyTupleRef , PyType , PyTypeRef ,
62+ PyUtf8Str , PyUtf8StrRef ,
6263 } ,
6364 convert:: IntoObject ,
6465 function:: { ArgCallable , ArgIterable , FsPath , FuncArgs , OptionalArg , PyComparisonValue } ,
@@ -848,7 +849,7 @@ mod _sqlite {
848849 }
849850
850851 impl Callable for Connection {
851- type Args = ( PyStrRef , ) ;
852+ type Args = ( PyUtf8StrRef , ) ;
852853
853854 fn call ( zelf : & Py < Self > , args : Self :: Args , vm : & VirtualMachine ) -> PyResult {
854855 if let Some ( stmt) = Statement :: new ( zelf, args. 0 , vm) ? {
@@ -983,7 +984,7 @@ mod _sqlite {
983984 #[ pymethod]
984985 fn execute (
985986 zelf : PyRef < Self > ,
986- sql : PyStrRef ,
987+ sql : PyUtf8StrRef ,
987988 parameters : OptionalArg < PyObjectRef > ,
988989 vm : & VirtualMachine ,
989990 ) -> PyResult < PyRef < Cursor > > {
@@ -995,7 +996,7 @@ mod _sqlite {
995996 #[ pymethod]
996997 fn executemany (
997998 zelf : PyRef < Self > ,
998- sql : PyStrRef ,
999+ sql : PyUtf8StrRef ,
9991000 seq_of_params : ArgIterable ,
10001001 vm : & VirtualMachine ,
10011002 ) -> PyResult < PyRef < Cursor > > {
@@ -1477,7 +1478,7 @@ mod _sqlite {
14771478 #[ pymethod]
14781479 fn execute (
14791480 zelf : PyRef < Self > ,
1480- sql : PyStrRef ,
1481+ sql : PyUtf8StrRef ,
14811482 parameters : OptionalArg < PyObjectRef > ,
14821483 vm : & VirtualMachine ,
14831484 ) -> PyResult < PyRef < Self > > {
@@ -1549,7 +1550,7 @@ mod _sqlite {
15491550 #[ pymethod]
15501551 fn executemany (
15511552 zelf : PyRef < Self > ,
1552- sql : PyStrRef ,
1553+ sql : PyUtf8StrRef ,
15531554 seq_of_params : ArgIterable ,
15541555 vm : & VirtualMachine ,
15551556 ) -> PyResult < PyRef < Self > > {
@@ -2298,10 +2299,9 @@ mod _sqlite {
22982299 impl Statement {
22992300 fn new (
23002301 connection : & Connection ,
2301- sql : PyStrRef ,
2302+ sql : PyUtf8StrRef ,
23022303 vm : & VirtualMachine ,
23032304 ) -> PyResult < Option < Self > > {
2304- let _ = sql. try_to_str ( vm) ?;
23052305 if sql. as_str ( ) . contains ( '\0' ) {
23062306 return Err ( new_programming_error (
23072307 vm,
@@ -2654,6 +2654,7 @@ mod _sqlite {
26542654 let val = val. to_f64 ( ) ;
26552655 unsafe { sqlite3_bind_double ( self . st , pos, val) }
26562656 } else if let Some ( val) = obj. downcast_ref :: < PyStr > ( ) {
2657+ let val = val. try_as_utf8 ( vm) ?;
26572658 let ( ptr, len) = str_to_ptr_len ( val, vm) ?;
26582659 unsafe { sqlite3_bind_text ( self . st , pos, ptr, len, SQLITE_TRANSIENT ( ) ) }
26592660 } else if let Ok ( buffer) = PyBuffer :: try_from_borrowed_object ( vm, obj) {
@@ -2905,6 +2906,7 @@ mod _sqlite {
29052906 } else if let Some ( val) = val. downcast_ref :: < PyFloat > ( ) {
29062907 sqlite3_result_double ( self . ctx , val. to_f64 ( ) )
29072908 } else if let Some ( val) = val. downcast_ref :: < PyStr > ( ) {
2909+ let val = val. try_as_utf8 ( vm) ?;
29082910 let ( ptr, len) = str_to_ptr_len ( val, vm) ?;
29092911 sqlite3_result_text ( self . ctx , ptr, len, SQLITE_TRANSIENT ( ) )
29102912 } else if let Ok ( buffer) = PyBuffer :: try_from_borrowed_object ( vm, val) {
@@ -2985,8 +2987,8 @@ mod _sqlite {
29852987 }
29862988 }
29872989
2988- fn str_to_ptr_len ( s : & PyStr , vm : & VirtualMachine ) -> PyResult < ( * const libc:: c_char , i32 ) > {
2989- let s_str = s. try_to_str ( vm ) ? ;
2990+ fn str_to_ptr_len ( s : & PyUtf8Str , vm : & VirtualMachine ) -> PyResult < ( * const libc:: c_char , i32 ) > {
2991+ let s_str = s. as_str ( ) ;
29902992 let len = c_int:: try_from ( s_str. len ( ) )
29912993 . map_err ( |_| vm. new_overflow_error ( "TEXT longer than INT_MAX bytes" ) ) ?;
29922994 let ptr = s_str. as_ptr ( ) . cast ( ) ;
0 commit comments