Bug 1313310 - Use SQLITE_OMIT_DEPRECATED. r=asuth draft
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 03 Nov 2016 20:14:03 +0100
changeset 434102 5d213471d4d6785abe5ac79a6696b47b6681cc6e
parent 434087 753433776a5e16b1c80c062bc6cdda05f26a81dd
child 434313 afdeb9f7e4785ada048f26f31b428fcb7353ffc2
push id34728
push usermak77@bonardo.net
push dateFri, 04 Nov 2016 21:17:02 +0000
reviewersasuth
bugs1313310
milestone52.0a1
Bug 1313310 - Use SQLITE_OMIT_DEPRECATED. r=asuth MozReview-Commit-ID: C4pZ6EP799G
db/sqlite3/src/moz.build
db/sqlite3/src/sqlite.symbols
storage/mozStorageConnection.cpp
--- a/db/sqlite3/src/moz.build
+++ b/db/sqlite3/src/moz.build
@@ -75,14 +75,18 @@ if CONFIG['OS_TARGET'] == 'Android':
     DEFINES['SQLITE_DEFAULT_FILE_PERMISSIONS'] = '0600'
 
 # Force using malloc_usable_size when building with jemalloc because _msize
 # causes assertions on Win64. See bug 719579.
 if CONFIG['OS_ARCH'] == 'WINNT' and CONFIG['MOZ_MEMORY']:
     DEFINES['HAVE_MALLOC_USABLE_SIZE'] = True
     DEFINES['SQLITE_WITHOUT_MSIZE'] = True
 
+# Omit unused functions to save some library footprint.
+DEFINES['SQLITE_OMIT_DEPRECATED'] = True
+DEFINES['SQLITE_OMIT_BUILTIN_TEST'] = True
+
 # Suppress warnings in third-party code.
 if CONFIG['GNU_CC']:
     CFLAGS += [
         '-Wno-sign-compare',
         '-Wno-type-limits',
     ]
--- a/db/sqlite3/src/sqlite.symbols
+++ b/db/sqlite3/src/sqlite.symbols
@@ -1,14 +1,13 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 sqlite3_aggregate_context
-sqlite3_aggregate_count
 sqlite3_auto_extension
 sqlite3_bind_blob
 sqlite3_bind_double
 sqlite3_bind_int
 sqlite3_bind_int64
 sqlite3_bind_null
 sqlite3_bind_parameter_count
 sqlite3_bind_parameter_index
@@ -54,34 +53,32 @@ sqlite3_db_mutex
 sqlite3_db_status
 sqlite3_declare_vtab
 sqlite3_enable_load_extension
 sqlite3_enable_shared_cache
 sqlite3_errcode
 sqlite3_errmsg
 sqlite3_errmsg16
 sqlite3_exec
-sqlite3_expired
+sqlite3_expanded_sql
 sqlite3_extended_result_codes
 sqlite3_file_control
 sqlite3_finalize
 sqlite3_free
 sqlite3_free_table
 sqlite3_get_autocommit
 sqlite3_get_auxdata
 sqlite3_get_table
-sqlite3_global_recover
 sqlite3_initialize
 sqlite3_interrupt
 sqlite3_last_insert_rowid
 sqlite3_libversion
 sqlite3_libversion_number
 sqlite3_load_extension
 sqlite3_malloc
-sqlite3_memory_alarm
 sqlite3_memory_highwater
 sqlite3_memory_used
 sqlite3_mutex_alloc
 sqlite3_mutex_enter
 sqlite3_mutex_free
 sqlite3_mutex_leave
 sqlite3_mutex_try
 sqlite3_mprintf
@@ -89,17 +86,16 @@ sqlite3_next_stmt
 sqlite3_open
 sqlite3_open_v2
 sqlite3_open16
 sqlite3_overload_function
 sqlite3_prepare
 sqlite3_prepare16
 sqlite3_prepare16_v2
 sqlite3_prepare_v2
-sqlite3_profile
 sqlite3_progress_handler
 sqlite3_realloc
 sqlite3_release_memory
 sqlite3_reset
 sqlite3_reset_auto_extension
 sqlite3_result_blob
 sqlite3_result_double
 sqlite3_result_error
