After a lot of reading and experimenting, I was able to get SQLite3
working with Visual C++.net 2003.
Here is what I did

Steps to use SQLite3 in VC++.net 2003
------------------------------------------------------------

Download the source code for sqlite3 from http://www.sqlite.org/download.html
Filename: sqlite-source-3_3_7.zip
Extract these files to a folder.

Downloaded the DLL from http://www.sqlite.org/download.html
Filename: sqlitedll-3_3_7.zip
(166.80 KiB)

Extracted the contents of the zip folder
Contents:
sqlite3.dll
sqlite3.def

the dll included supposedly does not work with 2003 version of VC++

So the following file was downloaded from
http://www.arkesystems.com/Solutions/SQLite/SQLite.aspx
Filename: Sqlite.dll project
This zip file contains only sqlite3.dll
This file must replace the original dll.

The .dll and the .def file are then moved to
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin

We need to generate a .lib file to use the dll in a program

Note: make sure mspdb71.dll is present in the above folder, else
search for it on the system and move a copy to this folder. (As I had
some trouble with getting lib.exe working)

Go to the command prompt and change the directory to
cd C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin

Now type the following and hit <ENTER> to generate the lib file

LIB /DEF:sqlite3.def
This should generate the following files
sqlite3.exp
sqlite3.lib



Create a new project in VC++.net 2003
copy the following files of sqlite3 into the projects 'debug' folder
sqlite3.lib
sqlite3.dll


Go to Project Properties and under 'additional library directories'
add the debug folder of the project

under Linker->Input->Additional dependencies add 'sqlite3.lib'

copy 'sqlite3.h' (from the source folder which is obtained by
unzipping sqlite-source-3_3_7.zip) to the project folder.

I used the sample C code from the SQLite
website(http://www.sqlite.org/quickstart.html), only making a few
changes to make it C++ compatible.

Here is the listing of my code
// sqliteConnector.cpp : Defines the entry point for the console application.
//
#include <iostream>
using namespace std;
#include "sqlite3.h"

static int callback(void *NotUsed, int argc, char **argv, char **azColName){
 int i;
 for(i=0; i<argc; i++){
   cout<<azColName[i]<<" = "<<argv[i] ? argv[i] : "NULL";
 }
 cout<<endl;
 return 0;
}

int main(int argc, char **argv){
 sqlite3 *db;
 char *zErrMsg = 0;
 int rc;

 if( argc!=3 ){
   cout<<"Usage: "<<argv[0]<<" DATABASE SQL-STATEMENT\n";
   exit(1);
 }
 rc = sqlite3_open(argv[1], &db);
 if( rc ){
   cout<<"Can't open database: "<<sqlite3_errmsg(db)<<"\n";
       sqlite3_close(db);
   exit(1);
 }
 rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
 if( rc!=SQLITE_OK ){
   cout<<"SQL error: "<<zErrMsg<<"\n";
       sqlite3_free(zErrMsg);
 }
 sqlite3_close(db);
 return 0;
}

Built the project and it worked without any issues. If you have a
database ready you are ready to test and it works fine


--
Abhi Menon


--
Abhilash R Menon

email:[EMAIL PROTECTED], [EMAIL PROTECTED]

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to