Skip to content

Commit c9fffa4

Browse files
Last version without the SQLiteDLLConnect changes
1 parent cf0f623 commit c9fffa4

File tree

3 files changed

+96
-63
lines changed

3 files changed

+96
-63
lines changed

sqlite3pp.cpp

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,22 @@
2222
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
// THE SOFTWARE.
2424

25-
// David Maisonave -- Nov-2021 Updated (std::string query::rows::get) to gracefully handle NULL string
25+
26+
//////////////////////////////////////////////////////////////////////////////////////////
27+
// Mod Author: David Maisonave - Sep-2025
28+
// This a modified version of [Wongoo Lee] original sqlite3pp.
29+
// - Source comes from the following link: https://github.com/iwongu/sqlite3pp
30+
// This version was originally modified by David Maisonave Nov-2021,
31+
// and then additional modifications made in Sep-2025.
32+
//
33+
// Most of the 2025 changes are associated with compiling with manage C++ code.
34+
//
35+
// Changes:
36+
// - Added UNICODE API's.
37+
// - Change some names to avoid spell checker errors.
38+
// - Changed local include to use "" instead of <>, to avoid compiler error on some systems.
39+
// - Added functions that take std::string
40+
// - Other miscellaneous changes where I added comments [David Maisonave changes]
2641

2742
#include <cstring>
2843
#include <memory>
@@ -37,6 +52,7 @@ SQLITE_EXTENSION_INIT1
3752
namespace sqlite3pp
3853
{
3954
null_type ignore;
55+
void* NULLPTR = NULL; // [David Maisonave changes] -- Used to replace [nullptr] which did not compile in manage C++ code
4056

4157
namespace
4258
{
@@ -81,6 +97,15 @@ namespace sqlite3pp
8197
}
8298
}
8399

100+
database::database(const std::string dbname, int flags, char const* vfs ) : db_( nullptr ), borrowing_( false )
101+
{
102+
if (dbname.size() > 0) {
103+
auto rc = connect( dbname.c_str(), flags, vfs);
104+
if ( rc != SQLITE_OK )
105+
throw database_error( "can't connect database" );
106+
}
107+
}
108+
84109
database::database(sqlite3* pdb) : db_(pdb), borrowing_(true)
85110
{
86111
}
@@ -246,13 +271,16 @@ namespace sqlite3pp
246271
return sqlite3_exec(db_, sql, 0, 0, 0);
247272
}
248273

249-
int database::executef(char const* sql, ...)
274+
int database::executef(char const* sql, const char* dbname, const char* name)
250275
{
251-
va_list ap;
252-
va_start(ap, sql);
253-
std::shared_ptr<char> msql(sqlite3_vmprintf(sql, ap), sqlite3_free);
254-
va_end(ap);
255-
276+
char* data = sqlite3_vmprintf(sql, (char*)dbname);
277+
std::shared_ptr<char> msql(sqlite3_vmprintf(data, (char*)name), sqlite3_free);
278+
sqlite3_free(data);
279+
return execute(msql.get());
280+
}
281+
int database::executef(char const* sql, const char* name)
282+
{
283+
std::shared_ptr<char> msql(sqlite3_vmprintf(sql, (char*)name), sqlite3_free);
256284
return execute(msql.get());
257285
}
258286

@@ -550,7 +578,7 @@ namespace sqlite3pp
550578
return *this;
551579
}
552580

553-
query::rows query::query_iterator::operator*() const
581+
query::query_iterator::value_type query::query_iterator::operator*() const
554582
{
555583
return rows(cmd_->stmt_);
556584
}

sqlite3pp.h

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,63 @@
2222
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
// THE SOFTWARE.
2424

25-
// David Maisonave -- Nov-2021 Added UNICODE API's
26-
25+
//////////////////////////////////////////////////////////////////////////////////////////
26+
// Mod Author: David Maisonave - Sep-2025
27+
// This a modified version of [Wongoo Lee] original sqlite3pp.
28+
// - Source comes from the following link: https://github.com/iwongu/sqlite3pp
29+
// This version was originally modified by David Maisonave Nov-2021,
30+
// and then additional modifications made in Sep-2025.
31+
//
32+
// Most of the 2025 changes are associated with compiling with manage C++ code,
33+
// using SQLiteDLLConnect.h which has a manage class SQLiteDLLConnect,
34+
// and allows run time linking to SQLite3.dll with manage C++ code.
35+
//
36+
// Changes:
37+
// - Added UNICODE API's.
38+
// - Change some names to avoid spell checker errors.
39+
// - Changed local include to use "" instead of <>, to avoid compiler error on some systems.
40+
// - Added functions that take std::string
41+
// - Added enhance logic to connect to SQLite3.db at runtime.
42+
// - Other miscellaneous changes where I added comments [David Maisonave changes]
43+
//
44+
// For example usage see [Wongoo Lee] github link: https://github.com/iwongu/sqlite3pp
2745

2846
#ifndef SQLITE3PP_H
2947
#define SQLITE3PP_H
3048

31-
#define SQLITE3PP_VERSION "1.0.8"
32-
#define SQLITE3PP_VERSION_MAJOR 1
33-
#define SQLITE3PP_VERSION_MINOR 0
34-
#define SQLITE3PP_VERSION_PATCH 8
49+
// [David Maisonave changes] -- commented out the following defines which where not being used, but was producing compiler warnings.
50+
//#define SQLITE3PP_VERSION "1.0.8"
51+
//#define SQLITE3PP_VERSION_MAJOR 1
52+
//#define SQLITE3PP_VERSION_MINOR 0
53+
//#define SQLITE3PP_VERSION_PATCH 8
3554

3655
#include <functional>
3756
#include <iterator>
3857
#include <stdexcept>
3958
#include <string>
4059
#include <tuple>
41-
#include <vector>
42-
#include <ctime>
43-
#include <memory>
60+
#include <vector> // [David Maisonave changes] -- Required for Blob & Clob types
61+
#include <memory> // [David Maisonave changes] -- Required for Blob & Clob types
62+
#include <ctime> // [David Maisonave changes] -- Required for Date & Datetime types
4463

64+
#ifdef SQLITE3PP_LOADABLE_EXTENSION
65+
#include "sqlite3ext.h"
66+
SQLITE_EXTENSION_INIT1
67+
#else
4568
#include "sqlite3.h"
69+
#endif
70+
#include "SQLiteDLLConnect.h"// [David Maisonave changes] -- Used for run time level connection to SQLite3.dll
4671

4772
namespace sqlite3pp
4873
{
74+
class database;
75+
namespace ext
76+
{
77+
class function;
78+
class aggregate;
79+
database borrow(sqlite3* pdb);
80+
}
81+
4982
#if defined(SQLITE3PP_NO_UNICODE) || !defined(_UNICODE)
5083
using tstring = std::string;
5184
#else
@@ -60,16 +93,6 @@ namespace sqlite3pp
6093
struct Datetime {std::tm tm_struct;};
6194
using TEXT = tstring;
6295
#endif //!SQLITE3PP_CONVERT_TO_RESULTING_AFFINITY
63-
64-
class database;
65-
66-
namespace ext
67-
{
68-
class function;
69-
class aggregate;
70-
database borrow(sqlite3* pdb);
71-
}
72-
7396
template <class T>
7497
struct convert {
7598
using to_int = int;
@@ -91,15 +114,9 @@ namespace sqlite3pp
91114
NonCopyable& operator=(NonCopyable const&) = delete;
92115
};
93116

94-
//struct sqlite3_api_routines;
95-
class db_api_root
96-
{
97-
public:
98-
db_api_root();
99-
};
100-
101-
class database : public db_api_root, private NonCopyable
117+
class database : NonCopyable
102118
{
119+
SQLite_DLL::RunTimeConnect* runTimeConnect = NULL;// [David Maisonave changes] -- Used for run time level connection to SQLite3.dll
103120
friend class statement;
104121
friend class database_error;
105122
friend class ext::function;
@@ -115,18 +132,17 @@ namespace sqlite3pp
115132
using backup_handler = std::function<void (int, int, int)>;
116133

117134
explicit database( char const* dbname = nullptr, int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, const char* vfs = nullptr );
118-
119135
database(database&& db);
120136
database& operator=(database&& db);
121-
137+
database(const std::string dbname, int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, const char* vfs = nullptr);// [David Maisonave changes] -- Add std::string support
138+
database(sqlite3* pdb); // [David Maisonave changes] -- Not sure why this was made private, but this constructor can be usefull when mixing classes of similar type.
122139
~database();
123140

124141
#ifndef SQLITE3PP_NO_UNICODE
125142
// Unicode support
126143
explicit database( const wchar_t* dbname, int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, const wchar_t* vfs = nullptr );
127144
int connect( const wchar_t* dbname, int flags, const wchar_t* vfs = nullptr );
128145
int execute( const std::wstring& sql );
129-
int execute( const std::string& sql );
130146
int attach(const wchar_t* dbname, const wchar_t* name);
131147
int detach(const wchar_t* name);
132148
int backup(const wchar_t* dbname, database& destdb, const wchar_t* destdbname, backup_handler h, int step_page = 5);
@@ -154,8 +170,8 @@ namespace sqlite3pp
154170
char const* error_msg() const;
155171

156172
int execute( char const* sql );
157-
int executef(char const* sql, ...);
158-
173+
// int executef(char const* sql, ...);// [David Maisonave changes] -- Removed this variadic function of executef because could not compile it in manage C++ code.
174+
int execute(const std::string& sql);// [David Maisonave changes] -- Adding std::string capabilities
159175
int set_busy_timeout(int ms);
160176

161177
void set_busy_handler(busy_handler h);
@@ -165,8 +181,8 @@ namespace sqlite3pp
165181
void set_authorize_handler(authorize_handler h);
166182

167183
private:
168-
database(sqlite3* pdb);
169-
184+
int executef(char const* sql, const char* dbname, const char* name);// [David Maisonave changes] -- Added this to replace associated variadic function which doesn't compile in manage C++ code.
185+
int executef(char const* sql, const char* name);// [David Maisonave changes] -- Added this to replace associated variadic function which doesn't compile in manage C++ code.
170186
private:
171187
sqlite3* db_;
172188
bool borrowing_;
@@ -182,13 +198,12 @@ namespace sqlite3pp
182198
{
183199
public:
184200
explicit database_error(char const* msg);
185-
explicit database_error(const std::string& msg);
201+
explicit database_error(const std::string& msg);// [David Maisonave changes] -- Adding std::string capabilities
186202
explicit database_error(database& db);
187203
};
188204

189205
enum copy_semantic { copy, nocopy };
190-
191-
class statement : public db_api_root, private NonCopyable
206+
class statement : NonCopyable
192207
{
193208
public:
194209
int prepare(char const* stmt);
@@ -354,9 +369,8 @@ namespace sqlite3pp
354369
private:
355370
sqlite3_stmt* stmt_;
356371
};
357-
358-
class query_iterator
359-
: public std::iterator<std::input_iterator_tag, rows>
372+
#pragma warning (disable : 4996) // [David Maisonave changes] -- Remove compiler warning for deprecated iterator.
373+
class query_iterator : public std::iterator<std::input_iterator_tag, rows>
360374
{
361375
public:
362376
query_iterator();
@@ -366,8 +380,7 @@ namespace sqlite3pp
366380
bool operator!=(query_iterator const&) const;
367381

368382
query_iterator& operator++();
369-
query::rows operator*() const;
370-
383+
value_type operator*() const;
371384
private:
372385
query* cmd_;
373386
int rc_;
@@ -388,7 +401,7 @@ namespace sqlite3pp
388401
iterator end();
389402
};
390403

391-
class transaction : public db_api_root, private NonCopyable
404+
class transaction : NonCopyable
392405
{
393406
public:
394407
explicit transaction(database& db, bool fcommit = false, bool freserve = false);

sqlite3pp_ez.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ namespace sqlite3pp
4242
if ( wsource == NULL )
4343
return std::wstring();
4444
MultiByteToWideChar( CP_ACP, 0, src, -1, wsource, nchars );
45-
std::wstring retrnVal = wsource;
45+
std::wstring returnVal = wSource;
4646
delete[] wsource;
47-
return retrnVal;
47+
return returnVal;
4848
}
4949

5050
std::string to_string( const wchar_t* src )
@@ -54,9 +54,9 @@ namespace sqlite3pp
5454
if ( source == NULL )
5555
return std::string();
5656
WideCharToMultiByte( CP_ACP, 0, src, -1, source, nchars, NULL, NULL );
57-
std::string retrnVal = source;
57+
std::string returnVal = source;
5858
delete[] source;
59-
return retrnVal;
59+
return returnVal;
6060
}
6161

6262
std::string to_string(const std::wstring &src)
@@ -245,14 +245,6 @@ namespace sqlite3pp
245245
return m_VerbosityLevels;
246246
}
247247

248-
db_api_root::db_api_root()
249-
{
250-
#ifdef SQLITE3PP_LOADABLE_EXTENSION
251-
static sqlite3_api_routines Glbl_sqlite3_api_routines;
252-
SQLITE_EXTENSION_INIT2(&Glbl_sqlite3_api_routines);
253-
#endif // SQLITE3PP_LOADABLE_EXTENSION
254-
}
255-
256248
int database::connect( const wchar_t* db_filename, int flags, const wchar_t * vfs )
257249
{
258250
if ( !borrowing_ )

0 commit comments

Comments
 (0)