- Make sure you have the latest version of SQLite
- Make sure you have the latest version of Mingw
- Using your favourite text editor, create a file called test.c and save it somwhere you can compile it. Make sure the sqlite.dll file is in the same directory. Here is the code for test.c:
#include <stdio.h>
#include <sqlite.h>
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int main(int argc, char **argv){
sqlite *db;
char *zErrMsg = 0;
int rc;
if( argc!=3 ){
fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
exit(1);
}
db = sqlite_open(argv[1], 0, &zErrMsg);
if( db==0 ){
fprintf(stderr, "Can't open database: %s\n", zErrMsg);
exit(1);
}
rc = sqlite_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
}
sqlite_close(db);
return 0;
}
- Compile test.c with the following: gcc -o main.exe -I /include sqlite.dll sltest2.c
- In the same directory as the compiled c file, enter: "sqlite test.db". This will create a new database named "test.db". Of course, sqlite.exe must either be in this directory or in your path.
- Enter the following:
sqlite> CREATE TABLE Orders
...> (
...> Orders
...> );
sqlite> INSERT INTO orders VALUES ("Order1");
sqlite> INSERT INTO orders VALUES ("Order2");
.quit
- Type the following command: main test.db "SELECT * FROM Orders;". If you are using a different db, modify the SQL statement accordingly.
- You should see:
C:\EJD\MinGW\bin>main test.db "SELECT * FROM Orders;".
Orders = Order1
Orders = Order2