~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/sqlite/test.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <sqlite3.h>
 
3
 
 
4
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
 
5
  int i;
 
6
  for(i=0; i<argc; i++){
 
7
    printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
 
8
  }
 
9
  printf("\n");
 
10
  return 0;
 
11
}
 
12
 
 
13
int main(){
 
14
  sqlite3 *db;
 
15
  char *zErrMsg = 0;
 
16
  int rc;
 
17
  int i;
 
18
  const char *commands[] = {
 
19
    "CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100));",
 
20
    "INSERT INTO t1 VALUES(1,13153,'thirteen thousand one hundred fifty three');",
 
21
    "INSERT INTO t1 VALUES(1,987,'some other number');",
 
22
    "SELECT count(*) FROM t1;",
 
23
    "SELECT a, b, c FROM t1;",
 
24
    NULL
 
25
  };
 
26
 
 
27
  rc = sqlite3_open(":memory:", &db);
 
28
  if( rc ){
 
29
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
 
30
    sqlite3_close(db);
 
31
    exit(1);
 
32
  }
 
33
  for (i = 0; commands[i]; i++) {
 
34
    rc = sqlite3_exec(db, commands[i], callback, 0, &zErrMsg);
 
35
    if( rc!=SQLITE_OK ){
 
36
      fprintf(stderr, "SQL error on %d: %s\n", i, zErrMsg);
 
37
      sqlite3_free(zErrMsg);
 
38
      exit(1);
 
39
    }
 
40
  }
 
41
  sqlite3_close(db);
 
42
  return 0;
 
43
}
 
44