File: 01-spatialite_init_ex.patch

package info (click to toggle)
pyspatialite 3.0.1-13
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 760 kB
  • sloc: ansic: 3,956; python: 2,899; makefile: 63
file content (86 lines) | stat: -rw-r--r-- 3,006 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Description: Support 'new' spatialite_init_ex() scheme as alternative for the deprecated spatialite_init() method.
Author: J├╝rgen E. Fischer <jef@norbit.de>
Origin: https://github.com/qgis/QGIS/commit/d7ca190295079957a8d0ef446cd834351020e901
Bug: https://github.com/lokkju/pyspatialite/issues/24
Applied-Upstream: https://github.com/lokkju/pyspatialite/commit/1684aa83827a5a4f6ea07f148d5fb1e5f745449c

--- a/setup.py
+++ b/setup.py
@@ -130,6 +130,7 @@ class MyBuildExt(build_ext):
         ext.define_macros.append(("SQLITE_ENABLE_RTREE", "1"))   # build with fulltext search enabled
         ext.define_macros.append(("SQLITE_ENABLE_COLUMN_METADATA", "1"))   # build with fulltext search enabled
         ext.define_macros.append(("OMIT_FREEXL","1")) # build without FreeXL
+        ext.define_macros.append(("SPATIALITE_HAS_INIT_EX","1")) # don't use deprecated spatialite_init() method
         #ext.sources.append(os.path.join(AMALGAMATION_ROOT, "sqlite3.c"))
         #ext.sources.append(os.path.join(AMALGAMATION_ROOT, "spatialite.c"))
         #ext.include_dirs.append(AMALGAMATION_ROOT)
--- a/src/connection.c
+++ b/src/connection.c
@@ -29,6 +29,7 @@
 #include "prepare_protocol.h"
 #include "util.h"
 #include "sqlitecompat.h"
+#include "spatialite.h"
 
 #include "pythread.h"
 
@@ -81,7 +82,6 @@ int pysqlite_connection_init(pysqlite_Co
     }
 
     self->initialized = 1;
-    spatialite_init(0);
     self->begin_statement = NULL;
 
     self->statement_cache = NULL;
@@ -106,7 +106,15 @@ int pysqlite_connection_init(pysqlite_Co
         }
 
         Py_BEGIN_ALLOW_THREADS
+#if defined(SPATIALITE_HAS_INIT_EX)
+        self->slconn = spatialite_alloc_connection();
+#else
+        spatialite_init( 0 );
+#endif
         rc = sqlite3_open(PyString_AsString(database_utf8), &self->db);
+#if defined(SPATIALITE_HAS_INIT_EX)
+        spatialite_init_ex( self->db, self->slconn, 0 );
+#endif
         Py_END_ALLOW_THREADS
 
         Py_DECREF(database_utf8);
@@ -272,6 +280,9 @@ void pysqlite_connection_dealloc(pysqlit
     if (self->db) {
         Py_BEGIN_ALLOW_THREADS
         sqlite3_close(self->db);
+#if defined(SPATIALITE_HAS_INIT_EX)
+        spatialite_cleanup_ex( self->slconn );
+#endif
         Py_END_ALLOW_THREADS
     } else if (self->apsw_connection) {
         ret = PyObject_CallMethod(self->apsw_connection, "close", "");
@@ -372,6 +383,9 @@ PyObject* pysqlite_connection_close(pysq
         } else {
             Py_BEGIN_ALLOW_THREADS
             rc = sqlite3_close(self->db);
+#if defined(SPATIALITE_HAS_INIT_EX)
+            spatialite_cleanup_ex( self->slconn );
+#endif
             Py_END_ALLOW_THREADS
 
             if (rc != SQLITE_OK) {
--- a/src/connection.h
+++ b/src/connection.h
@@ -33,12 +33,11 @@
 #include "sqlite3.h"
 #include "spatialite.h"
 
-int spatialite_init(int verbose);
-
 typedef struct
 {
     PyObject_HEAD
     sqlite3* db;
+    void *slconn;
 
     /* 1 if we are currently within a transaction, i. e. if a BEGIN has been
      * issued */