SHARE
TWEET

4

a guest May 22nd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include "../../common/sqlite-amalgamation-3220000/sqlite3.h"
  3. #include <stdio.h>
  4. #include <malloc.h>
  5.  
  6. int main(void) {
  7.     int rc;
  8.     sqlite3* db;
  9.     FILE* f;
  10.     size_t nFileSize;
  11.     char* pFile;
  12.     sqlite3_stmt *st;
  13.     const char* pFilePos;
  14.     const char* pFileEnd;
  15.     size_t nColCnt;
  16.     f = fopen("SCRIPT.SQL", "rb");
  17.     nFileSize = ftell(f);
  18.     pFile = malloc(nFileSize);
  19.     fseek(f, 0, SEEK_END);
  20.     fread(pFile, nFileSize, 1, f);
  21.     fclose(f);
  22.     rc = sqlite3_open("MYDB", &db);
  23.     pFilePos = pFile;
  24.     pFileEnd = pFilePos + nFileSize;
  25.     while (pFilePos < pFileEnd) {
  26.         rc = sqlite3_prepare(db, pFilePos, pFileEnd - pFilePos, &st, &pFilePos);
  27.         nColCnt = sqlite3_column_count(st);
  28.         if (!st) {
  29.             break;
  30.         }
  31.         while ((rc = sqlite3_step(st)) == SQLITE_ROW) {
  32.             for (int i = 0; i < nColCnt; ++i) {
  33.                 if (i) {
  34.                     printf("\t");
  35.                     printf("%s = %s", sqlite3_column_name(st, i), sqlite3_column_text(st, i));
  36.                 }
  37.                 printf("\n");
  38.             }
  39.         }
  40.         if (rc != SQLITE_DONE) {
  41.             __debugbreak();
  42.         }
  43.         rc = sqlite3_finalize(st);
  44.     }
  45.     rc = sqlite3_close(db);
  46.     free(pFile);
  47.     return 0;
  48. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top