| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- MODULE test_exec ;
- (*
- m2SQLITE smoke test: one-step exec interface (CREATE/INSERT),
- error capture via ExecWithErr, and change counters.
- *)
- FROM SQLite IMPORT DbHandle, SQLiteOk, SQLiteDone, SQLiteRow,
- sqlite3_open, sqlite3_close,
- sqlite3_changes, sqlite3_total_changes, sqlite3_last_insert_rowid;
- FROM SQLiteUtils IMPORT ExecSimple, ExecWithErr;
- FROM libc IMPORT printf;
- VAR db: DbHandle; rc: INTEGER; buf: ARRAY [0..255] OF CHAR;
- rowid: LONGINT;
- BEGIN
- IF sqlite3_open(":memory:", db) # SQLiteOk THEN
- printf("FAIL test_exec: open\n");
- HALT(1)
- END;
- rc := ExecSimple(db, "CREATE TABLE t(id INTEGER PRIMARY KEY, name TEXT);");
- IF rc # SQLiteOk THEN
- printf("FAIL test_exec: create rc=%d\n", rc);
- HALT(1)
- END;
- rc := ExecSimple(db, "INSERT INTO t(name) VALUES('alice');");
- IF rc # SQLiteOk THEN
- printf("FAIL test_exec: insert rc=%d\n", rc);
- HALT(1)
- END;
- IF sqlite3_changes(db) # 1 THEN
- printf("FAIL test_exec: changes=%d want 1\n", sqlite3_changes(db));
- HALT(1)
- END;
- rowid := sqlite3_last_insert_rowid(db);
- printf("last_rowid=%ld\n", rowid);
- IF rowid # 1 THEN
- printf("FAIL test_exec: rowid=%ld want 1\n", rowid);
- HALT(1)
- END;
- (* failing statement must report its message *)
- rc := ExecWithErr(db, "INSERT INTO bogus(x) VALUES(1);", buf);
- printf("bad exec rc=%d err=%s\n", rc, buf);
- IF rc = SQLiteOk THEN
- printf("FAIL test_exec: bad SQL succeeded\n");
- HALT(1)
- END;
- IF buf[0] = 0C THEN
- printf("FAIL test_exec: empty error message\n");
- HALT(1)
- END;
- printf("total_changes=%d\n", sqlite3_total_changes(db));
- rc := sqlite3_close(db);
- IF rc # SQLiteOk THEN
- printf("FAIL test_exec: close rc=%d\n", rc);
- HALT(1)
- END;
- printf("PASS test_exec\n")
- END test_exec.
|