Skip to content

Commit d46faec

Browse files
committed
Always build TSQLite but accept unresolved symbols
Always build TSQLite but accept unresolved symbols such that we can always build our SQLite interface without needing a build flag or to detect sqlite3 on the system. The price for us is that we need to duplicate the used sqlite3 interface declarations in our repository, but this should be acceptable since the interface is stable. The price for our users is that they need to explicitly link any library that uses TSQLite also against `sqlite3`, and if they use TSQLite in a macro they have to call `gInterpreter->Load("libsqlite3.so")`. It was checked that this works by running the TSQLite tutorials with this modification. The goal of this commit is that we can still provide TSQLite to our users, but without any maintenance cost like additional build options.
1 parent 41f7ac4 commit d46faec

File tree

7 files changed

+189
-9
lines changed

7 files changed

+189
-9
lines changed

sql/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44
# For the licensing terms see $ROOTSYS/LICENSE.
55
# For the list of contributors see $ROOTSYS/README/CREDITS.
66

7-
if(sqlite)
8-
add_subdirectory(sqlite)
9-
endif()
7+
add_subdirectory(sqlite)

sql/sqlite/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RSQLite
2525
RIO
2626
)
2727

28-
target_include_directories(RSQLite SYSTEM PUBLIC ${SQLITE_INCLUDE_DIR})
29-
target_link_libraries(RSQLite PUBLIC ${SQLITE_LIBRARIES})
28+
if(APPLE)
29+
target_link_libraries(RSQLite PUBLIC -Wl,-undefined)
30+
else()
31+
target_link_libraries(RSQLite PUBLIC -Wl,--unresolved-symbols=ignore-all)
32+
endif()

sql/sqlite/src/TSQLiteResult.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "TSQLiteResult.h"
1313
#include "TSQLiteRow.h"
1414

15-
#include <sqlite3.h>
15+
#include "sqlite3_interface.h"
1616

1717
ClassImp(TSQLiteResult);
1818

sql/sqlite/src/TSQLiteRow.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "TSQLiteRow.h"
1313

14-
#include <sqlite3.h>
14+
#include "sqlite3_interface.h"
1515

1616

1717
ClassImp(TSQLiteRow);

sql/sqlite/src/TSQLiteServer.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "TSQLTableInfo.h"
1818
#include "TSQLRow.h"
1919

20-
#include <sqlite3.h>
20+
#include "sqlite3_interface.h"
2121

2222
ClassImp(TSQLiteServer);
2323

sql/sqlite/src/TSQLiteStatement.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "TDatime.h"
2424
#include "TTimeStamp.h"
2525

26-
#include <sqlite3.h>
26+
#include "sqlite3_interface.h"
2727

2828
#include <stdlib.h>
2929

