changeset 2302:f31dfb131dee

fix backward compatibility with SQLite < 3.19.0
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 10 Jul 2017 11:27:55 +0200
parents bde58ce4b41c
children 692527245856
files Core/SQLite/Connection.h Core/SQLite/FunctionContext.cpp Core/SQLite/FunctionContext.h Core/SQLite/SQLiteTypes.h Core/SQLite/Statement.h Core/SQLite/StatementReference.h Resources/CMake/SQLiteConfiguration.cmake
diffstat 7 files changed, 83 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/Core/SQLite/Connection.h	Mon Jul 10 09:28:30 2017 +0200
+++ b/Core/SQLite/Connection.h	Mon Jul 10 11:27:55 2017 +0200
@@ -39,13 +39,11 @@
 
 #include "Statement.h"
 #include "IScalarFunction.h"
+#include "SQLiteTypes.h"
 
 #include <string>
 #include <map>
 
-struct sqlite3;
-struct sqlite3_stmt;
-
 #define SQLITE_FROM_HERE ::Orthanc::SQLite::StatementId(__FILE__, __LINE__)
 
 namespace Orthanc
--- a/Core/SQLite/FunctionContext.cpp	Mon Jul 10 09:28:30 2017 +0200
+++ b/Core/SQLite/FunctionContext.cpp	Mon Jul 10 11:27:55 2017 +0200
@@ -49,7 +49,7 @@
   {
     FunctionContext::FunctionContext(struct sqlite3_context* context,
                                      int argc,
-                                     struct sqlite3_value** argv)
+                                     Internals::SQLiteValue** argv)
     {
       assert(context != NULL);
       assert(argc >= 0);
--- a/Core/SQLite/FunctionContext.h	Mon Jul 10 09:28:30 2017 +0200
+++ b/Core/SQLite/FunctionContext.h	Mon Jul 10 11:27:55 2017 +0200
@@ -36,9 +36,6 @@
 
 #include "Statement.h"
 
-struct sqlite3_context;
-struct sqlite3_value;
- 
 namespace Orthanc
 {
   namespace SQLite
@@ -50,14 +47,14 @@
     private:
       struct sqlite3_context* context_;
       unsigned int argc_;
-      struct sqlite3_value** argv_;
+      Internals::SQLiteValue** argv_;
 
       void CheckIndex(unsigned int index) const;
 
     public:
       FunctionContext(struct sqlite3_context* context,
                       int argc,
-                      struct sqlite3_value** argv);
+                      Internals::SQLiteValue** argv);
 
       ColumnType GetColumnType(unsigned int index) const;
  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Core/SQLite/SQLiteTypes.h	Mon Jul 10 11:27:55 2017 +0200
@@ -0,0 +1,70 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ *
+ * Copyright (C) 2012-2016 Sebastien Jodogne <s.jodogne@gmail.com>,
+ * Medical Physics Department, CHU of Liege, Belgium
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *    * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *    * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *    * Neither the name of the CHU of Liege, nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ **/
+
+
+#pragma once
+
+struct sqlite3;
+struct sqlite3_context;
+struct sqlite3_stmt;
+
+#if !defined(ORTHANC_SQLITE_VERSION)
+#error  Please define macro ORTHANC_SQLITE_VERSION
+#endif
+
+#if ORTHANC_SQLITE_VERSION < 3019000
+struct Mem;
+#endif
+
+namespace Orthanc
+{
+  namespace SQLite
+  {
+    namespace Internals
+    {
+      /**
+       * "sqlite3_value" is defined as:
+       * - "typedef struct Mem sqlite3_value;" up to SQLite <= 3.18.2
+       * - "typedef struct sqlite3_value sqlite3_value;" since SQLite >= 3.19.0.
+       * We create our own copy of this typedef to get around this API incompatibility.
+       * https://github.com/mackyle/sqlite/commit/db1d90df06a78264775a14d22c3361eb5b42be17
+       **/
+      
+#if ORTHANC_SQLITE_VERSION < 3019000
+      typedef struct ::Mem  SQLiteValue;
+#else
+      typedef struct ::sqlite3_value  SQLiteValue;
+#endif
+    }
+  }
+}
--- a/Core/SQLite/Statement.h	Mon Jul 10 09:28:30 2017 +0200
+++ b/Core/SQLite/Statement.h	Mon Jul 10 11:27:55 2017 +0200
@@ -49,8 +49,6 @@
 #include <gtest/gtest_prod.h>
 #endif
 
-struct sqlite3_stmt;
-
 
 namespace Orthanc
 {
--- a/Core/SQLite/StatementReference.h	Mon Jul 10 09:28:30 2017 +0200
+++ b/Core/SQLite/StatementReference.h	Mon Jul 10 11:27:55 2017 +0200
@@ -38,13 +38,12 @@
 #pragma once
 
 #include "NonCopyable.h"
+#include "SQLiteTypes.h"
 
 #include <stdint.h>
 #include <cassert>
 #include <stdlib.h>
 
-struct sqlite3;
-struct sqlite3_stmt;
 
 namespace Orthanc
 {
--- a/Resources/CMake/SQLiteConfiguration.cmake	Mon Jul 10 09:28:30 2017 +0200
+++ b/Resources/CMake/SQLiteConfiguration.cmake	Mon Jul 10 11:27:55 2017 +0200
@@ -19,6 +19,8 @@
   SET(SQLITE_MD5 "5fbeff9645ab035a1f580e90b279a16d")
   SET(SQLITE_URL "http://www.orthanc-server.com/downloads/third-party/sqlite-amalgamation-3071300.zip")
 
+  add_definitions(-DORTHANC_SQLITE_VERSION=3007013)
+
   DownloadPackage(${SQLITE_MD5} ${SQLITE_URL} "${SQLITE_SOURCES_DIR}")
 
   set(SQLITE_SOURCES
@@ -52,7 +54,10 @@
 
   # Autodetection of the version of SQLite
   file(STRINGS "${SQLITE_INCLUDE_DIR}/sqlite3.h" SQLITE_VERSION_NUMBER1 REGEX "#define SQLITE_VERSION_NUMBER.*$")    
-  string(REGEX REPLACE "#define SQLITE_VERSION_NUMBER(.*)$" "\\1" SQLITE_VERSION_NUMBER ${SQLITE_VERSION_NUMBER1})
+  string(REGEX REPLACE "#define SQLITE_VERSION_NUMBER(.*)$" "\\1" SQLITE_VERSION_NUMBER2 ${SQLITE_VERSION_NUMBER1})
+
+  # Remove the trailing spaces to convert the string to a proper integer
+  string(STRIP ${SQLITE_VERSION_NUMBER2} SQLITE_VERSION_NUMBER)
 
   message("Detected version of SQLite: ${SQLITE_VERSION_NUMBER}")
 
@@ -61,5 +66,7 @@
     message(FATAL_ERROR "SQLite version must be above 3.7.0. Please set the CMake variable USE_SYSTEM_SQLITE to OFF.")
   ENDIF()
 
+  add_definitions(-DORTHANC_SQLITE_VERSION=${SQLITE_VERSION_NUMBER})
+
   link_libraries(sqlite3)
 endif()