Updated:
- Execute multiple SQL statements separated with ; (semicolons)
- 32/64-bit
- code can compiled with msvc too ?
Let me know if you find any errors in that code.
Small example for multiple SQL statements:
#include <stdio.h>
#include <stdlib.h>
#include "sqlite3.h"
#ifdef _WIN64
#pragma comment(lib, "SQLite364.lib")
#else
#pragma comment(lib, "SQLite3.lib")
#endif
int __cdecl main(int argc, char **argv)
{
sqlite3 *db;
int rc;
char *szSQL =
"DROP TABLE IF EXISTS test;"
"CREATE TABLE IF NOT EXISTS test (id INTEGER NOT NULL PRIMARY KEY, text VARCHAR(100));"
"INSERT INTO test VALUES (1, 'text1');"
"SELECT * FROM test;";
char *pSQL1, *pSQL2;
rc = sqlite3_open("test.db3", &db);
if (rc == SQLITE_OK)
{
sqlite3_stmt *stmt;
pSQL1 = szSQL; // at start
do
{
rc = sqlite3_prepare_v2(db, pSQL1, -1, &stmt, (const char**)&pSQL2);
if (rc == SQLITE_OK)
{
int nCols = sqlite3_column_count(stmt);
if (nCols)
{
int nCol;
for (nCol = 0; nCol < nCols; nCol++)
printf("%s\t", sqlite3_column_name(stmt, nCol));
printf("\n");
while ((rc = sqlite3_step(stmt)) == SQLITE_ROW)
for (nCol = 0; nCol < nCols; nCol++)
printf("%s\t", sqlite3_column_text(stmt, nCol));
printf("\n");
}
sqlite3_finalize(stmt);
} else {
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
break;
}
pSQL1 = pSQL2; // next statement
} while (*pSQL2);
sqlite3_close(db);
} else {
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return 1;
}
return 0;
}
EDIT 20110630-22:40: TLSQLite3Shell_WS_0_0_3.zip some fixes
EDIT 20110807: TLSQLite3Shell_WS_0_0_3_1.zip ToolBar bitmap