sql/sqlite/src/sqlite3_interface.h

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#ifndef sqlite3_interface_h
2+
#define sqlite3_interface_h
3+
4+
/**
5+
* Parts of sqlit3.h that we're using in TSQLite.
6+
*/
7+
8+
// Fundamental Datatypes
9+
#define SQLITE_INTEGER 1
10+
#define SQLITE_FLOAT 2
11+
#define SQLITE_BLOB 4
12+
#define SQLITE_NULL 5
13+
#ifdef SQLITE_TEXT
14+
#undef SQLITE_TEXT
15+
#else
16+
#define SQLITE_TEXT 3
17+
#endif
18+
#define SQLITE3_TEXT 3
19+
20+
// Result Codes
21+
#define SQLITE_OK 0 /* Successful result */
22+
/* beginning-of-error-codes */
23+
#define SQLITE_ERROR 1 /* Generic error */
24+
#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
25+
#define SQLITE_PERM 3 /* Access permission denied */
26+
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
27+
#define SQLITE_BUSY 5 /* The database file is locked */
28+
#define SQLITE_LOCKED 6 /* A table in the database is locked */
29+
#define SQLITE_NOMEM 7 /* A malloc() failed */
30+
#define SQLITE_READONLY 8 /* Attempt to write a readonly database */
31+
#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
32+
#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
33+
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
34+
#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
35+
#define SQLITE_FULL 13 /* Insertion failed because database is full */
36+
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
37+
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
38+
#define SQLITE_EMPTY 16 /* Internal use only */
39+
#define SQLITE_SCHEMA 17 /* The database schema changed */
40+
#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
41+
#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
42+
#define SQLITE_MISMATCH 20 /* Data type mismatch */
43+
#define SQLITE_MISUSE 21 /* Library used incorrectly */
44+
#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
45+
#define SQLITE_AUTH 23 /* Authorization denied */
46+
#define SQLITE_FORMAT 24 /* Not used */
47+
#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
48+
#define SQLITE_NOTADB 26 /* File opened that is not a database file */
49+
#define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */
50+
#define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */
51+
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
52+
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
53+
/* end-of-error-codes */
54+
55+
// Constants Defining Special Destructor Behavior
56+
typedef void (*sqlite3_destructor_type)(void *);
57+
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
58+
#define SQLITE_TRANSIENT ((sqlite3_destructor_type) - 1)
59+
60+
// Database Connection Handle
61+
typedef struct sqlite3 sqlite3;
62+
63+
// Prepared Statement Object
64+
typedef struct sqlite3_stmt sqlite3_stmt;
65+
66+
// Dynamically Typed Value Object
67+
class sqlite3_value;
68+
69+
// 64-Bit Integer Types
70+
#ifdef SQLITE_INT64_TYPE
71+
typedef SQLITE_INT64_TYPE sqlite_int64;
72+
#ifdef SQLITE_UINT64_TYPE
73+
typedef SQLITE_UINT64_TYPE sqlite_uint64;
74+
#else
75+
typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
76+
#endif
77+
#elif defined(_MSC_VER) || defined(__BORLANDC__)
78+
typedef __int64 sqlite_int64;
79+
typedef unsigned __int64 sqlite_uint64;
80+
#else
81+
typedef long long int sqlite_int64;
82+
typedef unsigned long long int sqlite_uint64;
83+
#endif
84+
typedef sqlite_int64 sqlite3_int64;
85+
typedef sqlite_uint64 sqlite3_uint64;
86+
87+
extern "C" {
88+
89+
// Closing A Database Connection
90+
int sqlite3_close(sqlite3 *);
91+
92+
// Number Of Columns In A Result Set
93+
int sqlite3_column_count(sqlite3_stmt *pStmt);
94+
95+
// Binding Values To Prepared Statements
96+
int sqlite3_bind_blob(sqlite3_stmt *, int, const void *, int n, void (*)(void *));
97+
int sqlite3_bind_blob64(sqlite3_stmt *, int, const void *, sqlite3_uint64, void (*)(void *));
98+
int sqlite3_bind_double(sqlite3_stmt *, int, double);
99+
int sqlite3_bind_int(sqlite3_stmt *, int, int);
100+
int sqlite3_bind_int64(sqlite3_stmt *, int, sqlite3_int64);
101+
int sqlite3_bind_null(sqlite3_stmt *, int);
102+
int sqlite3_bind_text(sqlite3_stmt *, int, const char *, int, void (*)(void *));
103+
int sqlite3_bind_text16(sqlite3_stmt *, int, const void *, int, void (*)(void *));
104+
int sqlite3_bind_text64(sqlite3_stmt *, int, const char *, sqlite3_uint64, void (*)(void *), unsigned char encoding);
105+
int sqlite3_bind_value(sqlite3_stmt *, int, const sqlite3_value *);
106+
int sqlite3_bind_pointer(sqlite3_stmt *, int, void *, const char *, void (*)(void *));
107+
int sqlite3_bind_zeroblob(sqlite3_stmt *, int, int n);
108+
int sqlite3_bind_zeroblob64(sqlite3_stmt *, int, sqlite3_uint64);
109+
110+
// Result Values From A Query
111+
const void *sqlite3_column_blob(sqlite3_stmt *, int iCol);
112+
double sqlite3_column_double(sqlite3_stmt *, int iCol);
113+
int sqlite3_column_int(sqlite3_stmt *, int iCol);
114+
sqlite3_int64 sqlite3_column_int64(sqlite3_stmt *, int iCol);
115+
const unsigned char *sqlite3_column_text(sqlite3_stmt *, int iCol);
116+
const void *sqlite3_column_text16(sqlite3_stmt *, int iCol);
117+
sqlite3_value *sqlite3_column_value(sqlite3_stmt *, int iCol);
118+
int sqlite3_column_bytes(sqlite3_stmt *, int iCol);
119+
int sqlite3_column_bytes16(sqlite3_stmt *, int iCol);
120+
int sqlite3_column_type(sqlite3_stmt *, int iCol);
121+
122+
// Compiling An SQL Statement
123+
int sqlite3_prepare(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **ppStmt, const char **pzTail);
124+
125+
// Error Codes And Messages
126+
int sqlite3_errcode(sqlite3 *db);
127+
int sqlite3_extended_errcode(sqlite3 *db);
128+
const char *sqlite3_errmsg(sqlite3 *);
129+
const void *sqlite3_errmsg16(sqlite3 *);
130+
const char *sqlite3_errstr(int);
131+
int sqlite3_error_offset(sqlite3 *db);
132+
133+
// Destroy A Prepared Statement Object
134+
int sqlite3_finalize(sqlite3_stmt *pStmt);
135+
136+
// Evaluate An SQL Statement
137+
int sqlite3_step(sqlite3_stmt *);
138+
139+
// Column Names In A Result Set
140+
const char *sqlite3_column_name(sqlite3_stmt *, int N);
141+
const void *sqlite3_column_name16(sqlite3_stmt *, int N);
142+
143+
// Find The Database Handle Of A Prepared Statement
144+
sqlite3 *sqlite3_db_handle(sqlite3_stmt *);
145+
146+
// Run-Time Library Version Numbers
147+
const char *sqlite3_libversion(void);
148+
const char *sqlite3_sourceid(void);
149+
int sqlite3_libversion_number(void);
150+
151+
// Opening A New Database Connection
152+
int sqlite3_open(const char *filename, sqlite3 **ppDb);
153+
154+
// Memory Allocation Subsystem
155+
void *sqlite3_malloc(int);
156+
void *sqlite3_malloc64(sqlite3_uint64);
157+
void *sqlite3_realloc(void *, int);
158+
void *sqlite3_realloc64(void *, sqlite3_uint64);
159+
void sqlite3_free(void *);
160+
sqlite3_uint64 sqlite3_msize(void *);
161+
162+
// Test For Auto-Commit Mode
163+
int sqlite3_get_autocommit(sqlite3 *);
164+
165+
// Number Of SQL Parameters
166+
int sqlite3_bind_parameter_count(sqlite3_stmt *);
167+
168+
// One-Step Query Execution Interface
169+
int sqlite3_exec(sqlite3 *, const char *sql, int (*callback)(void *, int, char **, char **), void *, char **errmsg);
170+
171+
// Reset A Prepared Statement Object
172+
int sqlite3_reset(sqlite3_stmt *pStmt);
173+
174+
// Count The Number Of Rows Modified
175+
int sqlite3_changes(sqlite3 *);
176+
sqlite3_int64 sqlite3_changes64(sqlite3 *);
177+
}
178+
179+
#endif // sqlite3_interface_h

0 commit comments

Comments
 (0)