@@ -123,20 +119,18 @@ sqlite3_snprintf
 sqlite3_sql
 sqlite3_status
 sqlite3_step
 sqlite3_stmt_readonly
 sqlite3_stmt_status
 #ifdef XP_UNIX
 sqlite3_temp_directory
 #endif
-sqlite3_thread_cleanup
 sqlite3_total_changes
-sqlite3_trace
-sqlite3_transfer_bindings
+sqlite3_trace_v2
 sqlite3_unlock_notify
 sqlite3_update_hook
 sqlite3_uri_parameter
 sqlite3_user_data
 sqlite3_value_blob
 sqlite3_value_bytes
 sqlite3_value_bytes16
 sqlite3_value_double
--- a/storage/mozStorageConnection.cpp
+++ b/storage/mozStorageConnection.cpp
@@ -189,20 +189,49 @@ struct Module
 
 Module gModules[] = {
   { "filesystem", RegisterFileSystemModule }
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Local Functions
 
-void tracefunc (void *aClosure, const char *aStmt)
+int tracefunc (unsigned aReason, void *aClosure, void *aP, void *aX)
 {
-  MOZ_LOG(gStorageLog, LogLevel::Debug, ("sqlite3_trace on %p for '%s'", aClosure,
-                                     aStmt));
+  switch (aReason) {
+    case SQLITE_TRACE_STMT: {
+      // aP is a pointer to the prepared statement.
+      sqlite3_stmt* stmt = static_cast<sqlite3_stmt*>(aP);
+      // aX is a pointer to a string containing the unexpanded SQL or a comment,
+      // starting with "--"" in case of a trigger.
+      char* expanded = static_cast<char*>(aX);
+      // Simulate what sqlite_trace was doing.
+      if (!::strncmp(expanded, "--", 2)) {
+        MOZ_LOG(gStorageLog, LogLevel::Debug,
+          ("TRACE_STMT on %p: '%s'", aClosure, expanded));
+      } else {
+        char* sql = ::sqlite3_expanded_sql(stmt);
+        MOZ_LOG(gStorageLog, LogLevel::Debug,
+          ("TRACE_STMT on %p: '%s'", aClosure, sql));
+        ::sqlite3_free(sql);
+      }
+      break;
+    }
+    case SQLITE_TRACE_PROFILE: {
+      // aX is pointer to a 64bit integer containing nanoseconds it took to
+      // execute the last command.
+      sqlite_int64 time = *(static_cast<sqlite_int64*>(aX)) / 1000000;
+      if (time > 0) {
+        MOZ_LOG(gStorageLog, LogLevel::Debug,
+          ("TRACE_TIME on %p: %dms", aClosure, time));
+      }
+      break;
+    }
+  }
+  return 0;
 }
 
 void
 basicFunctionHelper(sqlite3_context *aCtx,
                     int aArgc,
                     sqlite3_value **aArgv)
 {
   void *userData = ::sqlite3_user_data(aCtx);
@@ -696,17 +725,19 @@ Connection::initializeInternal()
   }
 
   // Properly wrap the database handle's mutex.
   sharedDBMutex.initWithMutex(sqlite3_db_mutex(mDBConn));
 
   // SQLite tracing can slow down queries (especially long queries)
   // significantly. Don't trace unless the user is actively monitoring SQLite.
   if (MOZ_LOG_TEST(gStorageLog, LogLevel::Debug)) {
-    ::sqlite3_trace(mDBConn, tracefunc, this);
+    ::sqlite3_trace_v2(mDBConn,
+                       SQLITE_TRACE_STMT | SQLITE_TRACE_PROFILE,
+                       tracefunc, this);
 
     MOZ_LOG(gStorageLog, LogLevel::Debug, ("Opening connection to '%s' (%p)",
                                         mTelemetryFilename.get(), this));
   }
 
   int64_t pageSize = Service::getDefaultPageSize();
 
   // Set page_size to the preferred default value.  This is effective only if