Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SQLite and BCB 6.0

36 views
Skip to first unread message

Luc Saint-Elie

unread,
Nov 24, 2002, 7:47:45 AM11/24/02
to
Hello,

I'm looking for pointer (urls..) about the use of SQLite
(www.sqlite.org) with C++ Builder 6.0

Thanks in advance

luc

Remy Lebeau (TeamB)

unread,
Nov 24, 2002, 4:42:49 PM11/24/02
to
Did you notice the section of that very site that explains using SQLite in
C/C++?

http://www.sqlite.org/c_interface.html

Also, the "Quick Start" section (http://www.sqlite.org/quickstart.html) has
an example. Also, according to the site, there are examples of using SQLite
in the "src/shell.c" source file of the sample program.


Gambit

"Luc Saint-Elie" <luc@saint-elie_dot_com> wrote in message
news:6ii1uu8m14nivq4to...@4ax.com...

Luc Saint-Elie

unread,
Nov 27, 2002, 1:55:40 AM11/27/02
to
Remy,
Yes I did... but it ....
I 'm just looking for for a real life basic example.

Thanks

Luc

Remy Lebeau (TeamB)

unread,
Nov 27, 2002, 3:53:55 AM11/27/02
to
The code is straight C, it should be usable in Builder as-is. If it's not,
then please explain the exact symptoms in detail.


Gambit

"Luc Saint-Elie" <luc@saint-elie_dot_com> wrote in message

news:s1r8uu882guu0uvnh...@4ax.com...

Remy Lebeau (TeamB)

unread,
Nov 27, 2002, 1:19:02 PM11/27/02
to

"Luc Saint-Elie" <luc@saint-elie_dot_com> wrote in message
news:13e9uug428eaau7kh...@4ax.com...

> The API web page talks about 3 fucntions for SQLite use

The three main functions interfacing into the SQLLite API itself that your
own code should be calling.

> but the main.c file provided with the source that
> build a simple console interface to use SQLite is 800
> lines of code.

That is the actual internal source code for the SQLLite API itself. You're
not supposed to copy that code itself. You're supposed to first compile
that code into the library and then include the compiled library in your own
projects. Or save yourself a step and just use the pre-compiled library
that is downloadable separately.


Gambit


Luc Saint-Elie

unread,
Nov 27, 2002, 3:06:11 PM11/27/02
to
Remy,

It's what I tried unsuccessfully..

I tried to compile the source added to my project, result :
[Linker Error] Unresolved external '_sqlite_open' referenced from
D:\BORLAND\PROJETS\SQLITE\TEST2\UNIT1.OBJ

I tried to use the site's dll and even a dll compiled with borland
compiler (and not repednant of MSVCRT.DLL
(http://groups.yahoo.com/group/sqlite/files/SqliteExplorer/) , result
:
[Linker Error] Unresolved external '_sqlite_open' referenced from
D:\BORLAND\PROJETS\SQLITE\TEST2\UNIT1.OBJ

As sqlite_open with linker problems have an underscore I tried to
uncheck "Generate Underscores" in Project | Options | Advanced
Compiler.

The result is worse...

[Linker Error] Unresolved external '_BeforeDestruction' referenced
from D:\BORLAND\PROJETS\SQLITE\TEST2\PROJECT1.OBJ
[Linker Error] Unresolved external '_ClassDestroy' referenced from
D:\BORLAND\PROJETS\SQLITE\TEST2\PROJECT1.OBJ
[Linker Error] Unresolved external '_ClassCreate' referenced from
D:\BORLAND\PROJETS\SQLITE\TEST2\UNIT1.OBJ
[Linker Error] Unresolved external '_AfterConstruction' referenced
from D:\BORLAND\PROJETS\SQLITE\TEST2\UNIT1.OBJ
[Linker Error] Unresolved external 'free' referenced from
D:\BORLAND\PROJETS\SQLITE\TEST2\UNIT1.OBJ


Here is a very basic sample :

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
typedef struct sqlite sqlite;
#define SQLITE_OK 0 /* Successful result */

TForm1 *Form1;
extern "C"
{
sqlite* __declspec(dllimport) sqlite_open(const char *dbname, int
mode, char **errmsg);
void __declspec(dllimport) sqlite_close(sqlite*);
int __declspec(dllimport) sqlite_exec(
sqlite*,
char *sql,
int (*)(void*,int,char**,char**),
void*,
char **errmsg
);

}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
try
{
//=======
sqlite *db;
char *errMsg = NULL;

/* Open SQLite database. Assume that there was table created. */

if( (db = sqlite_open( "data\\esparrago.db", 0660, &errMsg )) ==
NULL ) {
Label1->Caption = "Can't open esparrago.db";

if( errMsg != NULL ) {
AnsiString message = errMsg ;
Label1->Caption = message.c_str() ;
free( errMsg );
}
}
//=======
}
catch (...) // Fails if the input is not a number
{
Application->MessageBox("Problem",NULL,MB_ICONERROR);
};
}
//---------------------------------------------------------------------------

Luc

Remy Lebeau (TeamB)

unread,
Nov 27, 2002, 5:47:44 PM11/27/02
to

"Luc Saint-Elie" <luc@saint-elie_dot_com> wrote in message
news:fp8auuolneuv1p8jd...@4ax.com...

> I tried to compile the source added to my project, result :
> [Linker Error] Unresolved external '_sqlite_open' referenced from
> D:\BORLAND\PROJETS\SQLITE\TEST2\UNIT1.OBJ

You should not be using __declspec(dllimport) as you are not statically
linking to a DLL and the functions are not exported to begin with thus
nothing to import.

Try the following:

1) File > New > Library
2) Add all of the .c files from the SQLLite source into the library (except
the shell.c and tclsqlite.c files)
3) Build the library
4) add the compiled .lib file to your main project
5) #include the sqlite.h header file

Worked fine for me in BCB5

> As sqlite_open with linker problems have an underscore
> I tried to uncheck "Generate Underscores" in Project
> | Options | Advanced Compiler.

You should not disable that option manually. The VCL needs it enabled, as
you've discovered the hard way.


Gambit


0 new messages