A
#include <stdio.h> #include <sqlite3.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&NBSP;ARGC,&NBSP;CHAR&NBSP;**ARGV) { sqlite3 *db; char *message = 0; int rc ; if (argc!=3) { fprintf (stderr, "Usage: %s database sql-statement\n ", argv[0]); return 1; } rc = sqlite3_open (argv[1], &db); if (RC) { fprintf (stderr, "Can ' t open database: %s\n", sqlite3_ ErrMsg (db)); sqlite3_close (db); return 1; } rc = sqlite3_exec ( Db , argv[2], callback,0 ,&message); if ( rc!=SQLITE_OK ) { fprintf (stderr, "sql error: %s\n", message); sqlite3_free (message); } sqlite3_close (db); return 0;}
To run the command:
./example test_db "CREATE TABLE test_table (int val);"
A test_db file that appears in the directory is the test_db database:)
Reference documents:
[0] An Introduction to the SQLite/C + + Interface http://www.sqlite.org/cintro.html
[1] SQLite3 C language API Primer http://www.blogjava.net/xylz/archive/2012/09/25/388519.html
SQLite3 C Language API usage records