← cproj

add sqllite test

1261a4c4d17fbc44d606092d2db7edd4a21c9a66 · ovidiucs · Oct 8, 2019 06:32

+101 · 4 files changed

  • graph/db/Makefile +55 −0
  • graph/db/sqltest binary
  • graph/db/sqltest.c +46 −0
  • graph/db/sqltest.o binary
diff --git a/graph/db/Makefile b/graph/db/Makefile
new file mode 100644
index 0000000..796bfa0
--- /dev/null
+++ b/graph/db/Makefile
@@ -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
diff --git a/graph/db/sqltest b/graph/db/sqltest
new file mode 100755
index 0000000..76f5e1a
Binary files /dev/null and b/graph/db/sqltest differ
diff --git a/graph/db/sqltest.c b/graph/db/sqltest.c
new file mode 100644
index 0000000..ac09b6b
--- /dev/null
+++ b/graph/db/sqltest.c
@@ -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;
+}
diff --git a/graph/db/sqltest.o b/graph/db/sqltest.o
new file mode 100644
index 0000000..f74389a
Binary files /dev/null and b/graph/db/sqltest.o differ