@@ -6,6 +6,7 @@ extern crate lazy_static;
6
6
mod types;
7
7
8
8
use crate :: types:: libsql_config;
9
+ use libsql:: { errors, LoadExtensionGuard } ;
9
10
use tokio:: runtime:: Runtime ;
10
11
use types:: {
11
12
blob, libsql_connection, libsql_connection_t, libsql_database, libsql_database_t, libsql_row,
@@ -301,6 +302,55 @@ pub unsafe extern "C" fn libsql_connect(
301
302
0
302
303
}
303
304
305
+ #[ no_mangle]
306
+ pub unsafe extern "C" fn libsql_load_extension (
307
+ conn : libsql_connection_t ,
308
+ path : * const std:: ffi:: c_char ,
309
+ entry_point : * const std:: ffi:: c_char ,
310
+ out_err_msg : * mut * const std:: ffi:: c_char ,
311
+ ) -> std:: ffi:: c_int {
312
+ if path. is_null ( ) {
313
+ set_err_msg ( "Null path" . to_string ( ) , out_err_msg) ;
314
+ return 1 ;
315
+ }
316
+ let path = unsafe { std:: ffi:: CStr :: from_ptr ( path) } ;
317
+ let path = match path. to_str ( ) {
318
+ Ok ( path) => path,
319
+ Err ( e) => {
320
+ set_err_msg ( format ! ( "Wrong path: {}" , e) , out_err_msg) ;
321
+ return 2 ;
322
+ }
323
+ } ;
324
+ let mut entry_point_option = None ;
325
+ if !entry_point. is_null ( ) {
326
+ let entry_point = unsafe { std:: ffi:: CStr :: from_ptr ( entry_point) } ;
327
+ entry_point_option = match entry_point. to_str ( ) {
328
+ Ok ( entry_point) => Some ( entry_point) ,
329
+ Err ( e) => {
330
+ set_err_msg ( format ! ( "Wrong entry point: {}" , e) , out_err_msg) ;
331
+ return 4 ;
332
+ }
333
+ } ;
334
+ }
335
+ if conn. is_null ( ) {
336
+ set_err_msg ( "Null connection" . to_string ( ) , out_err_msg) ;
337
+ return 5 ;
338
+ }
339
+ let conn = conn. get_ref ( ) ;
340
+ match RT . block_on ( async move {
341
+ let _guard = LoadExtensionGuard :: new ( conn) ?;
342
+ conn. load_extension ( path, entry_point_option) ?;
343
+ Ok :: < ( ) , errors:: Error > ( ( ) )
344
+ } ) {
345
+ Ok ( ( ) ) => { }
346
+ Err ( e) => {
347
+ set_err_msg ( format ! ( "Error loading extension: {}" , e) , out_err_msg) ;
348
+ return 6 ;
349
+ }
350
+ } ;
351
+ 0
352
+ }
353
+
304
354
#[ no_mangle]
305
355
pub unsafe extern "C" fn libsql_reset (
306
356
conn : libsql_connection_t ,
0 commit comments