persistentstorage/sql/SQLite/loadext.c
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     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 ** $Id: loadext.c,v 1.53 2008/08/02 03:50:39 drh Exp $
       
    16 */
       
    17 
       
    18 #ifndef SQLITE_CORE
       
    19   #define SQLITE_CORE 1  /* Disable the API redefinition in sqlite3ext.h */
       
    20 #endif
       
    21 #include "sqlite3ext.h"
       
    22 #include "sqliteInt.h"
       
    23 #include <string.h>
       
    24 #include <ctype.h>
       
    25 
       
    26 #ifndef SQLITE_OMIT_LOAD_EXTENSION
       
    27 
       
    28 /*
       
    29 ** Some API routines are omitted when various features are
       
    30 ** excluded from a build of SQLite.  Substitute a NULL pointer
       
    31 ** for any missing APIs.
       
    32 */
       
    33 #ifndef SQLITE_ENABLE_COLUMN_METADATA
       
    34 # define sqlite3_column_database_name   0
       
    35 # define sqlite3_column_database_name16 0
       
    36 # define sqlite3_column_table_name      0
       
    37 # define sqlite3_column_table_name16    0
       
    38 # define sqlite3_column_origin_name     0
       
    39 # define sqlite3_column_origin_name16   0
       
    40 # define sqlite3_table_column_metadata  0
       
    41 #endif
       
    42 
       
    43 #ifdef SQLITE_OMIT_AUTHORIZATION
       
    44 # define sqlite3_set_authorizer         0
       
    45 #endif
       
    46 
       
    47 #ifdef SQLITE_OMIT_UTF16
       
    48 # define sqlite3_bind_text16            0
       
    49 # define sqlite3_collation_needed16     0
       
    50 # define sqlite3_column_decltype16      0
       
    51 # define sqlite3_column_name16          0
       
    52 # define sqlite3_column_text16          0
       
    53 # define sqlite3_complete16             0
       
    54 # define sqlite3_create_collation16     0
       
    55 # define sqlite3_create_function16      0
       
    56 # define sqlite3_errmsg16               0
       
    57 # define sqlite3_open16                 0
       
    58 # define sqlite3_prepare16              0
       
    59 # define sqlite3_prepare16_v2           0
       
    60 # define sqlite3_result_error16         0
       
    61 # define sqlite3_result_text16          0
       
    62 # define sqlite3_result_text16be        0
       
    63 # define sqlite3_result_text16le        0
       
    64 # define sqlite3_value_text16           0
       
    65 # define sqlite3_value_text16be         0
       
    66 # define sqlite3_value_text16le         0
       
    67 # define sqlite3_column_database_name16 0
       
    68 # define sqlite3_column_table_name16    0
       
    69 # define sqlite3_column_origin_name16   0
       
    70 #endif
       
    71 
       
    72 #ifdef SQLITE_OMIT_COMPLETE
       
    73 # define sqlite3_complete 0
       
    74 # define sqlite3_complete16 0
       
    75 #endif
       
    76 
       
    77 #ifdef SQLITE_OMIT_PROGRESS_CALLBACK
       
    78 # define sqlite3_progress_handler 0
       
    79 #endif
       
    80 
       
    81 #ifdef SQLITE_OMIT_VIRTUALTABLE
       
    82 # define sqlite3_create_module 0
       
    83 # define sqlite3_create_module_v2 0
       
    84 # define sqlite3_declare_vtab 0
       
    85 #endif
       
    86 
       
    87 #ifdef SQLITE_OMIT_SHARED_CACHE
       
    88 # define sqlite3_enable_shared_cache 0
       
    89 #endif
       
    90 
       
    91 #ifdef SQLITE_OMIT_TRACE
       
    92 # define sqlite3_profile       0
       
    93 # define sqlite3_trace         0
       
    94 #endif
       
    95 
       
    96 #ifdef SQLITE_OMIT_GET_TABLE
       
    97 # define sqlite3_free_table    0
       
    98 # define sqlite3_get_table     0
       
    99 #endif
       
   100 
       
   101 #ifdef SQLITE_OMIT_INCRBLOB
       
   102 #define sqlite3_bind_zeroblob  0
       
   103 #define sqlite3_blob_bytes     0
       
   104 #define sqlite3_blob_close     0
       
   105 #define sqlite3_blob_open      0
       
   106 #define sqlite3_blob_read      0
       
   107 #define sqlite3_blob_write     0
       
   108 #endif
       
   109 
       
   110 /*
       
   111 ** The following structure contains pointers to all SQLite API routines.
       
   112 ** A pointer to this structure is passed into extensions when they are
       
   113 ** loaded so that the extension can make calls back into the SQLite
       
   114 ** library.
       
   115 **
       
   116 ** When adding new APIs, add them to the bottom of this structure
       
   117 ** in order to preserve backwards compatibility.
       
   118 **
       
   119 ** Extensions that use newer APIs should first call the
       
   120 ** sqlite3_libversion_number() to make sure that the API they
       
   121 ** intend to use is supported by the library.  Extensions should
       
   122 ** also check to make sure that the pointer to the function is
       
   123 ** not NULL before calling it.
       
   124 */
       
   125 static const sqlite3_api_routines sqlite3Apis = {
       
   126   sqlite3_aggregate_context,
       
   127   sqlite3_aggregate_count,
       
   128   sqlite3_bind_blob,
       
   129   sqlite3_bind_double,
       
   130   sqlite3_bind_int,
       
   131   sqlite3_bind_int64,
       
   132   sqlite3_bind_null,
       
   133   sqlite3_bind_parameter_count,
       
   134   sqlite3_bind_parameter_index,
       
   135   sqlite3_bind_parameter_name,
       
   136   sqlite3_bind_text,
       
   137   sqlite3_bind_text16,
       
   138   sqlite3_bind_value,
       
   139   sqlite3_busy_handler,
       
   140   sqlite3_busy_timeout,
       
   141   sqlite3_changes,
       
   142   sqlite3_close,
       
   143   sqlite3_collation_needed,
       
   144   sqlite3_collation_needed16,
       
   145   sqlite3_column_blob,
       
   146   sqlite3_column_bytes,
       
   147   sqlite3_column_bytes16,
       
   148   sqlite3_column_count,
       
   149   sqlite3_column_database_name,
       
   150   sqlite3_column_database_name16,
       
   151   sqlite3_column_decltype,
       
   152   sqlite3_column_decltype16,
       
   153   sqlite3_column_double,
       
   154   sqlite3_column_int,
       
   155   sqlite3_column_int64,
       
   156   sqlite3_column_name,
       
   157   sqlite3_column_name16,
       
   158   sqlite3_column_origin_name,
       
   159   sqlite3_column_origin_name16,
       
   160   sqlite3_column_table_name,
       
   161   sqlite3_column_table_name16,
       
   162   sqlite3_column_text,
       
   163   sqlite3_column_text16,
       
   164   sqlite3_column_type,
       
   165   sqlite3_column_value,
       
   166   sqlite3_commit_hook,
       
   167   sqlite3_complete,
       
   168   sqlite3_complete16,
       
   169   sqlite3_create_collation,
       
   170   sqlite3_create_collation16,
       
   171   sqlite3_create_function,
       
   172   sqlite3_create_function16,
       
   173   sqlite3_create_module,
       
   174   sqlite3_data_count,
       
   175   sqlite3_db_handle,
       
   176   sqlite3_declare_vtab,
       
   177   sqlite3_enable_shared_cache,
       
   178   sqlite3_errcode,
       
   179   sqlite3_errmsg,
       
   180   sqlite3_errmsg16,
       
   181   sqlite3_exec,
       
   182   sqlite3_expired,
       
   183   sqlite3_finalize,
       
   184   sqlite3_free,
       
   185   sqlite3_free_table,
       
   186   sqlite3_get_autocommit,
       
   187   sqlite3_get_auxdata,
       
   188   sqlite3_get_table,
       
   189   0,     /* Was sqlite3_global_recover(), but that function is deprecated */
       
   190   sqlite3_interrupt,
       
   191   sqlite3_last_insert_rowid,
       
   192   sqlite3_libversion,
       
   193   sqlite3_libversion_number,
       
   194   sqlite3_malloc,
       
   195   sqlite3_mprintf,
       
   196   sqlite3_open,
       
   197   sqlite3_open16,
       
   198   sqlite3_prepare,
       
   199   sqlite3_prepare16,
       
   200   sqlite3_profile,
       
   201   sqlite3_progress_handler,
       
   202   sqlite3_realloc,
       
   203   sqlite3_reset,
       
   204   sqlite3_result_blob,
       
   205   sqlite3_result_double,
       
   206   sqlite3_result_error,
       
   207   sqlite3_result_error16,
       
   208   sqlite3_result_int,
       
   209   sqlite3_result_int64,
       
   210   sqlite3_result_null,
       
   211   sqlite3_result_text,
       
   212   sqlite3_result_text16,
       
   213   sqlite3_result_text16be,
       
   214   sqlite3_result_text16le,
       
   215   sqlite3_result_value,
       
   216   sqlite3_rollback_hook,
       
   217   sqlite3_set_authorizer,
       
   218   sqlite3_set_auxdata,
       
   219   sqlite3_snprintf,
       
   220   sqlite3_step,
       
   221   sqlite3_table_column_metadata,
       
   222   sqlite3_thread_cleanup,
       
   223   sqlite3_total_changes,
       
   224   sqlite3_trace,
       
   225   sqlite3_transfer_bindings,
       
   226   sqlite3_update_hook,
       
   227   sqlite3_user_data,
       
   228   sqlite3_value_blob,
       
   229   sqlite3_value_bytes,
       
   230   sqlite3_value_bytes16,
       
   231   sqlite3_value_double,
       
   232   sqlite3_value_int,
       
   233   sqlite3_value_int64,
       
   234   sqlite3_value_numeric_type,
       
   235   sqlite3_value_text,
       
   236   sqlite3_value_text16,
       
   237   sqlite3_value_text16be,
       
   238   sqlite3_value_text16le,
       
   239   sqlite3_value_type,
       
   240   sqlite3_vmprintf,
       
   241   /*
       
   242   ** The original API set ends here.  All extensions can call any
       
   243   ** of the APIs above provided that the pointer is not NULL.  But
       
   244   ** before calling APIs that follow, extension should check the
       
   245   ** sqlite3_libversion_number() to make sure they are dealing with
       
   246   ** a library that is new enough to support that API.
       
   247   *************************************************************************
       
   248   */
       
   249   sqlite3_overload_function,
       
   250 
       
   251   /*
       
   252   ** Added after 3.3.13
       
   253   */
       
   254   sqlite3_prepare_v2,
       
   255   sqlite3_prepare16_v2,
       
   256   sqlite3_clear_bindings,
       
   257 
       
   258   /*
       
   259   ** Added for 3.4.1
       
   260   */
       
   261   sqlite3_create_module_v2,
       
   262 
       
   263   /*
       
   264   ** Added for 3.5.0
       
   265   */
       
   266   sqlite3_bind_zeroblob,
       
   267   sqlite3_blob_bytes,
       
   268   sqlite3_blob_close,
       
   269   sqlite3_blob_open,
       
   270   sqlite3_blob_read,
       
   271   sqlite3_blob_write,
       
   272   sqlite3_create_collation_v2,
       
   273   sqlite3_file_control,
       
   274   sqlite3_memory_highwater,
       
   275   sqlite3_memory_used,
       
   276 #ifdef SQLITE_MUTEX_NOOP
       
   277   0, 
       
   278   0, 
       
   279   0,
       
   280   0,
       
   281   0,
       
   282 #else
       
   283   sqlite3_mutex_alloc,
       
   284   sqlite3_mutex_enter,
       
   285   sqlite3_mutex_free,
       
   286   sqlite3_mutex_leave,
       
   287   sqlite3_mutex_try,
       
   288 #endif
       
   289   sqlite3_open_v2,
       
   290   sqlite3_release_memory,
       
   291   sqlite3_result_error_nomem,
       
   292   sqlite3_result_error_toobig,
       
   293   sqlite3_sleep,
       
   294   sqlite3_soft_heap_limit,
       
   295   sqlite3_vfs_find,
       
   296   sqlite3_vfs_register,
       
   297   sqlite3_vfs_unregister,
       
   298 
       
   299   /*
       
   300   ** Added for 3.5.8
       
   301   */
       
   302   sqlite3_threadsafe,
       
   303   sqlite3_result_zeroblob,
       
   304   sqlite3_result_error_code,
       
   305   sqlite3_test_control,
       
   306   sqlite3_randomness,
       
   307   sqlite3_context_db_handle,
       
   308 
       
   309   /*
       
   310   ** Added for 3.6.0
       
   311   */
       
   312   sqlite3_extended_result_codes,
       
   313   sqlite3_limit,
       
   314   sqlite3_next_stmt,
       
   315   sqlite3_sql,
       
   316   sqlite3_status,
       
   317 };
       
   318 
       
   319 /*
       
   320 ** Attempt to load an SQLite extension library contained in the file
       
   321 ** zFile.  The entry point is zProc.  zProc may be 0 in which case a
       
   322 ** default entry point name (sqlite3_extension_init) is used.  Use
       
   323 ** of the default name is recommended.
       
   324 **
       
   325 ** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
       
   326 **
       
   327 ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with 
       
   328 ** error message text.  The calling function should free this memory
       
   329 ** by calling sqlite3DbFree(db, ).
       
   330 */
       
   331 static int sqlite3LoadExtension(
       
   332   sqlite3 *db,          /* Load the extension into this database connection */
       
   333   const char *zFile,    /* Name of the shared library containing extension */
       
   334   const char *zProc,    /* Entry point.  Use "sqlite3_extension_init" if 0 */
       
   335   char **pzErrMsg       /* Put error message here if not 0 */
       
   336 ){
       
   337   sqlite3_vfs *pVfs = db->pVfs;
       
   338   void *handle;
       
   339   int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
       
   340   char *zErrmsg = 0;
       
   341   void **aHandle;
       
   342 
       
   343   /* Ticket #1863.  To avoid a creating security problems for older
       
   344   ** applications that relink against newer versions of SQLite, the
       
   345   ** ability to run load_extension is turned off by default.  One
       
   346   ** must call sqlite3_enable_load_extension() to turn on extension
       
   347   ** loading.  Otherwise you get the following error.
       
   348   */
       
   349   if( (db->flags & SQLITE_LoadExtension)==0 ){
       
   350     if( pzErrMsg ){
       
   351       *pzErrMsg = sqlite3_mprintf("not authorized");
       
   352     }
       
   353     return SQLITE_ERROR;
       
   354   }
       
   355 
       
   356   if( zProc==0 ){
       
   357     zProc = "sqlite3_extension_init";
       
   358   }
       
   359 
       
   360   handle = sqlite3OsDlOpen(pVfs, zFile);
       
   361   if( handle==0 ){
       
   362     if( pzErrMsg ){
       
   363       char zErr[256];
       
   364       zErr[sizeof(zErr)-1] = '\0';
       
   365       sqlite3_snprintf(sizeof(zErr)-1, zErr, 
       
   366           "unable to open shared library [%s]", zFile);
       
   367       sqlite3OsDlError(pVfs, sizeof(zErr)-1, zErr);
       
   368       *pzErrMsg = sqlite3DbStrDup(0, zErr);
       
   369     }
       
   370     return SQLITE_ERROR;
       
   371   }
       
   372   xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
       
   373                    sqlite3OsDlSym(pVfs, handle, zProc);
       
   374   if( xInit==0 ){
       
   375     if( pzErrMsg ){
       
   376       char zErr[256];
       
   377       zErr[sizeof(zErr)-1] = '\0';
       
   378       sqlite3_snprintf(sizeof(zErr)-1, zErr,
       
   379           "no entry point [%s] in shared library [%s]", zProc,zFile);
       
   380       sqlite3OsDlError(pVfs, sizeof(zErr)-1, zErr);
       
   381       *pzErrMsg = sqlite3DbStrDup(0, zErr);
       
   382       sqlite3OsDlClose(pVfs, handle);
       
   383     }
       
   384     return SQLITE_ERROR;
       
   385   }else if( xInit(db, &zErrmsg, &sqlite3Apis) ){
       
   386     if( pzErrMsg ){
       
   387       *pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg);
       
   388     }
       
   389     sqlite3_free(zErrmsg);
       
   390     sqlite3OsDlClose(pVfs, handle);
       
   391     return SQLITE_ERROR;
       
   392   }
       
   393 
       
   394   /* Append the new shared library handle to the db->aExtension array. */
       
   395   aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1));
       
   396   if( aHandle==0 ){
       
   397     return SQLITE_NOMEM;
       
   398   }
       
   399   if( db->nExtension>0 ){
       
   400     memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension);
       
   401   }
       
   402   sqlite3DbFree(db, db->aExtension);
       
   403   db->aExtension = aHandle;
       
   404 
       
   405   db->aExtension[db->nExtension++] = handle;
       
   406   return SQLITE_OK;
       
   407 }
       
   408 int sqlite3_load_extension(
       
   409   sqlite3 *db,          /* Load the extension into this database connection */
       
   410   const char *zFile,    /* Name of the shared library containing extension */
       
   411   const char *zProc,    /* Entry point.  Use "sqlite3_extension_init" if 0 */
       
   412   char **pzErrMsg       /* Put error message here if not 0 */
       
   413 ){
       
   414   int rc;
       
   415   sqlite3_mutex_enter(db->mutex);
       
   416   rc = sqlite3LoadExtension(db, zFile, zProc, pzErrMsg);
       
   417   sqlite3_mutex_leave(db->mutex);
       
   418   return rc;
       
   419 }
       
   420 
       
   421 /*
       
   422 ** Call this routine when the database connection is closing in order
       
   423 ** to clean up loaded extensions
       
   424 */
       
   425 void sqlite3CloseExtensions(sqlite3 *db){
       
   426   int i;
       
   427   assert( sqlite3_mutex_held(db->mutex) );
       
   428   for(i=0; i<db->nExtension; i++){
       
   429     sqlite3OsDlClose(db->pVfs, db->aExtension[i]);
       
   430   }
       
   431   sqlite3DbFree(db, db->aExtension);
       
   432 }
       
   433 
       
   434 /*
       
   435 ** Enable or disable extension loading.  Extension loading is disabled by
       
   436 ** default so as not to open security holes in older applications.
       
   437 */
       
   438 int sqlite3_enable_load_extension(sqlite3 *db, int onoff){
       
   439   sqlite3_mutex_enter(db->mutex);
       
   440   if( onoff ){
       
   441     db->flags |= SQLITE_LoadExtension;
       
   442   }else{
       
   443     db->flags &= ~SQLITE_LoadExtension;
       
   444   }
       
   445   sqlite3_mutex_leave(db->mutex);
       
   446   return SQLITE_OK;
       
   447 }
       
   448 
       
   449 #endif /* SQLITE_OMIT_LOAD_EXTENSION */
       
   450 
       
   451 /*
       
   452 ** The auto-extension code added regardless of whether or not extension
       
   453 ** loading is supported.  We need a dummy sqlite3Apis pointer for that
       
   454 ** code if regular extension loading is not available.  This is that
       
   455 ** dummy pointer.
       
   456 */
       
   457 #ifdef SQLITE_OMIT_LOAD_EXTENSION
       
   458 static const sqlite3_api_routines sqlite3Apis = { 0 };
       
   459 #endif
       
   460 
       
   461 
       
   462 /*
       
   463 ** The following object holds the list of automatically loaded
       
   464 ** extensions.
       
   465 **
       
   466 ** This list is shared across threads.  The SQLITE_MUTEX_STATIC_MASTER
       
   467 ** mutex must be held while accessing this list.
       
   468 */
       
   469 static struct {
       
   470   int nExt;        /* Number of entries in aExt[] */          
       
   471   void **aExt;     /* Pointers to the extension init functions */
       
   472 } autoext = { 0, 0 };
       
   473 
       
   474 
       
   475 /*
       
   476 ** Register a statically linked extension that is automatically
       
   477 ** loaded by every new database connection.
       
   478 */
       
   479 int sqlite3_auto_extension(void *xInit){
       
   480   int rc = SQLITE_OK;
       
   481 #ifndef SQLITE_OMIT_AUTOINIT
       
   482   rc = sqlite3_initialize();
       
   483   if( rc ){
       
   484     return rc;
       
   485   }else
       
   486 #endif
       
   487   {
       
   488     int i;
       
   489 #ifndef SQLITE_MUTEX_NOOP
       
   490     sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
       
   491 #endif
       
   492     sqlite3_mutex_enter(mutex);
       
   493     for(i=0; i<autoext.nExt; i++){
       
   494       if( autoext.aExt[i]==xInit ) break;
       
   495     }
       
   496     if( i==autoext.nExt ){
       
   497       int nByte = (autoext.nExt+1)*sizeof(autoext.aExt[0]);
       
   498       void **aNew;
       
   499       aNew = sqlite3_realloc(autoext.aExt, nByte);
       
   500       if( aNew==0 ){
       
   501         rc = SQLITE_NOMEM;
       
   502       }else{
       
   503         autoext.aExt = aNew;
       
   504         autoext.aExt[autoext.nExt] = xInit;
       
   505         autoext.nExt++;
       
   506       }
       
   507     }
       
   508     sqlite3_mutex_leave(mutex);
       
   509     assert( (rc&0xff)==rc );
       
   510     return rc;
       
   511   }
       
   512 }
       
   513 
       
   514 /*
       
   515 ** Reset the automatic extension loading mechanism.
       
   516 */
       
   517 void sqlite3_reset_auto_extension(void){
       
   518 #ifndef SQLITE_OMIT_AUTOINIT
       
   519   if( sqlite3_initialize()==SQLITE_OK )
       
   520 #endif
       
   521   {
       
   522 #ifndef SQLITE_MUTEX_NOOP
       
   523     sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
       
   524 #endif
       
   525     sqlite3_mutex_enter(mutex);
       
   526     sqlite3_free(autoext.aExt);
       
   527     autoext.aExt = 0;
       
   528     autoext.nExt = 0;
       
   529     sqlite3_mutex_leave(mutex);
       
   530   }
       
   531 }
       
   532 
       
   533 /*
       
   534 ** Load all automatic extensions.
       
   535 */
       
   536 int sqlite3AutoLoadExtensions(sqlite3 *db){
       
   537   int i;
       
   538   int go = 1;
       
   539   int rc = SQLITE_OK;
       
   540   int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
       
   541 
       
   542   if( autoext.nExt==0 ){
       
   543     /* Common case: early out without every having to acquire a mutex */
       
   544     return SQLITE_OK;
       
   545   }
       
   546   for(i=0; go; i++){
       
   547     char *zErrmsg = 0;
       
   548 #ifndef SQLITE_MUTEX_NOOP
       
   549     sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
       
   550 #endif
       
   551     sqlite3_mutex_enter(mutex);
       
   552     if( i>=autoext.nExt ){
       
   553       xInit = 0;
       
   554       go = 0;
       
   555     }else{
       
   556       xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
       
   557               autoext.aExt[i];
       
   558     }
       
   559     sqlite3_mutex_leave(mutex);
       
   560     if( xInit && xInit(db, &zErrmsg, &sqlite3Apis) ){
       
   561       sqlite3Error(db, SQLITE_ERROR,
       
   562             "automatic extension loading failed: %s", zErrmsg);
       
   563       go = 0;
       
   564       rc = SQLITE_ERROR;
       
   565       sqlite3_free(zErrmsg);
       
   566     }
       
   567   }
       
   568   return rc;
       
   569 }