This program demonstrates the use of SQLcrypt™. It is based on the "quick start" example on www.sqlite.org.
#include <stdio.h>
#include <sqlite3.h>
#include <sqlcrypt3.h>
static int callback(void *NotUsed, int ac, char **av, char **azColName){
int i;
for(i=0; i<ac; i++){
printf("%s = %s\n", azColName[i], av[i] ? av[i] : "NULL");
}
printf("\n");
return 0;
}
int main(int argc, char **argv){
sqlite3 *db;
char *zErrMsg = 0;
int enc_op, rc;
if( argc!=5 ){
fprintf(stderr, "Usage: %s DATABASE e|? PASSPHRASE SQL\n", argv[0]);
exit(1);
}
rc = sqlcrypt3_license_key("ZIHKBLID-IACHUSSU-JUPOTCNF-CXYOQSFE");
if( rc!=SQLITE_OK ){
fprintf(stderr, "Incorrect license key.\n");
exit(1);
}
rc = sqlite3_open(argv[1], &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
enc_op = ( *argv[2]=='e' ) ? 1 : 0;
rc = sqlcrypt3_passphrase(db, argv[3], enc_op, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
rc = sqlite3_exec(db, argv[4], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
}
sqlite3_close(db);
return 0;
}
Mike Chirico has produced an excellent tutorial on SQLite that is fully applicable to SQLcrypt™. Take a look.
SQLite itself has been interfaced to many other programming languages. We intend to extend as many of these interfaces as is practical for SQLcrypt™.