add sqllite test
+101 · 4 files changed
-
graph/db/Makefile+55 −0 -
graph/db/sqltestbinary -
graph/db/sqltest.c+46 −0 -
graph/db/sqltest.obinary
@@ -0,0 +1,55 @@ +# Unix makefile for a C program. Set BinName to program name. + +# Definitions. +BinName = sqltest +Libs = -lc -lsqlite3 + +# Options and arguments to the C compiler. +CC = clang +#CFLAGS = -g -funsigned-char -W -Wall -ggdb3 -Wunused\ +# -Wno-comment -Wno-missing-field-initializers -Wno-missing-braces -Wno-parentheses\ +# -Wno-pointer-sign -Wno-unused-parameter -Wno-unused-result $(COPTS)\ +# -Og +CFLAGS = -g \ +-Og \ +-Wall \ +-Werror \ +-Wextra \ +-Wno-comment \ +-Wno-missing-field-initializers \ +-Wno-missing-braces \ +-Wno-unused \ +-Wundef \ +-Wmissing-include-dirs \ +-Wmissing-declarations \ +-Wmissing-prototypes \ +-Wstrict-selector-match \ +-Wundeclared-selector \ +-Woverlength-strings \ +-Wimplicit-atomic-properties \ +-Wformat=2 \ +-Wno-parentheses \ +-Wcast-align \ +-Wcast-qual \ +-Wfloat-equal \ +-Wdisabled-optimization \ +-Winit-self \ +-Wredundant-decls \ +-Wshadow \ +-Wsign-conversion \ +-Wstrict-overflow=5 \ +-Wstrict-prototypes \ +-Wswitch-default \ +-Wunreachable-code \ + + +# Targets. +$(BinName): $(BinName).o + $(CC) $(LDFLAGS) $? $(Libs) -o $(BinName) +#strip $(BinName) + +$(BinName).o: $(BinName).c + $(CC) $(CFLAGS) -c -o $(BinName).o $? + +clean: + rm -f $(BinName) $(BinName).o Binary files /dev/null and b/graph/db/sqltest differ @@ -0,0 +1,46 @@ +#include <sqlite3.h> +#include <stdio.h> + +int main(void) { + + sqlite3 *db; + sqlite3_stmt *stmt; + + //1. initiate database connection + + int rc = sqlite3_open(":memory:",&db); + + if (rc != SQLITE_OK) { + fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); + sqlite3_close(db); + + return 1; + } + // 2. routines , db, zsql - statements to be compiled, nByte - negative read up to /0 ter + // mination + // If nByte is positive, then it is the number of bytes read from zSql. + // If nByte is zero, then no prepared statement is generated. + // If the caller knows that the supplied string is nul-terminated, then there + // is a small performance advantage to passing an nByte parameter that + // is the number of bytes in the input string including the nul-terminator. + rc = sqlite3_prepare_v2(db,"SELECT SQLITE_VERSION()",-1,&stmt, 0); + // the sqlite3_prepare() family of routines return SQLITE_OK; otherwise an error code is returned. + if (rc != SQLITE_OK){ + fprintf(stderr, "Fail to fetch data: %s\n", sqlite3_errmsg(db)); + sqlite3_close(db); + + return 1; + } + + // 3 + rc = sqlite3_step(stmt); + if (rc == SQLITE_ROW) { + fprintf(stdout, "%s\n",sqlite3_column_text(stmt, 0)); + } + + sqlite3_finalize(stmt); + sqlite3_close(db); + + + return 0; +} Binary files /dev/null and b/graph/db/sqltest.o differ