Hi,
I'm programing (trying to) a program that must Open, Manage and Save a SQLite 2.1 database repeatedly in milliseconds. DB size 49KB.
Programing language : C++
Compiler : Dev-C++ v4.9.9.2 aka. Bloodshed
What have I found?
"sqlite3.h" and put it in the includes folder.
with it was "sqlite3.c" and "sqlite3ext.h" witch together makes the
"sqlite-amalgamation-3_6_11" package.
I do not know what to do with the 2 extra files.
Well
http://www.sqlite.org/amalgamation.html tells me that this set makes a program run 5 -> 10% faster, but I tried including all of them and lets just say the result was unpleasing.
So then I found a "SQLite wrapper"
http://www.adp-gmbh.ch/sqlite/wrapper.html
2 files to create and include into the include folder. done.
SQLiteWrapper.cpp and SQLiteWrapper.h
I used there test app.
http://www.adp-gmbh.ch/sqlite/wrapper_test_1.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include "SQLiteWrapper.h"
int main() {
SQLiteWrapper sqlite;
if (sqlite.Open("SQLiteWrapper.db")) {
std::cout << "SQLiteWrapper.db created or opened" << std::endl;
}
else {
std::cout << "couldn't open SQLiteWrapper.db" << std::endl;
}
if (sqlite.DirectStatement("insert into foo values (1, 2)")) {
std::cout << "values (1,2) into foo inserted" << std::endl;
}
else {
std::cout << "Couldn't insert into foo" << std::endl;
}
return 0;
}
| |
and the result: PS: most directories were replaced with <dir> to help you read the log.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
Compiler: Default compiler
Executing g++.exe...
g++.exe "<dir>\devcpp\work folder\test\sqlitetest.cpp"
-o "<dir>\devcpp\work folder\test\sqlitetest.exe"
-I"<dir>\devcpp\lib\gcc\mingw32\3.4.2\include"
-I"<dir>\devcpp\include\c++\3.4.2\backward"
-I"<dir>\devcpp\include\c++\3.4.2\mingw32"
-I"<dir>\devcpp\include\c++\3.4.2"
-I"<dir>\devcpp\include"
-L"<dir>\devcpp\lib"
In file included from <dir>\devcpp\work folder\test\sqlitetest.cpp:3:
<dir>/devcpp/include/SQLiteWrapper.h:137:7: warning: no newline at end of file
<dir2>\Temp/ccYlbaaa.o(.text+0x170):sqlitetest.cpp: undefined reference to `SQLiteWrapper::SQLiteWrapper()'
<dir2>\Temp/ccYlbaaa.o(.text+0x1b5):sqlitetest.cpp: undefined reference to `SQLiteWrapper::Open(std::string const&)'
<dir2>\Temp/ccYlbaaa.o(.text+0x2e6):sqlitetest.cpp: undefined reference to `SQLiteWrapper::DirectStatement(std::string const&)'
collect2: ld returned 1 exit status
Execution terminated
| |
So with that in mind I got another at
http://www.alhem.net/project/sqlite/
to get the file they use in there programs I must get a file "libsqlitewrapped.h"
Sometimes the libsqlitewrapped.h file does not get created, so here's how to manually create it.
Win32
copy IError.h+StderrLog.h+SysLog.h+Database.h+Query.h libsqlitewrapped.h
Unix
cat IError.h StderrLog.h SysLog.h Database.h Query.h > libsqlitewrapped.h
|
the result
1 2 3 4 5 6 7
|
pped.h
IError.h
StderrLog.h
SysLog.h
Database.h
Query.h
1 file(s) copied.
| |
thus a success.
libsqlitewrapped.h was created with the size ~15KB.
Moved that file into the includes folder.
Now let's test it.
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
|
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>
#include <string>
#include "Database.h" // Line 6
#include "Query.h" // Line 7
int main()
{
Database db( "database_file.db" );
Query q(db);
q.execute("delete from user");
q.execute("insert into user values(1,'First Person')");
q.execute("insert into user values(2,'Another Person')");
q.get_result("select num,name from user");
while (q.fetch_row())
{
long num = q.getval();
std::string name = q.getstr();
printf("User#%ld: %s\n", num, name.c_str() );
}
q.free_result();
}
| |
hmmm thats funny, look at that, look at line 6 & 7, I put those in the file libsqlitewrapped.h ...? ok whatever.
So I copy the following files in the include folder. <again, more files /cry>
Database.cpp
Database.h
IError.h
Query.cpp
Query.h
StderrLog.cpp
StderrLog.h
SysLog.cpp
SysLog.h
This is all the files that come in the zip.
The result: Some <dir> story here
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
|
Compiler: Default compiler
Executing g++.exe...
g++.exe "<dir>\devcpp\work folder\test\sqlitetest2.cpp"
-o "<dir>\devcpp\work folder\test\sqlitetest2.exe"
-I"<dir>\devcpp\lib\gcc\mingw32\3.4.2\include"
-I"<dir>\devcpp\include\c++\3.4.2\backward"
-I"<dir>\devcpp\include\c++\3.4.2\mingw32"
-I"<dir>\devcpp\include\c++\3.4.2"
-I"<dir>\devcpp\include"
-L"<dir>\devcpp\lib"
<dir2>\Temp/ccmAaaaa.o(.text+0xbd):sqlitetest2.cpp: undefined reference to `Database::Database(std::string const&, IError*)'
<dir2>\Temp/ccmAaaaa.o(.text+0x16a):sqlitetest2.cpp: undefined reference to `Query::Query(Database&)'
<dir2>\Temp/ccmAaaaa.o(.text+0x1b8):sqlitetest2.cpp: undefined reference to `Query::execute(std::string const&)'
<dir2>\Temp/ccmAaaaa.o(.text+0x281):sqlitetest2.cpp: undefined reference to `Query::execute(std::string const&)'
<dir2>\Temp/ccmAaaaa.o(.text+0x34a):sqlitetest2.cpp: undefined reference to `Query::execute(std::string const&)'
<dir2>\Temp/ccmAaaaa.o(.text+0x413):sqlitetest2.cpp: undefined reference to `Query::get_result(std::string const&)'
<dir2>\Temp/ccmAaaaa.o(.text+0x4a6):sqlitetest2.cpp: undefined reference to `Query::fetch_row()'
<dir2>\Temp/ccmAaaaa.o(.text+0x4bc):sqlitetest2.cpp: undefined reference to `Query::getval()'
<dir2>\Temp/ccmAaaaa.o(.text+0x4ee):sqlitetest2.cpp: undefined reference to `Query::getstr()'
<dir2>\Temp/ccmAaaaa.o(.text+0x695):sqlitetest2.cpp: undefined reference to `Query::free_result()'
<dir2>\Temp/ccmAaaaa.o(.text+0x6bb):sqlitetest2.cpp: undefined reference to `Query::~Query()'
<dir2>\Temp/ccmAaaaa.o(.text+0x6e1):sqlitetest2.cpp: undefined reference to `Query::~Query()'
<dir2>\Temp/ccmAaaaa.o(.text+0x704):sqlitetest2.cpp: undefined reference to `Database::~Database()'
<dir2>\Temp/ccmAaaaa.o(.text+0x73d):sqlitetest2.cpp: undefined reference to `Database::~Database()'
collect2: ld returned 1 exit status
Execution terminated
| |
Ok so let's try their Tut.
http://www.alhem.net/sql_cpp_tutorial/tut_3.html
1 2 3 4 5 6 7 8 9 10 11 12
|
#include <libsqlitewrapped.h>
int main()
{
Database db("tutorial.db");
if (!db.Connected())
{
printf("Database not connected - exiting\n");
exit(-1);
}
}
| |
Nice now only the libsqlitewrapped.h is used.
and the result:
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
|
Compiler: Default compiler
Executing g++.exe...
g++.exe "<dir>\devcpp\work folder\test\sqlitetest2.cpp"
-o "<dir>\devcpp\work folder\test\sqlitetest2.exe"
-I"<dir>\devcpp\lib\gcc\mingw32\3.4.2\include"
-I"<dir>\devcpp\include\c++\3.4.2\backward"
-I"<dir>\devcpp\include\c++\3.4.2\mingw32"
-I"<dir>\devcpp\include\c++\3.4.2"
-I"<dir>\devcpp\include"
-L"<dir>\devcpp\lib"
In file included from <dir>\devcpp\work folder\test\sqlitetest2.cpp:1:
<dir>/devcpp/include/libsqlitewrapped.h:273: error: ISO C++ forbids declaration of `sqlite3' with no type
<dir>/devcpp/include/libsqlitewrapped.h:273: error: expected `;' before '*' token
In file included from <dir>\devcpp\work folder\test\sqlitetest2.cpp:1:
<dir>/devcpp/include/libsqlitewrapped.h:419: error: ISO C++ forbids declaration of `sqlite3_stmt' with no type
<dir>/devcpp/include/libsqlitewrapped.h:419: error: expected `;' before '*' token
<dir>/devcpp/include/libsqlitewrapped.h:427: error: `sqlite_int64' does not name a type
<dir>/devcpp/include/libsqlitewrapped.h:500: error: ISO C++ forbids declaration of `sqlite3_stmt' with no type
<dir>/devcpp/include/libsqlitewrapped.h:500: error: expected `;' before '*' token
<dir>/devcpp/include/libsqlitewrapped.h:519: error: stray '\26' in program
In file included from <dir>\devcpp\work folder\test\sqlitetest2.cpp:1:
<dir>/devcpp/include/libsqlitewrapped.h:519:2: warning: no newline at end of file
Execution terminated
| |
At this point I had just about enough.
I want to try and keep this hole thing multiplatform.
as soon as I get my Boost Lib working like it's espouse to, then I'd like to use SQLite in it. The Boost Lib Pack does not have SQLite support at this stage.
PS: I'm new in C++, with enough knowledge about php (if it counts for something).
Note: I do not want to reinvent the wheel, thus I'd like to use Libs to save time and not code on stuff that is already coded. If you can supply a better Lib than Boost PLEASE do tell me :P
I want to say "Thanks in advance." but that then would read like the sign at Macdolans tables "Thank you for cleaning your table." hmmmm yeah about that.
Thanks in advance :P