SHARE
TWEET

3

a guest May 22nd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "../../common/sqlite-amalgamation-3220000/sqlite3.h"
  2. #include <stdio.h>
  3.  
  4. const char szSql[] =
  5. "SELECT 2+2, 3*3;"
  6. "CREATE TABLE users(id INT NOT NULL, email VARCHAR(20) NOT NULL);"
  7. "INSERT INTO users (id, email) VALUES (1, 'nobody@noserver.net');"
  8. "SELECT rowid, * FROM users;"
  9. "INSERT INTO users (rowid, id, email) VALUES (2019, 1, 'nobody@noserver.net');"
  10. "HELLO";
  11.  
  12. int main(void) {
  13.     sqlite3 *db;
  14.     int      nErrNr;
  15.     sqlite3_stmt* st;
  16.     const char *pErr;
  17.     char* tail;
  18.     int nColCnt;
  19.     int i;
  20.     nErrNr = sqlite3_open("MyFirstDb", &db);
  21.     nErrNr = sqlite3_prepare(db, "SELECT ?+?, ?*?", -1, &st, &tail);
  22.     if (nErrNr) {
  23.         pErr = sqlite3_errmsg(db);
  24.         printf("%s\n", pErr);
  25.     }
  26.     nErrNr = sqlite3_bind_int(st, 1, 2);
  27.     nErrNr = sqlite3_bind_int(st, 2, 2);
  28.     nErrNr = sqlite3_bind_int(st, 3, 2);
  29.     nErrNr = sqlite3_bind_int(st, 4, 2);
  30.     while ((nErrNr = sqlite3_step(st)) == SQLITE_ROW) {
  31.         nColCnt = sqlite3_column_count(st);
  32.         for (int i = 0; i < nColCnt; ++i) {
  33.             printf("%s=%s\t", sqlite3_column_name(st, i), sqlite3_column_text(st, i));
  34.         }
  35.         printf("\n");
  36.     }
  37.     if (nErrNr != SQLITE_DONE) {
  38.         pErr = sqlite3_errmsg(db);
  39.         printf("%s\n", pErr);
  40.     }
  41.     nErrNr = sqlite3_finalize(st);
  42.     sqlite3_close(db);
  43.     system("pause");
  44.     return 0;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top