Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include "../../common/sqlite-amalgamation-3220000/sqlite3.h"
- #include <stdio.h>
- #include <malloc.h>
- int main(void) {
- int rc;
- sqlite3* db;
- FILE* f;
- size_t nFileSize;
- char* pFile;
- sqlite3_stmt *st;
- const char* pFilePos;
- const char* pFileEnd;
- size_t nColCnt;
- f = fopen("SCRIPT.SQL", "rb");
- nFileSize = ftell(f);
- pFile = malloc(nFileSize);
- fseek(f, 0, SEEK_END);
- fread(pFile, nFileSize, 1, f);
- fclose(f);
- rc = sqlite3_open("MYDB", &db);
- pFilePos = pFile;
- pFileEnd = pFilePos + nFileSize;
- while (pFilePos < pFileEnd) {
- rc = sqlite3_prepare(db, pFilePos, pFileEnd - pFilePos, &st, &pFilePos);
- nColCnt = sqlite3_column_count(st);
- if (!st) {
- break;
- }
- while ((rc = sqlite3_step(st)) == SQLITE_ROW) {
- for (int i = 0; i < nColCnt; ++i) {
- if (i) {
- printf("\t");
- printf("%s = %s", sqlite3_column_name(st, i), sqlite3_column_text(st, i));
- }
- printf("\n");
- }
- }
- if (rc != SQLITE_DONE) {
- __debugbreak();
- }
- rc = sqlite3_finalize(st);
- }
- rc = sqlite3_close(db);
- free(pFile);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement