11e397f8fSdrh /*
21e397f8fSdrh ** 2006 June 7
31e397f8fSdrh **
41e397f8fSdrh ** The author disclaims copyright to this source code. In place of
51e397f8fSdrh ** a legal notice, here is a blessing:
61e397f8fSdrh **
71e397f8fSdrh ** May you do good and not evil.
81e397f8fSdrh ** May you find forgiveness for yourself and forgive others.
91e397f8fSdrh ** May you share freely, never taking more than you give.
101e397f8fSdrh **
111e397f8fSdrh *************************************************************************
121e397f8fSdrh ** This file contains code used to dynamically load extensions into
131e397f8fSdrh ** the SQLite library.
141e397f8fSdrh */
151e397f8fSdrh
167c9aaa70Sdanielk1977 #ifndef SQLITE_CORE
171e397f8fSdrh #define SQLITE_CORE 1 /* Disable the API redefinition in sqlite3ext.h */
187c9aaa70Sdanielk1977 #endif
191e397f8fSdrh #include "sqlite3ext.h"
20f1952c5dSdrh #include "sqliteInt.h"
211e397f8fSdrh
229323f761Smlcreech #ifndef SQLITE_OMIT_LOAD_EXTENSION
2344e95d4fSmistachkin /*
2470df4fe6Sdrh ** Some API routines are omitted when various features are
2570df4fe6Sdrh ** excluded from a build of SQLite. Substitute a NULL pointer
2670df4fe6Sdrh ** for any missing APIs.
2770df4fe6Sdrh */
281e397f8fSdrh #ifndef SQLITE_ENABLE_COLUMN_METADATA
291e397f8fSdrh # define sqlite3_column_database_name 0
301e397f8fSdrh # define sqlite3_column_database_name16 0
311e397f8fSdrh # define sqlite3_column_table_name 0
321e397f8fSdrh # define sqlite3_column_table_name16 0
331e397f8fSdrh # define sqlite3_column_origin_name 0
341e397f8fSdrh # define sqlite3_column_origin_name16 0
351e397f8fSdrh #endif
361e397f8fSdrh
374b2688abSdanielk1977 #ifdef SQLITE_OMIT_AUTHORIZATION
384b2688abSdanielk1977 # define sqlite3_set_authorizer 0
394b2688abSdanielk1977 #endif
404b2688abSdanielk1977
414b2688abSdanielk1977 #ifdef SQLITE_OMIT_UTF16
424b2688abSdanielk1977 # define sqlite3_bind_text16 0
434b2688abSdanielk1977 # define sqlite3_collation_needed16 0
444b2688abSdanielk1977 # define sqlite3_column_decltype16 0
454b2688abSdanielk1977 # define sqlite3_column_name16 0
464b2688abSdanielk1977 # define sqlite3_column_text16 0
474b2688abSdanielk1977 # define sqlite3_complete16 0
484b2688abSdanielk1977 # define sqlite3_create_collation16 0
494b2688abSdanielk1977 # define sqlite3_create_function16 0
504b2688abSdanielk1977 # define sqlite3_errmsg16 0
514b2688abSdanielk1977 # define sqlite3_open16 0
524b2688abSdanielk1977 # define sqlite3_prepare16 0
53af30469dSdrh # define sqlite3_prepare16_v2 0
54f0f44b79Sdrh # define sqlite3_prepare16_v3 0
554b2688abSdanielk1977 # define sqlite3_result_error16 0
564b2688abSdanielk1977 # define sqlite3_result_text16 0
574b2688abSdanielk1977 # define sqlite3_result_text16be 0
584b2688abSdanielk1977 # define sqlite3_result_text16le 0
594b2688abSdanielk1977 # define sqlite3_value_text16 0
604b2688abSdanielk1977 # define sqlite3_value_text16be 0
614b2688abSdanielk1977 # define sqlite3_value_text16le 0
62af30469dSdrh # define sqlite3_column_database_name16 0
63af30469dSdrh # define sqlite3_column_table_name16 0
64af30469dSdrh # define sqlite3_column_origin_name16 0
654b2688abSdanielk1977 #endif
664b2688abSdanielk1977
674b2688abSdanielk1977 #ifdef SQLITE_OMIT_COMPLETE
684b2688abSdanielk1977 # define sqlite3_complete 0
694b2688abSdanielk1977 # define sqlite3_complete16 0
704b2688abSdanielk1977 #endif
714b2688abSdanielk1977
72bb2b4418Sdan #ifdef SQLITE_OMIT_DECLTYPE
73bb2b4418Sdan # define sqlite3_column_decltype16 0
74bb2b4418Sdan # define sqlite3_column_decltype 0
75bb2b4418Sdan #endif
76bb2b4418Sdan
774b2688abSdanielk1977 #ifdef SQLITE_OMIT_PROGRESS_CALLBACK
784b2688abSdanielk1977 # define sqlite3_progress_handler 0
794b2688abSdanielk1977 #endif
804b2688abSdanielk1977
814b2688abSdanielk1977 #ifdef SQLITE_OMIT_VIRTUALTABLE
824b2688abSdanielk1977 # define sqlite3_create_module 0
83b7865fbcSdanielk1977 # define sqlite3_create_module_v2 0
844b2688abSdanielk1977 # define sqlite3_declare_vtab 0
850ea2517cSdan # define sqlite3_vtab_config 0
860ea2517cSdan # define sqlite3_vtab_on_conflict 0
87f6e015faSdan # define sqlite3_vtab_collation 0
884b2688abSdanielk1977 #endif
894b2688abSdanielk1977
90e31a1fb0Sdrh #ifdef SQLITE_OMIT_SHARED_CACHE
91e31a1fb0Sdrh # define sqlite3_enable_shared_cache 0
92e31a1fb0Sdrh #endif
93e31a1fb0Sdrh
94087ec072Sdrh #if defined(SQLITE_OMIT_TRACE) || defined(SQLITE_OMIT_DEPRECATED)
95e31a1fb0Sdrh # define sqlite3_profile 0
96e31a1fb0Sdrh # define sqlite3_trace 0
97e31a1fb0Sdrh #endif
98e31a1fb0Sdrh
99e31a1fb0Sdrh #ifdef SQLITE_OMIT_GET_TABLE
100e31a1fb0Sdrh # define sqlite3_free_table 0
101e31a1fb0Sdrh # define sqlite3_get_table 0
102e31a1fb0Sdrh #endif
103e31a1fb0Sdrh
104a15db353Sdanielk1977 #ifdef SQLITE_OMIT_INCRBLOB
105a15db353Sdanielk1977 #define sqlite3_bind_zeroblob 0
106a15db353Sdanielk1977 #define sqlite3_blob_bytes 0
107a15db353Sdanielk1977 #define sqlite3_blob_close 0
108a15db353Sdanielk1977 #define sqlite3_blob_open 0
109a15db353Sdanielk1977 #define sqlite3_blob_read 0
110a15db353Sdanielk1977 #define sqlite3_blob_write 0
1110ea2517cSdan #define sqlite3_blob_reopen 0
112a15db353Sdanielk1977 #endif
113a15db353Sdanielk1977
11444e95d4fSmistachkin #if defined(SQLITE_OMIT_TRACE)
11544e95d4fSmistachkin # define sqlite3_trace_v2 0
11644e95d4fSmistachkin #endif
11744e95d4fSmistachkin
11870df4fe6Sdrh /*
11970df4fe6Sdrh ** The following structure contains pointers to all SQLite API routines.
12070df4fe6Sdrh ** A pointer to this structure is passed into extensions when they are
12170df4fe6Sdrh ** loaded so that the extension can make calls back into the SQLite
12270df4fe6Sdrh ** library.
12370df4fe6Sdrh **
12470df4fe6Sdrh ** When adding new APIs, add them to the bottom of this structure
12570df4fe6Sdrh ** in order to preserve backwards compatibility.
12670df4fe6Sdrh **
12770df4fe6Sdrh ** Extensions that use newer APIs should first call the
12870df4fe6Sdrh ** sqlite3_libversion_number() to make sure that the API they
12970df4fe6Sdrh ** intend to use is supported by the library. Extensions should
13070df4fe6Sdrh ** also check to make sure that the pointer to the function is
13170df4fe6Sdrh ** not NULL before calling it.
13270df4fe6Sdrh */
133de24478eSdrh static const sqlite3_api_routines sqlite3Apis = {
1341e397f8fSdrh sqlite3_aggregate_context,
135eec556d3Sshane #ifndef SQLITE_OMIT_DEPRECATED
1361e397f8fSdrh sqlite3_aggregate_count,
137eec556d3Sshane #else
138eec556d3Sshane 0,
139eec556d3Sshane #endif
1401e397f8fSdrh sqlite3_bind_blob,
1411e397f8fSdrh sqlite3_bind_double,
1421e397f8fSdrh sqlite3_bind_int,
1431e397f8fSdrh sqlite3_bind_int64,
1441e397f8fSdrh sqlite3_bind_null,
1451e397f8fSdrh sqlite3_bind_parameter_count,
1461e397f8fSdrh sqlite3_bind_parameter_index,
1471e397f8fSdrh sqlite3_bind_parameter_name,
1481e397f8fSdrh sqlite3_bind_text,
1491e397f8fSdrh sqlite3_bind_text16,
150c1be6324Sdrh sqlite3_bind_value,
1511e397f8fSdrh sqlite3_busy_handler,
1521e397f8fSdrh sqlite3_busy_timeout,
1531e397f8fSdrh sqlite3_changes,
1541e397f8fSdrh sqlite3_close,
1551e397f8fSdrh sqlite3_collation_needed,
1561e397f8fSdrh sqlite3_collation_needed16,
1571e397f8fSdrh sqlite3_column_blob,
1581e397f8fSdrh sqlite3_column_bytes,
1591e397f8fSdrh sqlite3_column_bytes16,
1601e397f8fSdrh sqlite3_column_count,
1611e397f8fSdrh sqlite3_column_database_name,
1621e397f8fSdrh sqlite3_column_database_name16,
1631e397f8fSdrh sqlite3_column_decltype,
1641e397f8fSdrh sqlite3_column_decltype16,
1651e397f8fSdrh sqlite3_column_double,
1661e397f8fSdrh sqlite3_column_int,
1671e397f8fSdrh sqlite3_column_int64,
1681e397f8fSdrh sqlite3_column_name,
1691e397f8fSdrh sqlite3_column_name16,
1701e397f8fSdrh sqlite3_column_origin_name,
1711e397f8fSdrh sqlite3_column_origin_name16,
1721e397f8fSdrh sqlite3_column_table_name,
1731e397f8fSdrh sqlite3_column_table_name16,
1741e397f8fSdrh sqlite3_column_text,
1751e397f8fSdrh sqlite3_column_text16,
1761e397f8fSdrh sqlite3_column_type,
177d6e8dd00Sdanielk1977 sqlite3_column_value,
1781e397f8fSdrh sqlite3_commit_hook,
1791e397f8fSdrh sqlite3_complete,
1801e397f8fSdrh sqlite3_complete16,
1811e397f8fSdrh sqlite3_create_collation,
1821e397f8fSdrh sqlite3_create_collation16,
1831e397f8fSdrh sqlite3_create_function,
1841e397f8fSdrh sqlite3_create_function16,
185d6e8dd00Sdanielk1977 sqlite3_create_module,
1861e397f8fSdrh sqlite3_data_count,
1871e397f8fSdrh sqlite3_db_handle,
188d6e8dd00Sdanielk1977 sqlite3_declare_vtab,
1891e397f8fSdrh sqlite3_enable_shared_cache,
1901e397f8fSdrh sqlite3_errcode,
1911e397f8fSdrh sqlite3_errmsg,
1921e397f8fSdrh sqlite3_errmsg16,
1931e397f8fSdrh sqlite3_exec,
194eec556d3Sshane #ifndef SQLITE_OMIT_DEPRECATED
1951e397f8fSdrh sqlite3_expired,
196eec556d3Sshane #else
197eec556d3Sshane 0,
198eec556d3Sshane #endif
1991e397f8fSdrh sqlite3_finalize,
2001e397f8fSdrh sqlite3_free,
2011e397f8fSdrh sqlite3_free_table,
2021e397f8fSdrh sqlite3_get_autocommit,
2031e397f8fSdrh sqlite3_get_auxdata,
2041e397f8fSdrh sqlite3_get_table,
205e31a1fb0Sdrh 0, /* Was sqlite3_global_recover(), but that function is deprecated */
2061e397f8fSdrh sqlite3_interrupt,
2071e397f8fSdrh sqlite3_last_insert_rowid,
2081e397f8fSdrh sqlite3_libversion,
2091e397f8fSdrh sqlite3_libversion_number,
21028dd479cSdrh sqlite3_malloc,
2111e397f8fSdrh sqlite3_mprintf,
2121e397f8fSdrh sqlite3_open,
2131e397f8fSdrh sqlite3_open16,
2141e397f8fSdrh sqlite3_prepare,
2151e397f8fSdrh sqlite3_prepare16,
2161e397f8fSdrh sqlite3_profile,
2171e397f8fSdrh sqlite3_progress_handler,
21828dd479cSdrh sqlite3_realloc,
2191e397f8fSdrh sqlite3_reset,
2201e397f8fSdrh sqlite3_result_blob,
2211e397f8fSdrh sqlite3_result_double,
2221e397f8fSdrh sqlite3_result_error,
2231e397f8fSdrh sqlite3_result_error16,
2241e397f8fSdrh sqlite3_result_int,
2251e397f8fSdrh sqlite3_result_int64,
2261e397f8fSdrh sqlite3_result_null,
2271e397f8fSdrh sqlite3_result_text,
2281e397f8fSdrh sqlite3_result_text16,
2291e397f8fSdrh sqlite3_result_text16be,
2301e397f8fSdrh sqlite3_result_text16le,
2311e397f8fSdrh sqlite3_result_value,
2321e397f8fSdrh sqlite3_rollback_hook,
2331e397f8fSdrh sqlite3_set_authorizer,
2341e397f8fSdrh sqlite3_set_auxdata,
2351e397f8fSdrh sqlite3_snprintf,
2361e397f8fSdrh sqlite3_step,
2371e397f8fSdrh sqlite3_table_column_metadata,
238eec556d3Sshane #ifndef SQLITE_OMIT_DEPRECATED
2391e397f8fSdrh sqlite3_thread_cleanup,
240eec556d3Sshane #else
241eec556d3Sshane 0,
242eec556d3Sshane #endif
2431e397f8fSdrh sqlite3_total_changes,
2441e397f8fSdrh sqlite3_trace,
245eec556d3Sshane #ifndef SQLITE_OMIT_DEPRECATED
2461e397f8fSdrh sqlite3_transfer_bindings,
247eec556d3Sshane #else
248eec556d3Sshane 0,
249eec556d3Sshane #endif
2501e397f8fSdrh sqlite3_update_hook,
2511e397f8fSdrh sqlite3_user_data,
2521e397f8fSdrh sqlite3_value_blob,
2531e397f8fSdrh sqlite3_value_bytes,
2541e397f8fSdrh sqlite3_value_bytes16,
2551e397f8fSdrh sqlite3_value_double,
2561e397f8fSdrh sqlite3_value_int,
2571e397f8fSdrh sqlite3_value_int64,
2581e397f8fSdrh sqlite3_value_numeric_type,
2591e397f8fSdrh sqlite3_value_text,
2601e397f8fSdrh sqlite3_value_text16,
2611e397f8fSdrh sqlite3_value_text16be,
2621e397f8fSdrh sqlite3_value_text16le,
2631e397f8fSdrh sqlite3_value_type,
2641e397f8fSdrh sqlite3_vmprintf,
26570df4fe6Sdrh /*
26670df4fe6Sdrh ** The original API set ends here. All extensions can call any
26770df4fe6Sdrh ** of the APIs above provided that the pointer is not NULL. But
26870df4fe6Sdrh ** before calling APIs that follow, extension should check the
26970df4fe6Sdrh ** sqlite3_libversion_number() to make sure they are dealing with
27070df4fe6Sdrh ** a library that is new enough to support that API.
27170df4fe6Sdrh *************************************************************************
27270df4fe6Sdrh */
2737409310aSshess sqlite3_overload_function,
2746d54da05Sdrh
2756d54da05Sdrh /*
2766d54da05Sdrh ** Added after 3.3.13
2776d54da05Sdrh */
2786d54da05Sdrh sqlite3_prepare_v2,
2796d54da05Sdrh sqlite3_prepare16_v2,
280a92993caSdrh sqlite3_clear_bindings,
2816bf0ae74Sdrh
2826bf0ae74Sdrh /*
2836bf0ae74Sdrh ** Added for 3.4.1
2846bf0ae74Sdrh */
2856bf0ae74Sdrh sqlite3_create_module_v2,
2866bf0ae74Sdrh
287428e2826Sdrh /*
288428e2826Sdrh ** Added for 3.5.0
289428e2826Sdrh */
290428e2826Sdrh sqlite3_bind_zeroblob,
291428e2826Sdrh sqlite3_blob_bytes,
292428e2826Sdrh sqlite3_blob_close,
293428e2826Sdrh sqlite3_blob_open,
294428e2826Sdrh sqlite3_blob_read,
295428e2826Sdrh sqlite3_blob_write,
296428e2826Sdrh sqlite3_create_collation_v2,
297cc6bb3eaSdrh sqlite3_file_control,
298428e2826Sdrh sqlite3_memory_highwater,
299428e2826Sdrh sqlite3_memory_used,
30018472fa7Sdrh #ifdef SQLITE_MUTEX_OMIT
301ad3e78b6Sdrh 0,
302ad3e78b6Sdrh 0,
303ad3e78b6Sdrh 0,
304ad3e78b6Sdrh 0,
305ad3e78b6Sdrh 0,
306ad3e78b6Sdrh #else
30761f6dc60Sdrh sqlite3_mutex_alloc,
30861f6dc60Sdrh sqlite3_mutex_enter,
30961f6dc60Sdrh sqlite3_mutex_free,
31061f6dc60Sdrh sqlite3_mutex_leave,
31161f6dc60Sdrh sqlite3_mutex_try,
312ad3e78b6Sdrh #endif
313428e2826Sdrh sqlite3_open_v2,
314428e2826Sdrh sqlite3_release_memory,
315428e2826Sdrh sqlite3_result_error_nomem,
316428e2826Sdrh sqlite3_result_error_toobig,
317428e2826Sdrh sqlite3_sleep,
318428e2826Sdrh sqlite3_soft_heap_limit,
319428e2826Sdrh sqlite3_vfs_find,
320428e2826Sdrh sqlite3_vfs_register,
321428e2826Sdrh sqlite3_vfs_unregister,
3222fa1868fSdrh
3232fa1868fSdrh /*
3242fa1868fSdrh ** Added for 3.5.8
3252fa1868fSdrh */
326e5dd20a6Sdrh sqlite3_threadsafe,
327e5dd20a6Sdrh sqlite3_result_zeroblob,
328e5dd20a6Sdrh sqlite3_result_error_code,
329e5dd20a6Sdrh sqlite3_test_control,
3302fa1868fSdrh sqlite3_randomness,
331fa4a4b91Sdrh sqlite3_context_db_handle,
3328b6abedbSdrh
3338b6abedbSdrh /*
3348b6abedbSdrh ** Added for 3.6.0
3358b6abedbSdrh */
3368b6abedbSdrh sqlite3_extended_result_codes,
3378b6abedbSdrh sqlite3_limit,
3388b6abedbSdrh sqlite3_next_stmt,
3398b6abedbSdrh sqlite3_sql,
3408b6abedbSdrh sqlite3_status,
341fd7ebbf6Sdrh
342fd7ebbf6Sdrh /*
343fd7ebbf6Sdrh ** Added for 3.7.4
344fd7ebbf6Sdrh */
345fd7ebbf6Sdrh sqlite3_backup_finish,
346fd7ebbf6Sdrh sqlite3_backup_init,
347fd7ebbf6Sdrh sqlite3_backup_pagecount,
348fd7ebbf6Sdrh sqlite3_backup_remaining,
349fd7ebbf6Sdrh sqlite3_backup_step,
3504e49c77fSdrh #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
351fd7ebbf6Sdrh sqlite3_compileoption_get,
352fd7ebbf6Sdrh sqlite3_compileoption_used,
3534e49c77fSdrh #else
3544e49c77fSdrh 0,
3554e49c77fSdrh 0,
3564e49c77fSdrh #endif
357fd7ebbf6Sdrh sqlite3_create_function_v2,
358fd7ebbf6Sdrh sqlite3_db_config,
359fd7ebbf6Sdrh sqlite3_db_mutex,
360fd7ebbf6Sdrh sqlite3_db_status,
361fd7ebbf6Sdrh sqlite3_extended_errcode,
362fd7ebbf6Sdrh sqlite3_log,
363fd7ebbf6Sdrh sqlite3_soft_heap_limit64,
364fd7ebbf6Sdrh sqlite3_sourceid,
365fd7ebbf6Sdrh sqlite3_stmt_status,
366fd7ebbf6Sdrh sqlite3_strnicmp,
3674e49c77fSdrh #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
368fd7ebbf6Sdrh sqlite3_unlock_notify,
3694e49c77fSdrh #else
3704e49c77fSdrh 0,
3714e49c77fSdrh #endif
3724e49c77fSdrh #ifndef SQLITE_OMIT_WAL
373fd7ebbf6Sdrh sqlite3_wal_autocheckpoint,
374fd7ebbf6Sdrh sqlite3_wal_checkpoint,
375fd7ebbf6Sdrh sqlite3_wal_hook,
3764e49c77fSdrh #else
3774e49c77fSdrh 0,
3784e49c77fSdrh 0,
3794e49c77fSdrh 0,
3804e49c77fSdrh #endif
3810ea2517cSdan sqlite3_blob_reopen,
3820ea2517cSdan sqlite3_vtab_config,
3830ea2517cSdan sqlite3_vtab_on_conflict,
3841d59d036Sdrh sqlite3_close_v2,
3851d59d036Sdrh sqlite3_db_filename,
3861d59d036Sdrh sqlite3_db_readonly,
3871d59d036Sdrh sqlite3_db_release_memory,
3881d59d036Sdrh sqlite3_errstr,
3891d59d036Sdrh sqlite3_stmt_busy,
3901d59d036Sdrh sqlite3_stmt_readonly,
3911d59d036Sdrh sqlite3_stricmp,
3921d59d036Sdrh sqlite3_uri_boolean,
3931d59d036Sdrh sqlite3_uri_int64,
3941d59d036Sdrh sqlite3_uri_parameter,
3951d59d036Sdrh sqlite3_vsnprintf,
3960807cc2cSdrh sqlite3_wal_checkpoint_v2,
3970807cc2cSdrh /* Version 3.8.7 and later */
3980807cc2cSdrh sqlite3_auto_extension,
3990807cc2cSdrh sqlite3_bind_blob64,
400bbf483f8Sdrh sqlite3_bind_text64,
4010807cc2cSdrh sqlite3_cancel_auto_extension,
4020807cc2cSdrh sqlite3_load_extension,
4030807cc2cSdrh sqlite3_malloc64,
4040807cc2cSdrh sqlite3_msize,
4050807cc2cSdrh sqlite3_realloc64,
4060807cc2cSdrh sqlite3_reset_auto_extension,
4070807cc2cSdrh sqlite3_result_blob64,
408bbf483f8Sdrh sqlite3_result_text64,
409f5ed7ad6Sdrh sqlite3_strglob,
410f5ed7ad6Sdrh /* Version 3.8.11 and later */
411f5ed7ad6Sdrh (sqlite3_value*(*)(const sqlite3_value*))sqlite3_value_dup,
4126bacdc21Sdrh sqlite3_value_free,
41380c03022Sdan sqlite3_result_zeroblob64,
414cf94f179Sdrh sqlite3_bind_zeroblob64,
41558a8a923Sdrh /* Version 3.9.0 and later */
416cf94f179Sdrh sqlite3_value_subtype,
4177be53fe4Sdrh sqlite3_result_subtype,
4187be53fe4Sdrh /* Version 3.10.0 and later */
4197be53fe4Sdrh sqlite3_status64,
4207be53fe4Sdrh sqlite3_strlike,
4211b9f2141Sdrh sqlite3_db_cacheflush,
4221b9f2141Sdrh /* Version 3.12.0 and later */
42344e95d4fSmistachkin sqlite3_system_errno,
42444e95d4fSmistachkin /* Version 3.14.0 and later */
42544e95d4fSmistachkin sqlite3_trace_v2,
4260d8d9c9eSdrh sqlite3_expanded_sql,
4270d8d9c9eSdrh /* Version 3.18.0 and later */
428db3e0456Sdrh sqlite3_set_last_insert_rowid,
429db3e0456Sdrh /* Version 3.20.0 and later */
430db3e0456Sdrh sqlite3_prepare_v3,
4315587d86dSdrh sqlite3_prepare16_v3,
4325587d86dSdrh sqlite3_bind_pointer,
4335587d86dSdrh sqlite3_result_pointer,
43476506cd3Sdrh sqlite3_value_pointer,
43576506cd3Sdrh /* Version 3.22.0 and later */
43676506cd3Sdrh sqlite3_vtab_nochange,
4374a4532bbSdrh sqlite3_value_nochange,
438f0f9dbd3Sdrh sqlite3_vtab_collation,
439f0f9dbd3Sdrh /* Version 3.24.0 and later */
440f0f9dbd3Sdrh sqlite3_keyword_count,
441f0f9dbd3Sdrh sqlite3_keyword_name,
442f0f9dbd3Sdrh sqlite3_keyword_check,
443f0f9dbd3Sdrh sqlite3_str_new,
444f0f9dbd3Sdrh sqlite3_str_finish,
445f0f9dbd3Sdrh sqlite3_str_appendf,
446f0f9dbd3Sdrh sqlite3_str_vappendf,
447f0f9dbd3Sdrh sqlite3_str_append,
448f0f9dbd3Sdrh sqlite3_str_appendall,
449f0f9dbd3Sdrh sqlite3_str_appendchar,
450f0f9dbd3Sdrh sqlite3_str_reset,
451f0f9dbd3Sdrh sqlite3_str_errcode,
452f0f9dbd3Sdrh sqlite3_str_length,
453173e7823Sdrh sqlite3_str_value,
454173e7823Sdrh /* Version 3.25.0 and later */
4558bee11a4Smistachkin sqlite3_create_window_function,
4568bee11a4Smistachkin /* Version 3.26.0 and later */
4578bee11a4Smistachkin #ifdef SQLITE_ENABLE_NORMALIZE
45880ac9cb3Sdrh sqlite3_normalized_sql,
4598bee11a4Smistachkin #else
46080ac9cb3Sdrh 0,
4618bee11a4Smistachkin #endif
46280ac9cb3Sdrh /* Version 3.28.0 and later */
46380ac9cb3Sdrh sqlite3_stmt_isexplain,
46410c0e711Sdrh sqlite3_value_frombind,
46595da9d5dSdrh /* Version 3.30.0 and later */
466b008e4d7Sdan #ifndef SQLITE_OMIT_VIRTUALTABLE
46795da9d5dSdrh sqlite3_drop_modules,
468b008e4d7Sdan #else
469b008e4d7Sdan 0,
470b008e4d7Sdan #endif
471803f06bfSdrh /* Version 3.31.0 and later */
472803f06bfSdrh sqlite3_hard_heap_limit64,
4738080403eSdrh sqlite3_uri_key,
4748080403eSdrh sqlite3_filename_database,
4758080403eSdrh sqlite3_filename_journal,
4768080403eSdrh sqlite3_filename_wal,
4774defdddcSdrh /* Version 3.32.0 and later */
4784defdddcSdrh sqlite3_create_filename,
4794defdddcSdrh sqlite3_free_filename,
480480620c7Sdrh sqlite3_database_file_object,
4814989a530Sdrh /* Version 3.34.0 and later */
4824989a530Sdrh sqlite3_txn_state,
48310496f76Slarrybr /* Version 3.36.1 and later */
48410496f76Slarrybr sqlite3_changes64,
48510496f76Slarrybr sqlite3_total_changes64,
4861bbfc674Sdrh /* Version 3.37.0 and later */
4871bbfc674Sdrh sqlite3_autovacuum_pages,
488f62641e9Sdrh /* Version 3.38.0 and later */
489f62641e9Sdrh sqlite3_error_offset,
49007fd1bf3Sdan #ifndef SQLITE_OMIT_VIRTUALTABLE
49182801a5bSdrh sqlite3_vtab_rhs_value,
492ec778d27Sdrh sqlite3_vtab_distinct,
4930fe7e7d9Sdrh sqlite3_vtab_in,
4940fe7e7d9Sdrh sqlite3_vtab_in_first,
495b5bb769cSlarrybr sqlite3_vtab_in_next,
49607fd1bf3Sdan #else
49707fd1bf3Sdan 0,
49807fd1bf3Sdan 0,
49907fd1bf3Sdan 0,
50007fd1bf3Sdan 0,
50107fd1bf3Sdan 0,
50207fd1bf3Sdan #endif
503b5bb769cSlarrybr /* Version 3.39.0 and later */
504b5bb769cSlarrybr #ifndef SQLITE_OMIT_DESERIALIZE
505b5bb769cSlarrybr sqlite3_deserialize,
506ff16267dSdrh sqlite3_serialize,
507b5bb769cSlarrybr #else
508b5bb769cSlarrybr 0,
509ff16267dSdrh 0,
510b5bb769cSlarrybr #endif
511*0388f179Sdrh sqlite3_db_name,
512*0388f179Sdrh /* Version 3.40.0 and later */
513*0388f179Sdrh sqlite3_value_type
5141e397f8fSdrh };
5151e397f8fSdrh
516e238e314Sdrh /* True if x is the directory separator character
517e238e314Sdrh */
518e238e314Sdrh #if SQLITE_OS_WIN
519e238e314Sdrh # define DirSep(X) ((X)=='/'||(X)=='\\')
520e238e314Sdrh #else
521e238e314Sdrh # define DirSep(X) ((X)=='/')
522e238e314Sdrh #endif
523e238e314Sdrh
52470df4fe6Sdrh /*
5251e397f8fSdrh ** Attempt to load an SQLite extension library contained in the file
526428397c1Sdrh ** zFile. The entry point is zProc. zProc may be 0 in which case a
527428397c1Sdrh ** default entry point name (sqlite3_extension_init) is used. Use
528428397c1Sdrh ** of the default name is recommended.
5291e397f8fSdrh **
5301e397f8fSdrh ** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
5311e397f8fSdrh **
5321e397f8fSdrh ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
5331e397f8fSdrh ** error message text. The calling function should free this memory
534633e6d57Sdrh ** by calling sqlite3DbFree(db, ).
5351e397f8fSdrh */
sqlite3LoadExtension(sqlite3 * db,const char * zFile,const char * zProc,char ** pzErrMsg)536b21c8cd4Sdrh static int sqlite3LoadExtension(
5371e397f8fSdrh sqlite3 *db, /* Load the extension into this database connection */
5381e397f8fSdrh const char *zFile, /* Name of the shared library containing extension */
539428397c1Sdrh const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */
5401e397f8fSdrh char **pzErrMsg /* Put error message here if not 0 */
5411e397f8fSdrh ){
542b4b47411Sdanielk1977 sqlite3_vfs *pVfs = db->pVfs;
543761df87eSdrh void *handle;
54444e95d4fSmistachkin sqlite3_loadext_entry xInit;
5451e397f8fSdrh char *zErrmsg = 0;
546c288e442Sdrh const char *zEntry;
547c288e442Sdrh char *zAltEntry = 0;
548761df87eSdrh void **aHandle;
549cf145047Sdrh u64 nMsg = strlen(zFile);
550c288e442Sdrh int ii;
551c1502e2fSdrh int rc;
552c288e442Sdrh
553c288e442Sdrh /* Shared library endings to try if zFile cannot be loaded as written */
554c288e442Sdrh static const char *azEndings[] = {
555c288e442Sdrh #if SQLITE_OS_WIN
556c288e442Sdrh "dll"
557c288e442Sdrh #elif defined(__APPLE__)
558c288e442Sdrh "dylib"
559c288e442Sdrh #else
560c288e442Sdrh "so"
561c288e442Sdrh #endif
562c288e442Sdrh };
563c288e442Sdrh
5641e397f8fSdrh
5657aaa8786Sdrh if( pzErrMsg ) *pzErrMsg = 0;
566191dd061Sdrh
567191dd061Sdrh /* Ticket #1863. To avoid a creating security problems for older
568191dd061Sdrh ** applications that relink against newer versions of SQLite, the
569191dd061Sdrh ** ability to run load_extension is turned off by default. One
570191dd061Sdrh ** must call either sqlite3_enable_load_extension(db) or
571191dd061Sdrh ** sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, 0)
572191dd061Sdrh ** to turn on extension loading.
573191dd061Sdrh */
574191dd061Sdrh if( (db->flags & SQLITE_LoadExtension)==0 ){
575191dd061Sdrh if( pzErrMsg ){
576191dd061Sdrh *pzErrMsg = sqlite3_mprintf("not authorized");
577191dd061Sdrh }
578191dd061Sdrh return SQLITE_ERROR;
579191dd061Sdrh }
580191dd061Sdrh
581c288e442Sdrh zEntry = zProc ? zProc : "sqlite3_extension_init";
582191dd061Sdrh
583cf145047Sdrh /* tag-20210611-1. Some dlopen() implementations will segfault if given
584cf145047Sdrh ** an oversize filename. Most filesystems have a pathname limit of 4K,
585cf145047Sdrh ** so limit the extension filename length to about twice that.
586cf145047Sdrh ** https://sqlite.org/forum/forumpost/08a0d6d9bf */
587cf145047Sdrh if( nMsg>SQLITE_MAX_PATHLEN ) goto extension_not_found;
588cf145047Sdrh
589b4b47411Sdanielk1977 handle = sqlite3OsDlOpen(pVfs, zFile);
590c288e442Sdrh #if SQLITE_OS_UNIX || SQLITE_OS_WIN
591c288e442Sdrh for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
592c288e442Sdrh char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
593fad3039cSmistachkin if( zAltFile==0 ) return SQLITE_NOMEM_BKPT;
59460208c34Sdrh handle = sqlite3OsDlOpen(pVfs, zAltFile);
595c288e442Sdrh sqlite3_free(zAltFile);
596c288e442Sdrh }
597c288e442Sdrh #endif
598cf145047Sdrh if( handle==0 ) goto extension_not_found;
59944e95d4fSmistachkin xInit = (sqlite3_loadext_entry)sqlite3OsDlSym(pVfs, handle, zEntry);
600c288e442Sdrh
601c288e442Sdrh /* If no entry point was specified and the default legacy
602c288e442Sdrh ** entry point name "sqlite3_extension_init" was not found, then
603c288e442Sdrh ** construct an entry point name "sqlite3_X_init" where the X is
604c288e442Sdrh ** replaced by the lowercase value of every ASCII alphabetic
605c288e442Sdrh ** character in the filename after the last "/" upto the first ".",
606c288e442Sdrh ** and eliding the first three characters if they are "lib".
607c288e442Sdrh ** Examples:
608c288e442Sdrh **
609c288e442Sdrh ** /usr/local/lib/libExample5.4.3.so ==> sqlite3_example_init
610c288e442Sdrh ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
611c288e442Sdrh */
612c288e442Sdrh if( xInit==0 && zProc==0 ){
613c288e442Sdrh int iFile, iEntry, c;
614c288e442Sdrh int ncFile = sqlite3Strlen30(zFile);
615f3cdcdccSdrh zAltEntry = sqlite3_malloc64(ncFile+30);
616c288e442Sdrh if( zAltEntry==0 ){
617c288e442Sdrh sqlite3OsDlClose(pVfs, handle);
618fad3039cSmistachkin return SQLITE_NOMEM_BKPT;
619c288e442Sdrh }
620c288e442Sdrh memcpy(zAltEntry, "sqlite3_", 8);
621e238e314Sdrh for(iFile=ncFile-1; iFile>=0 && !DirSep(zFile[iFile]); iFile--){}
622c288e442Sdrh iFile++;
623c288e442Sdrh if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3;
624c288e442Sdrh for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){
625c288e442Sdrh if( sqlite3Isalpha(c) ){
626c288e442Sdrh zAltEntry[iEntry++] = (char)sqlite3UpperToLower[(unsigned)c];
627c288e442Sdrh }
628c288e442Sdrh }
629c288e442Sdrh memcpy(zAltEntry+iEntry, "_init", 6);
630c288e442Sdrh zEntry = zAltEntry;
63144e95d4fSmistachkin xInit = (sqlite3_loadext_entry)sqlite3OsDlSym(pVfs, handle, zEntry);
632c288e442Sdrh }
6331e397f8fSdrh if( xInit==0 ){
6341e397f8fSdrh if( pzErrMsg ){
635cf145047Sdrh nMsg += strlen(zEntry) + 300;
636f3cdcdccSdrh *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
63750d654daSdrh if( zErrmsg ){
638cf145047Sdrh assert( nMsg<0x7fffffff ); /* zErrmsg would be NULL if not so */
639cf145047Sdrh sqlite3_snprintf((int)nMsg, zErrmsg,
640c288e442Sdrh "no entry point [%s] in shared library [%s]", zEntry, zFile);
64150d654daSdrh sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
64250d654daSdrh }
64398cab2c0Sdanielk1977 }
644c288e442Sdrh sqlite3OsDlClose(pVfs, handle);
645c288e442Sdrh sqlite3_free(zAltEntry);
6461e397f8fSdrh return SQLITE_ERROR;
647c288e442Sdrh }
648c288e442Sdrh sqlite3_free(zAltEntry);
649c1502e2fSdrh rc = xInit(db, &zErrmsg, &sqlite3Apis);
650c1502e2fSdrh if( rc ){
651c1502e2fSdrh if( rc==SQLITE_OK_LOAD_PERMANENTLY ) return SQLITE_OK;
6521e397f8fSdrh if( pzErrMsg ){
6531e397f8fSdrh *pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg);
6541e397f8fSdrh }
6551e397f8fSdrh sqlite3_free(zErrmsg);
656b4b47411Sdanielk1977 sqlite3OsDlClose(pVfs, handle);
6571e397f8fSdrh return SQLITE_ERROR;
6581e397f8fSdrh }
65969e777f3Sdanielk1977
66069e777f3Sdanielk1977 /* Append the new shared library handle to the db->aExtension array. */
661701bb3b4Sdrh aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1));
66269e777f3Sdanielk1977 if( aHandle==0 ){
663fad3039cSmistachkin return SQLITE_NOMEM_BKPT;
66469e777f3Sdanielk1977 }
66569e777f3Sdanielk1977 if( db->nExtension>0 ){
666701bb3b4Sdrh memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension);
66769e777f3Sdanielk1977 }
668633e6d57Sdrh sqlite3DbFree(db, db->aExtension);
66969e777f3Sdanielk1977 db->aExtension = aHandle;
67069e777f3Sdanielk1977
671701bb3b4Sdrh db->aExtension[db->nExtension++] = handle;
6721e397f8fSdrh return SQLITE_OK;
673cf145047Sdrh
674cf145047Sdrh extension_not_found:
675cf145047Sdrh if( pzErrMsg ){
676cf145047Sdrh nMsg += 300;
677cf145047Sdrh *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
678cf145047Sdrh if( zErrmsg ){
679cf145047Sdrh assert( nMsg<0x7fffffff ); /* zErrmsg would be NULL if not so */
680cf145047Sdrh sqlite3_snprintf((int)nMsg, zErrmsg,
681cf145047Sdrh "unable to open shared library [%.*s]", SQLITE_MAX_PATHLEN, zFile);
682cf145047Sdrh sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
683cf145047Sdrh }
684cf145047Sdrh }
685cf145047Sdrh return SQLITE_ERROR;
6861e397f8fSdrh }
sqlite3_load_extension(sqlite3 * db,const char * zFile,const char * zProc,char ** pzErrMsg)687b21c8cd4Sdrh int sqlite3_load_extension(
688b21c8cd4Sdrh sqlite3 *db, /* Load the extension into this database connection */
689b21c8cd4Sdrh const char *zFile, /* Name of the shared library containing extension */
690b21c8cd4Sdrh const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */
691b21c8cd4Sdrh char **pzErrMsg /* Put error message here if not 0 */
692b21c8cd4Sdrh ){
693b21c8cd4Sdrh int rc;
694b21c8cd4Sdrh sqlite3_mutex_enter(db->mutex);
695b21c8cd4Sdrh rc = sqlite3LoadExtension(db, zFile, zProc, pzErrMsg);
6967aaa8786Sdrh rc = sqlite3ApiExit(db, rc);
697b21c8cd4Sdrh sqlite3_mutex_leave(db->mutex);
698b21c8cd4Sdrh return rc;
699b21c8cd4Sdrh }
700f1952c5dSdrh
701f1952c5dSdrh /*
702f1952c5dSdrh ** Call this routine when the database connection is closing in order
703f1952c5dSdrh ** to clean up loaded extensions
704f1952c5dSdrh */
sqlite3CloseExtensions(sqlite3 * db)705f1952c5dSdrh void sqlite3CloseExtensions(sqlite3 *db){
706f1952c5dSdrh int i;
707b21c8cd4Sdrh assert( sqlite3_mutex_held(db->mutex) );
708f1952c5dSdrh for(i=0; i<db->nExtension; i++){
709b4b47411Sdanielk1977 sqlite3OsDlClose(db->pVfs, db->aExtension[i]);
710f1952c5dSdrh }
711633e6d57Sdrh sqlite3DbFree(db, db->aExtension);
712f1952c5dSdrh }
713f1952c5dSdrh
714c2e87a3eSdrh /*
715c2e87a3eSdrh ** Enable or disable extension loading. Extension loading is disabled by
716c2e87a3eSdrh ** default so as not to open security holes in older applications.
717c2e87a3eSdrh */
sqlite3_enable_load_extension(sqlite3 * db,int onoff)718c2e87a3eSdrh int sqlite3_enable_load_extension(sqlite3 *db, int onoff){
719b21c8cd4Sdrh sqlite3_mutex_enter(db->mutex);
720c2e87a3eSdrh if( onoff ){
721191dd061Sdrh db->flags |= SQLITE_LoadExtension|SQLITE_LoadExtFunc;
722c2e87a3eSdrh }else{
723d5b44d60Sdrh db->flags &= ~(u64)(SQLITE_LoadExtension|SQLITE_LoadExtFunc);
724c2e87a3eSdrh }
725b21c8cd4Sdrh sqlite3_mutex_leave(db->mutex);
726c2e87a3eSdrh return SQLITE_OK;
727c2e87a3eSdrh }
728c2e87a3eSdrh
72998365be0Sdrh #endif /* !defined(SQLITE_OMIT_LOAD_EXTENSION) */
730984bfaa4Sdrh
7311409be69Sdrh /*
732605264d2Sdrh ** The following object holds the list of automatically loaded
733605264d2Sdrh ** extensions.
7341409be69Sdrh **
735ccb2113aSdrh ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MAIN
736605264d2Sdrh ** mutex must be held while accessing this list.
7371409be69Sdrh */
7381875f7a3Sdrh typedef struct sqlite3AutoExtList sqlite3AutoExtList;
7391875f7a3Sdrh static SQLITE_WSD struct sqlite3AutoExtList {
740f3cdcdccSdrh u32 nExt; /* Number of entries in aExt[] */
7411875f7a3Sdrh void (**aExt)(void); /* Pointers to the extension init functions */
74278f82d1eSdrh } sqlite3Autoext = { 0, 0 };
74378f82d1eSdrh
74478f82d1eSdrh /* The "wsdAutoext" macro will resolve to the autoextension
74578f82d1eSdrh ** state vector. If writable static data is unsupported on the target,
74678f82d1eSdrh ** we have to locate the state vector at run-time. In the more common
74778f82d1eSdrh ** case where writable static data is supported, wsdStat can refer directly
74878f82d1eSdrh ** to the "sqlite3Autoext" state vector declared above.
74978f82d1eSdrh */
75078f82d1eSdrh #ifdef SQLITE_OMIT_WSD
75178f82d1eSdrh # define wsdAutoextInit \
7521875f7a3Sdrh sqlite3AutoExtList *x = &GLOBAL(sqlite3AutoExtList,sqlite3Autoext)
75378f82d1eSdrh # define wsdAutoext x[0]
75478f82d1eSdrh #else
75578f82d1eSdrh # define wsdAutoextInit
75678f82d1eSdrh # define wsdAutoext sqlite3Autoext
75778f82d1eSdrh #endif
7581409be69Sdrh
7591409be69Sdrh
7601409be69Sdrh /*
7611409be69Sdrh ** Register a statically linked extension that is automatically
7621409be69Sdrh ** loaded by every new database connection.
7631409be69Sdrh */
sqlite3_auto_extension(void (* xInit)(void))76444e95d4fSmistachkin int sqlite3_auto_extension(
76532c83c8bSdrh void (*xInit)(void)
76644e95d4fSmistachkin ){
76700f0faf3Sdanielk1977 int rc = SQLITE_OK;
76840257ffdSdrh #ifndef SQLITE_OMIT_AUTOINIT
76900f0faf3Sdanielk1977 rc = sqlite3_initialize();
77040257ffdSdrh if( rc ){
77140257ffdSdrh return rc;
77240257ffdSdrh }else
77340257ffdSdrh #endif
77440257ffdSdrh {
7756a412b8bSdrh u32 i;
77618472fa7Sdrh #if SQLITE_THREADSAFE
777ccb2113aSdrh sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
778e265b084Sdrh #endif
77978f82d1eSdrh wsdAutoextInit;
780b4b47411Sdanielk1977 sqlite3_mutex_enter(mutex);
78178f82d1eSdrh for(i=0; i<wsdAutoext.nExt; i++){
782b0df540dSdrh if( wsdAutoext.aExt[i]==xInit ) break;
7831409be69Sdrh }
78478f82d1eSdrh if( i==wsdAutoext.nExt ){
785f3cdcdccSdrh u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
7861875f7a3Sdrh void (**aNew)(void);
787f3cdcdccSdrh aNew = sqlite3_realloc64(wsdAutoext.aExt, nByte);
788605264d2Sdrh if( aNew==0 ){
789fad3039cSmistachkin rc = SQLITE_NOMEM_BKPT;
7901409be69Sdrh }else{
79178f82d1eSdrh wsdAutoext.aExt = aNew;
792b0df540dSdrh wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
79378f82d1eSdrh wsdAutoext.nExt++;
7941409be69Sdrh }
7951409be69Sdrh }
796b4b47411Sdanielk1977 sqlite3_mutex_leave(mutex);
7974ac285a1Sdrh assert( (rc&0xff)==rc );
7981409be69Sdrh return rc;
7991409be69Sdrh }
80040257ffdSdrh }
8011409be69Sdrh
8021409be69Sdrh /*
803425e27dbSdrh ** Cancel a prior call to sqlite3_auto_extension. Remove xInit from the
804425e27dbSdrh ** set of routines that is invoked for each new database connection, if it
805425e27dbSdrh ** is currently on the list. If xInit is not on the list, then this
806425e27dbSdrh ** routine is a no-op.
807425e27dbSdrh **
808425e27dbSdrh ** Return 1 if xInit was found on the list and removed. Return 0 if xInit
809425e27dbSdrh ** was not on the list.
810425e27dbSdrh */
sqlite3_cancel_auto_extension(void (* xInit)(void))81144e95d4fSmistachkin int sqlite3_cancel_auto_extension(
81232c83c8bSdrh void (*xInit)(void)
81344e95d4fSmistachkin ){
814425e27dbSdrh #if SQLITE_THREADSAFE
815ccb2113aSdrh sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
816425e27dbSdrh #endif
817425e27dbSdrh int i;
818425e27dbSdrh int n = 0;
819425e27dbSdrh wsdAutoextInit;
820425e27dbSdrh sqlite3_mutex_enter(mutex);
8216a412b8bSdrh for(i=(int)wsdAutoext.nExt-1; i>=0; i--){
822b0df540dSdrh if( wsdAutoext.aExt[i]==xInit ){
823425e27dbSdrh wsdAutoext.nExt--;
824425e27dbSdrh wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
825425e27dbSdrh n++;
826425e27dbSdrh break;
827425e27dbSdrh }
828425e27dbSdrh }
829425e27dbSdrh sqlite3_mutex_leave(mutex);
830425e27dbSdrh return n;
831425e27dbSdrh }
832425e27dbSdrh
833425e27dbSdrh /*
8341409be69Sdrh ** Reset the automatic extension loading mechanism.
8351409be69Sdrh */
sqlite3_reset_auto_extension(void)8361409be69Sdrh void sqlite3_reset_auto_extension(void){
83740257ffdSdrh #ifndef SQLITE_OMIT_AUTOINIT
83840257ffdSdrh if( sqlite3_initialize()==SQLITE_OK )
83940257ffdSdrh #endif
84040257ffdSdrh {
84118472fa7Sdrh #if SQLITE_THREADSAFE
842ccb2113aSdrh sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
843e265b084Sdrh #endif
84478f82d1eSdrh wsdAutoextInit;
845b4b47411Sdanielk1977 sqlite3_mutex_enter(mutex);
84678f82d1eSdrh sqlite3_free(wsdAutoext.aExt);
84778f82d1eSdrh wsdAutoext.aExt = 0;
84878f82d1eSdrh wsdAutoext.nExt = 0;
849b4b47411Sdanielk1977 sqlite3_mutex_leave(mutex);
8501409be69Sdrh }
85140257ffdSdrh }
8521409be69Sdrh
8531409be69Sdrh /*
8541409be69Sdrh ** Load all automatic extensions.
8557aaa8786Sdrh **
8567aaa8786Sdrh ** If anything goes wrong, set an error in the database connection.
8571409be69Sdrh */
sqlite3AutoLoadExtensions(sqlite3 * db)8587aaa8786Sdrh void sqlite3AutoLoadExtensions(sqlite3 *db){
8596a412b8bSdrh u32 i;
8601409be69Sdrh int go = 1;
861e5077c12Sdrh int rc;
86244e95d4fSmistachkin sqlite3_loadext_entry xInit;
8631409be69Sdrh
86478f82d1eSdrh wsdAutoextInit;
86578f82d1eSdrh if( wsdAutoext.nExt==0 ){
8661409be69Sdrh /* Common case: early out without every having to acquire a mutex */
8677aaa8786Sdrh return;
8681409be69Sdrh }
8691409be69Sdrh for(i=0; go; i++){
8707aaa8786Sdrh char *zErrmsg;
87118472fa7Sdrh #if SQLITE_THREADSAFE
872ccb2113aSdrh sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
873e265b084Sdrh #endif
87498365be0Sdrh #ifdef SQLITE_OMIT_LOAD_EXTENSION
87598365be0Sdrh const sqlite3_api_routines *pThunk = 0;
87698365be0Sdrh #else
87798365be0Sdrh const sqlite3_api_routines *pThunk = &sqlite3Apis;
87898365be0Sdrh #endif
879b4b47411Sdanielk1977 sqlite3_mutex_enter(mutex);
88078f82d1eSdrh if( i>=wsdAutoext.nExt ){
8811409be69Sdrh xInit = 0;
8821409be69Sdrh go = 0;
8831409be69Sdrh }else{
88444e95d4fSmistachkin xInit = (sqlite3_loadext_entry)wsdAutoext.aExt[i];
8851409be69Sdrh }
886b4b47411Sdanielk1977 sqlite3_mutex_leave(mutex);
8877aaa8786Sdrh zErrmsg = 0;
88898365be0Sdrh if( xInit && (rc = xInit(db, &zErrmsg, pThunk))!=0 ){
88913f40da3Sdrh sqlite3ErrorWithMsg(db, rc,
8901409be69Sdrh "automatic extension loading failed: %s", zErrmsg);
8911409be69Sdrh go = 0;
8927aaa8786Sdrh }
8934a50aac5Sdrh sqlite3_free(zErrmsg);
8941409be69Sdrh }
8951409be69Sdrh }
896