drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | ** 2006 June 7 |
| 3 | ** |
| 4 | ** The author disclaims copyright to this source code. In place of |
| 5 | ** a legal notice, here is a blessing: |
| 6 | ** |
| 7 | ** May you do good and not evil. |
| 8 | ** May you find forgiveness for yourself and forgive others. |
| 9 | ** May you share freely, never taking more than you give. |
| 10 | ** |
| 11 | ************************************************************************* |
| 12 | ** This file contains code used to dynamically load extensions into |
| 13 | ** the SQLite library. |
| 14 | */ |
| 15 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 16 | |
| 17 | #define SQLITE_CORE 1 /* Disable the API redefinition in sqlite3ext.h */ |
| 18 | #include "sqlite3ext.h" |
drh | f1952c5 | 2006-06-08 15:48:00 +0000 | [diff] [blame] | 19 | #include "sqliteInt.h" |
drh | 1409be6 | 2006-08-23 20:07:20 +0000 | [diff] [blame] | 20 | #include "os.h" |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 21 | #include <string.h> |
| 22 | #include <ctype.h> |
| 23 | |
drh | 70df4fe | 2006-06-13 15:12:21 +0000 | [diff] [blame] | 24 | /* |
| 25 | ** Some API routines are omitted when various features are |
| 26 | ** excluded from a build of SQLite. Substitute a NULL pointer |
| 27 | ** for any missing APIs. |
| 28 | */ |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 29 | #ifndef SQLITE_ENABLE_COLUMN_METADATA |
| 30 | # define sqlite3_column_database_name 0 |
| 31 | # define sqlite3_column_database_name16 0 |
| 32 | # define sqlite3_column_table_name 0 |
| 33 | # define sqlite3_column_table_name16 0 |
| 34 | # define sqlite3_column_origin_name 0 |
| 35 | # define sqlite3_column_origin_name16 0 |
| 36 | # define sqlite3_table_column_metadata 0 |
| 37 | #endif |
| 38 | |
danielk1977 | 4b2688a | 2006-06-20 11:01:07 +0000 | [diff] [blame] | 39 | #ifdef SQLITE_OMIT_AUTHORIZATION |
drh | af30469 | 2007-04-23 23:56:31 +0000 | [diff] [blame] | 40 | # define sqlite3_set_authorizer 0 |
danielk1977 | 4b2688a | 2006-06-20 11:01:07 +0000 | [diff] [blame] | 41 | #endif |
| 42 | |
| 43 | #ifdef SQLITE_OMIT_UTF16 |
drh | af30469 | 2007-04-23 23:56:31 +0000 | [diff] [blame] | 44 | # define sqlite3_bind_text16 0 |
| 45 | # define sqlite3_collation_needed16 0 |
| 46 | # define sqlite3_column_decltype16 0 |
| 47 | # define sqlite3_column_name16 0 |
| 48 | # define sqlite3_column_text16 0 |
| 49 | # define sqlite3_complete16 0 |
| 50 | # define sqlite3_create_collation16 0 |
| 51 | # define sqlite3_create_function16 0 |
| 52 | # define sqlite3_errmsg16 0 |
| 53 | # define sqlite3_open16 0 |
| 54 | # define sqlite3_prepare16 0 |
| 55 | # define sqlite3_prepare16_v2 0 |
| 56 | # define sqlite3_result_error16 0 |
| 57 | # define sqlite3_result_text16 0 |
| 58 | # define sqlite3_result_text16be 0 |
| 59 | # define sqlite3_result_text16le 0 |
| 60 | # define sqlite3_value_text16 0 |
| 61 | # define sqlite3_value_text16be 0 |
| 62 | # define sqlite3_value_text16le 0 |
| 63 | # define sqlite3_column_database_name16 0 |
| 64 | # define sqlite3_column_table_name16 0 |
| 65 | # define sqlite3_column_origin_name16 0 |
danielk1977 | 4b2688a | 2006-06-20 11:01:07 +0000 | [diff] [blame] | 66 | #endif |
| 67 | |
| 68 | #ifdef SQLITE_OMIT_COMPLETE |
| 69 | # define sqlite3_complete 0 |
| 70 | # define sqlite3_complete16 0 |
| 71 | #endif |
| 72 | |
| 73 | #ifdef SQLITE_OMIT_PROGRESS_CALLBACK |
| 74 | # define sqlite3_progress_handler 0 |
| 75 | #endif |
| 76 | |
| 77 | #ifdef SQLITE_OMIT_VIRTUALTABLE |
| 78 | # define sqlite3_create_module 0 |
danielk1977 | b7865fb | 2007-06-27 11:10:03 +0000 | [diff] [blame^] | 79 | # define sqlite3_create_module_v2 0 |
danielk1977 | 4b2688a | 2006-06-20 11:01:07 +0000 | [diff] [blame] | 80 | # define sqlite3_declare_vtab 0 |
| 81 | #endif |
| 82 | |
drh | e31a1fb | 2007-01-26 13:08:24 +0000 | [diff] [blame] | 83 | #ifdef SQLITE_OMIT_SHARED_CACHE |
| 84 | # define sqlite3_enable_shared_cache 0 |
| 85 | #endif |
| 86 | |
| 87 | #ifdef SQLITE_OMIT_TRACE |
| 88 | # define sqlite3_profile 0 |
| 89 | # define sqlite3_trace 0 |
| 90 | #endif |
| 91 | |
| 92 | #ifdef SQLITE_OMIT_GET_TABLE |
| 93 | # define sqlite3_free_table 0 |
| 94 | # define sqlite3_get_table 0 |
| 95 | #endif |
| 96 | |
drh | 70df4fe | 2006-06-13 15:12:21 +0000 | [diff] [blame] | 97 | /* |
| 98 | ** The following structure contains pointers to all SQLite API routines. |
| 99 | ** A pointer to this structure is passed into extensions when they are |
| 100 | ** loaded so that the extension can make calls back into the SQLite |
| 101 | ** library. |
| 102 | ** |
| 103 | ** When adding new APIs, add them to the bottom of this structure |
| 104 | ** in order to preserve backwards compatibility. |
| 105 | ** |
| 106 | ** Extensions that use newer APIs should first call the |
| 107 | ** sqlite3_libversion_number() to make sure that the API they |
| 108 | ** intend to use is supported by the library. Extensions should |
| 109 | ** also check to make sure that the pointer to the function is |
| 110 | ** not NULL before calling it. |
| 111 | */ |
drh | 1409be6 | 2006-08-23 20:07:20 +0000 | [diff] [blame] | 112 | const sqlite3_api_routines sqlite3_apis = { |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 113 | sqlite3_aggregate_context, |
| 114 | sqlite3_aggregate_count, |
| 115 | sqlite3_bind_blob, |
| 116 | sqlite3_bind_double, |
| 117 | sqlite3_bind_int, |
| 118 | sqlite3_bind_int64, |
| 119 | sqlite3_bind_null, |
| 120 | sqlite3_bind_parameter_count, |
| 121 | sqlite3_bind_parameter_index, |
| 122 | sqlite3_bind_parameter_name, |
| 123 | sqlite3_bind_text, |
| 124 | sqlite3_bind_text16, |
drh | c1be632 | 2006-06-27 00:14:27 +0000 | [diff] [blame] | 125 | sqlite3_bind_value, |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 126 | sqlite3_busy_handler, |
| 127 | sqlite3_busy_timeout, |
| 128 | sqlite3_changes, |
| 129 | sqlite3_close, |
| 130 | sqlite3_collation_needed, |
| 131 | sqlite3_collation_needed16, |
| 132 | sqlite3_column_blob, |
| 133 | sqlite3_column_bytes, |
| 134 | sqlite3_column_bytes16, |
| 135 | sqlite3_column_count, |
| 136 | sqlite3_column_database_name, |
| 137 | sqlite3_column_database_name16, |
| 138 | sqlite3_column_decltype, |
| 139 | sqlite3_column_decltype16, |
| 140 | sqlite3_column_double, |
| 141 | sqlite3_column_int, |
| 142 | sqlite3_column_int64, |
| 143 | sqlite3_column_name, |
| 144 | sqlite3_column_name16, |
| 145 | sqlite3_column_origin_name, |
| 146 | sqlite3_column_origin_name16, |
| 147 | sqlite3_column_table_name, |
| 148 | sqlite3_column_table_name16, |
| 149 | sqlite3_column_text, |
| 150 | sqlite3_column_text16, |
| 151 | sqlite3_column_type, |
danielk1977 | d6e8dd0 | 2006-06-15 15:38:41 +0000 | [diff] [blame] | 152 | sqlite3_column_value, |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 153 | sqlite3_commit_hook, |
| 154 | sqlite3_complete, |
| 155 | sqlite3_complete16, |
| 156 | sqlite3_create_collation, |
| 157 | sqlite3_create_collation16, |
| 158 | sqlite3_create_function, |
| 159 | sqlite3_create_function16, |
danielk1977 | d6e8dd0 | 2006-06-15 15:38:41 +0000 | [diff] [blame] | 160 | sqlite3_create_module, |
danielk1977 | 832a58a | 2007-06-22 15:21:15 +0000 | [diff] [blame] | 161 | sqlite3_create_module_v2, |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 162 | sqlite3_data_count, |
| 163 | sqlite3_db_handle, |
danielk1977 | d6e8dd0 | 2006-06-15 15:38:41 +0000 | [diff] [blame] | 164 | sqlite3_declare_vtab, |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 165 | sqlite3_enable_shared_cache, |
| 166 | sqlite3_errcode, |
| 167 | sqlite3_errmsg, |
| 168 | sqlite3_errmsg16, |
| 169 | sqlite3_exec, |
| 170 | sqlite3_expired, |
| 171 | sqlite3_finalize, |
| 172 | sqlite3_free, |
| 173 | sqlite3_free_table, |
| 174 | sqlite3_get_autocommit, |
| 175 | sqlite3_get_auxdata, |
| 176 | sqlite3_get_table, |
drh | e31a1fb | 2007-01-26 13:08:24 +0000 | [diff] [blame] | 177 | 0, /* Was sqlite3_global_recover(), but that function is deprecated */ |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 178 | sqlite3_interrupt, |
| 179 | sqlite3_last_insert_rowid, |
| 180 | sqlite3_libversion, |
| 181 | sqlite3_libversion_number, |
drh | 28dd479 | 2006-06-26 21:35:44 +0000 | [diff] [blame] | 182 | sqlite3_malloc, |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 183 | sqlite3_mprintf, |
| 184 | sqlite3_open, |
| 185 | sqlite3_open16, |
| 186 | sqlite3_prepare, |
| 187 | sqlite3_prepare16, |
| 188 | sqlite3_profile, |
| 189 | sqlite3_progress_handler, |
drh | 28dd479 | 2006-06-26 21:35:44 +0000 | [diff] [blame] | 190 | sqlite3_realloc, |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 191 | sqlite3_reset, |
| 192 | sqlite3_result_blob, |
| 193 | sqlite3_result_double, |
| 194 | sqlite3_result_error, |
| 195 | sqlite3_result_error16, |
| 196 | sqlite3_result_int, |
| 197 | sqlite3_result_int64, |
| 198 | sqlite3_result_null, |
| 199 | sqlite3_result_text, |
| 200 | sqlite3_result_text16, |
| 201 | sqlite3_result_text16be, |
| 202 | sqlite3_result_text16le, |
| 203 | sqlite3_result_value, |
| 204 | sqlite3_rollback_hook, |
| 205 | sqlite3_set_authorizer, |
| 206 | sqlite3_set_auxdata, |
| 207 | sqlite3_snprintf, |
| 208 | sqlite3_step, |
| 209 | sqlite3_table_column_metadata, |
| 210 | sqlite3_thread_cleanup, |
| 211 | sqlite3_total_changes, |
| 212 | sqlite3_trace, |
| 213 | sqlite3_transfer_bindings, |
| 214 | sqlite3_update_hook, |
| 215 | sqlite3_user_data, |
| 216 | sqlite3_value_blob, |
| 217 | sqlite3_value_bytes, |
| 218 | sqlite3_value_bytes16, |
| 219 | sqlite3_value_double, |
| 220 | sqlite3_value_int, |
| 221 | sqlite3_value_int64, |
| 222 | sqlite3_value_numeric_type, |
| 223 | sqlite3_value_text, |
| 224 | sqlite3_value_text16, |
| 225 | sqlite3_value_text16be, |
| 226 | sqlite3_value_text16le, |
| 227 | sqlite3_value_type, |
| 228 | sqlite3_vmprintf, |
drh | 70df4fe | 2006-06-13 15:12:21 +0000 | [diff] [blame] | 229 | /* |
| 230 | ** The original API set ends here. All extensions can call any |
| 231 | ** of the APIs above provided that the pointer is not NULL. But |
| 232 | ** before calling APIs that follow, extension should check the |
| 233 | ** sqlite3_libversion_number() to make sure they are dealing with |
| 234 | ** a library that is new enough to support that API. |
| 235 | ************************************************************************* |
| 236 | */ |
shess | 7409310 | 2006-09-22 23:38:21 +0000 | [diff] [blame] | 237 | sqlite3_overload_function, |
drh | 6d54da0 | 2007-03-25 19:08:46 +0000 | [diff] [blame] | 238 | |
| 239 | /* |
| 240 | ** Added after 3.3.13 |
| 241 | */ |
| 242 | sqlite3_prepare_v2, |
| 243 | sqlite3_prepare16_v2, |
drh | a92993c | 2007-03-29 18:46:00 +0000 | [diff] [blame] | 244 | sqlite3_clear_bindings, |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 245 | }; |
| 246 | |
drh | 70df4fe | 2006-06-13 15:12:21 +0000 | [diff] [blame] | 247 | /* |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 248 | ** Attempt to load an SQLite extension library contained in the file |
drh | 428397c | 2006-06-17 13:21:32 +0000 | [diff] [blame] | 249 | ** zFile. The entry point is zProc. zProc may be 0 in which case a |
| 250 | ** default entry point name (sqlite3_extension_init) is used. Use |
| 251 | ** of the default name is recommended. |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 252 | ** |
| 253 | ** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong. |
| 254 | ** |
| 255 | ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with |
| 256 | ** error message text. The calling function should free this memory |
| 257 | ** by calling sqlite3_free(). |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 258 | */ |
| 259 | int sqlite3_load_extension( |
| 260 | sqlite3 *db, /* Load the extension into this database connection */ |
| 261 | const char *zFile, /* Name of the shared library containing extension */ |
drh | 428397c | 2006-06-17 13:21:32 +0000 | [diff] [blame] | 262 | const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */ |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 263 | char **pzErrMsg /* Put error message here if not 0 */ |
| 264 | ){ |
drh | 761df87 | 2006-12-21 01:29:22 +0000 | [diff] [blame] | 265 | void *handle; |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 266 | int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); |
| 267 | char *zErrmsg = 0; |
drh | 761df87 | 2006-12-21 01:29:22 +0000 | [diff] [blame] | 268 | void **aHandle; |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 269 | |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 270 | /* Ticket #1863. To avoid a creating security problems for older |
| 271 | ** applications that relink against newer versions of SQLite, the |
| 272 | ** ability to run load_extension is turned off by default. One |
| 273 | ** must call sqlite3_enable_load_extension() to turn on extension |
| 274 | ** loading. Otherwise you get the following error. |
| 275 | */ |
| 276 | if( (db->flags & SQLITE_LoadExtension)==0 ){ |
| 277 | if( pzErrMsg ){ |
| 278 | *pzErrMsg = sqlite3_mprintf("not authorized"); |
| 279 | } |
| 280 | return SQLITE_ERROR; |
| 281 | } |
| 282 | |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 283 | if( zProc==0 ){ |
drh | 428397c | 2006-06-17 13:21:32 +0000 | [diff] [blame] | 284 | zProc = "sqlite3_extension_init"; |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 285 | } |
| 286 | |
drh | 761df87 | 2006-12-21 01:29:22 +0000 | [diff] [blame] | 287 | handle = sqlite3OsDlopen(zFile); |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 288 | if( handle==0 ){ |
| 289 | if( pzErrMsg ){ |
| 290 | *pzErrMsg = sqlite3_mprintf("unable to open shared library [%s]", zFile); |
| 291 | } |
| 292 | return SQLITE_ERROR; |
| 293 | } |
| 294 | xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*)) |
drh | 761df87 | 2006-12-21 01:29:22 +0000 | [diff] [blame] | 295 | sqlite3OsDlsym(handle, zProc); |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 296 | if( xInit==0 ){ |
| 297 | if( pzErrMsg ){ |
| 298 | *pzErrMsg = sqlite3_mprintf("no entry point [%s] in shared library [%s]", |
| 299 | zProc, zFile); |
| 300 | } |
drh | 761df87 | 2006-12-21 01:29:22 +0000 | [diff] [blame] | 301 | sqlite3OsDlclose(handle); |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 302 | return SQLITE_ERROR; |
drh | 1409be6 | 2006-08-23 20:07:20 +0000 | [diff] [blame] | 303 | }else if( xInit(db, &zErrmsg, &sqlite3_apis) ){ |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 304 | if( pzErrMsg ){ |
| 305 | *pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg); |
| 306 | } |
| 307 | sqlite3_free(zErrmsg); |
drh | 761df87 | 2006-12-21 01:29:22 +0000 | [diff] [blame] | 308 | sqlite3OsDlclose(handle); |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 309 | return SQLITE_ERROR; |
| 310 | } |
danielk1977 | 69e777f | 2006-06-14 10:38:02 +0000 | [diff] [blame] | 311 | |
| 312 | /* Append the new shared library handle to the db->aExtension array. */ |
| 313 | db->nExtension++; |
| 314 | aHandle = sqliteMalloc(sizeof(handle)*db->nExtension); |
| 315 | if( aHandle==0 ){ |
| 316 | return SQLITE_NOMEM; |
| 317 | } |
| 318 | if( db->nExtension>0 ){ |
| 319 | memcpy(aHandle, db->aExtension, sizeof(handle)*(db->nExtension-1)); |
| 320 | } |
| 321 | sqliteFree(db->aExtension); |
| 322 | db->aExtension = aHandle; |
| 323 | |
drh | 761df87 | 2006-12-21 01:29:22 +0000 | [diff] [blame] | 324 | db->aExtension[db->nExtension-1] = handle; |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 325 | return SQLITE_OK; |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 326 | } |
drh | f1952c5 | 2006-06-08 15:48:00 +0000 | [diff] [blame] | 327 | |
| 328 | /* |
| 329 | ** Call this routine when the database connection is closing in order |
| 330 | ** to clean up loaded extensions |
| 331 | */ |
| 332 | void sqlite3CloseExtensions(sqlite3 *db){ |
| 333 | int i; |
| 334 | for(i=0; i<db->nExtension; i++){ |
drh | 761df87 | 2006-12-21 01:29:22 +0000 | [diff] [blame] | 335 | sqlite3OsDlclose(db->aExtension[i]); |
drh | f1952c5 | 2006-06-08 15:48:00 +0000 | [diff] [blame] | 336 | } |
| 337 | sqliteFree(db->aExtension); |
| 338 | } |
| 339 | |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 340 | /* |
| 341 | ** Enable or disable extension loading. Extension loading is disabled by |
| 342 | ** default so as not to open security holes in older applications. |
| 343 | */ |
| 344 | int sqlite3_enable_load_extension(sqlite3 *db, int onoff){ |
| 345 | if( onoff ){ |
| 346 | db->flags |= SQLITE_LoadExtension; |
| 347 | }else{ |
| 348 | db->flags &= ~SQLITE_LoadExtension; |
| 349 | } |
| 350 | return SQLITE_OK; |
| 351 | } |
| 352 | |
drh | 1409be6 | 2006-08-23 20:07:20 +0000 | [diff] [blame] | 353 | /* |
| 354 | ** A list of automatically loaded extensions. |
| 355 | ** |
| 356 | ** This list is shared across threads, so be sure to hold the |
| 357 | ** mutex while accessing or changing it. |
| 358 | */ |
| 359 | static int nAutoExtension = 0; |
| 360 | static void **aAutoExtension = 0; |
| 361 | |
| 362 | |
| 363 | /* |
| 364 | ** Register a statically linked extension that is automatically |
| 365 | ** loaded by every new database connection. |
| 366 | */ |
| 367 | int sqlite3_auto_extension(void *xInit){ |
| 368 | int i; |
| 369 | int rc = SQLITE_OK; |
| 370 | sqlite3OsEnterMutex(); |
| 371 | for(i=0; i<nAutoExtension; i++){ |
| 372 | if( aAutoExtension[i]==xInit ) break; |
| 373 | } |
| 374 | if( i==nAutoExtension ){ |
| 375 | nAutoExtension++; |
| 376 | aAutoExtension = sqlite3Realloc( aAutoExtension, |
| 377 | nAutoExtension*sizeof(aAutoExtension[0]) ); |
| 378 | if( aAutoExtension==0 ){ |
| 379 | nAutoExtension = 0; |
| 380 | rc = SQLITE_NOMEM; |
| 381 | }else{ |
| 382 | aAutoExtension[nAutoExtension-1] = xInit; |
| 383 | } |
| 384 | } |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 385 | sqlite3OsLeaveMutex(); |
| 386 | assert( (rc&0xff)==rc ); |
drh | 1409be6 | 2006-08-23 20:07:20 +0000 | [diff] [blame] | 387 | return rc; |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | ** Reset the automatic extension loading mechanism. |
| 392 | */ |
| 393 | void sqlite3_reset_auto_extension(void){ |
| 394 | sqlite3OsEnterMutex(); |
| 395 | sqliteFree(aAutoExtension); |
| 396 | aAutoExtension = 0; |
| 397 | nAutoExtension = 0; |
| 398 | sqlite3OsLeaveMutex(); |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | ** Load all automatic extensions. |
| 403 | */ |
| 404 | int sqlite3AutoLoadExtensions(sqlite3 *db){ |
| 405 | int i; |
| 406 | int go = 1; |
| 407 | int rc = SQLITE_OK; |
| 408 | int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); |
| 409 | |
| 410 | if( nAutoExtension==0 ){ |
| 411 | /* Common case: early out without every having to acquire a mutex */ |
| 412 | return SQLITE_OK; |
| 413 | } |
| 414 | for(i=0; go; i++){ |
| 415 | char *zErrmsg = 0; |
| 416 | sqlite3OsEnterMutex(); |
| 417 | if( i>=nAutoExtension ){ |
| 418 | xInit = 0; |
| 419 | go = 0; |
| 420 | }else{ |
| 421 | xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*)) |
| 422 | aAutoExtension[i]; |
| 423 | } |
| 424 | sqlite3OsLeaveMutex(); |
| 425 | if( xInit && xInit(db, &zErrmsg, &sqlite3_apis) ){ |
| 426 | sqlite3Error(db, SQLITE_ERROR, |
| 427 | "automatic extension loading failed: %s", zErrmsg); |
| 428 | go = 0; |
| 429 | rc = SQLITE_ERROR; |
| 430 | } |
| 431 | } |
| 432 | return rc; |
| 433 | } |
| 434 | |
drh | 1e397f8 | 2006-06-08 15:28:43 +0000 | [diff] [blame] | 435 | #endif /* SQLITE_OMIT_LOAD_EXTENSION */ |