Created
December 18, 2014 01:48
-
-
Save likejazz/4302a543075e4f6695ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sqlite3.h> | |
static int callback(void *NotUsed, int argc, char **argv, char **azColName) { | |
NotUsed = 0; | |
int i; | |
for (i = 0; i < argc; i++) { | |
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); | |
} | |
printf("\n"); | |
return 0; | |
} | |
int main(int argc, char **argv) { | |
sqlite3 *db; | |
char *zErrMsg = 0; | |
int rc; | |
if (argc != 2) { | |
fprintf(stderr, "Usage: %s DATABASE\n", argv[0]); | |
exit(1); | |
} | |
rc = sqlite3_open(argv[1], &db); | |
if (rc) { | |
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); | |
sqlite3_close(db); | |
exit(1); | |
} | |
rc = sqlite3_exec(db, "SELECT sqlite_version()", callback, 0, &zErrMsg); | |
if (rc != SQLITE_OK) { | |
fprintf(stderr, "SQL error: %s\n", zErrMsg); | |
/* This will free zErrMsg if assigned */ | |
if (zErrMsg) | |
free(zErrMsg); | |
} | |
sqlite3_close(db); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment