wxsqlite3. Problem compiling in DialogBlocks

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
avico
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Aug 10, 2009 8:58 am

wxsqlite3. Problem compiling in DialogBlocks

Post by avico »

Hi forum:

I test wxsqlite3 in a basic DialogBlocks project i obtain errors like :

----------------------- Configuration: MinGW Release -----------------------
In directory: C:\Documents and Settings\Antonio\Mis documentos\DialogBlocks Projects
mingw32-make.exe -f makefile.gcc CONFIG=release all
g++.exe -c -o MinGWRelease/test.o -fno-rtti -fno-pcc-struct-return -fstrict-aliasing -Wall -Wno-write-strings -D__WXMSW__ -D__GNUWIN32__ -D__WIN95__ -O -Wall -Wno-write-strings -I"C:/wxWidgets-2.8.10/include" -I"C:/wxWidgets-2.8.10/contrib/include" -I"C:/wxWidgets-2.8.10/lib/gcc_lib/msw" test.cpp
*** In file included from test.cpp:30:
*** wxsqlite3.h:409: error: expected identifier before numeric constant
*** wxsqlite3.h:409: error: expected `}' before numeric constant
*** wxsqlite3.h:409: error: expected unqualified-id before numeric constant
*** wxsqlite3.h:448: error: expected identifier before numeric constant
*** wxsqlite3.h:448: error: expected `}' before numeric constant
*** wxsqlite3.h:448: error: expected unqualified-id before numeric constant
*** wxsqlite3.h:451: error: expected declaration before '}' token
*** In file included from test.cpp:30:
*** wxsqlite3.h:13:1: unterminated #ifndef
*** mingw32-make.exe: *** [MinGWRelease/test.o] Error 1
Done.

9 errors, 0 warnings


The process for this is in DialogBlocs create a new project, create a basic Frame with a menu (only an item for open file with wxFileDialog) and a wxGrid element.

I add files from sqlite-amalgamation (sqlite3.c, sqlite3.h and sqlite3ext.h) for connect a sqlite database and compile without problem.

I add wxsqlite3.h, wxsqlite3.cpp, wxsqlitedef.h, wxsqlitedyn.h and wxsqlite3opt for integrate into project and add #include "wxsqlite3.h" in .c file (without more code). Compile this, show the above errors.

What is the problem?
avico
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Aug 10, 2009 8:58 am

¿Solved?

Post by avico »

write includes like:

#include "wxsqlite3.h"
...
#include "sqlite3.h"

solve the problem.

if #include "wxsqlite3.h" is after #include "sqlite3.h", has compilation error.
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxsqlite3. Problem compiling in DialogBlocks

Post by utelle »

avico wrote: I test wxsqlite3 in a basic DialogBlocks project i obtain errors like :

----------------------- Configuration: MinGW Release -----------------------
*** In file included from test.cpp:30:
*** wxsqlite3.h:409: error: expected identifier before numeric constant
[...]
9 errors, 0 warnings
This happens, since you apparently included sqlite3.h before wxsqlite3.h. sqlite3.h defines several symbols using #define statements, namely error codes and so on. The same symbols are used in wxsqlite3.h within enums. If sqlite3.h is included before wxsqlite3.h the preprocessor textually replaces the symbols within the enums by numbers - and that leads to the errors you received.

In the first place I don't see a reason for including sqlite3.h at all when using wxSQLite3. Encapsulating SQLite is what wxSQLite3 is all about. But if there are good reasons to include sqlite3.h this might indicate missing features in wxSQLite3. In that case report it to the author of wxSQLite3 (that's me :-)) and ask for integration of the missing feature.
avico wrote: I add files from sqlite-amalgamation (sqlite3.c, sqlite3.h and sqlite3ext.h) for connect a sqlite database and compile without problem.

I add wxsqlite3.h, wxsqlite3.cpp, wxsqlitedef.h, wxsqlitedyn.h and wxsqlite3opt for integrate into project and add #include "wxsqlite3.h" in .c file (without more code). Compile this, show the above errors.

What is the problem?
wxSQLite3 is written in C++. It should not be included in a .c file as the compiler usually interprets such files as pure C and not C++.
avico wrote: write includes like:

#include "wxsqlite3.h"
...
#include "sqlite3.h"

solve the problem.

if #include "wxsqlite3.h" is after #include "sqlite3.h", has compilation error.
Explanation above. Including sqlite3.h after wxsqlite3.h means that the preprocessor replaces only symbols defined by sqlite3.h in your own code. Usually this works without problems, but if you use wxSQLite3's enums you might get in trouble.

Regards,

Ulrich
avico
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Aug 10, 2009 8:58 am

Reason in ignorance.

Post by avico »

Yes, ignorance. Eliminate #include "sqlite3.h" compile without problem.

I am civil engineer, not programer, amb elemental concepts for programers are ignored for me (pointers are devil :-)).

For hobby, I test sqlite for store values and use a rudimentary wrapper (from sqlitecc). I test wsqlite3 for migrate from a "rudimentary and efficient" wrapper to "modern and wonderfull" wrapper with more funtcionalities.

And have more problem (Unicode are friend to pointers :-)).

In my code, whit actual wrapper, use like this:

grid_lista->SetCellValue(i, 0, query.GetField(i,0));

and show result without problem.

If values stored in sqlite are like "COMPACTACIÓN" and use wsqlite3 for retreive, code like

grid_lista->SetCellValue(table.GetAsString(2));

show empty value. Value stored like "COMPACTACION" show correctly.

I read documentation for wxSqlite about Unicode, search in projects like wxDatabaseLayer for solve this, but has problem
(remember, not programer).

Has a "sample for stupids" for convert value retreived for database like "table.GetAsString(2)" and show corretly in a widget ?.
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Reason in ignorance.

Post by utelle »

avico wrote:And have more problem (Unicode are friend to pointers :-)).

In my code, whit actual wrapper, use like this:

grid_lista->SetCellValue(i, 0, query.GetField(i,0));

and show result without problem.

If values stored in sqlite are like "COMPACTACIÓN" and use wsqlite3 for retreive, code like

grid_lista->SetCellValue(table.GetAsString(2));

show empty value. Value stored like "COMPACTACION" show correctly.

I read documentation for wxSqlite about Unicode, search in projects like wxDatabaseLayer for solve this, but has problem
(remember, not programer).

Has a "sample for stupids" for convert value retreived for database like "table.GetAsString(2)" and show corretly in a widget ?.
I guess the problem in your case is the tool you used to primarily store data in your SQLite database. Text should be stored as Unicode in a SQLite database, but unfortunately SQLite does not enforce the use of Unicode. If the text was encoded with Codepage cp1252 (winansi) for example wxSQLite3 will not be able to retrieve it correctly - as you already experienced.

The problem is made worse by wxWidgets itself since the wxWidgets conversion classes return an empty string if only a single character in the source string was not Unicode.

The default encoding for SQLite is UTF-8 (although this can be changed to UTF-16LE/BE), so you have to ensure that data are stored in UTF-8 format in the database to ensure it can be retrieved correctly.

Regards,

Ulrich
Post Reply