From a9d46ce747016e9c8e5f851ceacfa8661b73a2e1 Mon Sep 17 00:00:00 2001 From: Valentin Rakush Date: Tue, 31 Dec 2019 08:58:47 +0000 Subject: [PATCH] Tess for overload method execute_statement. Usage example --- test/tap/tests/sqlite3-t.cpp | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/tap/tests/sqlite3-t.cpp diff --git a/test/tap/tests/sqlite3-t.cpp b/test/tap/tests/sqlite3-t.cpp new file mode 100644 index 000000000..a6589b0d6 --- /dev/null +++ b/test/tap/tests/sqlite3-t.cpp @@ -0,0 +1,39 @@ +#include +#include "tap.h" +#include +#include +#include +#include "sqlite3db.h" + +int main() { + plan(8); + + SQLite3DB *db; // in memory + db = new SQLite3DB(); + db->open((char *)"file:mem_db?mode=memory&cache=shared", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX); + bool rc=db->check_and_build_table((char*)"test", (char*)"CREATE TABLE TEST (hostname VARCHAR NOT NULL , port INT NOT NULL DEFAULT 3306)"); + ok(rc, "TEST table is created"); + rc=db->execute("INSERT INTO TEST (hostname, port) VALUES ('localhost', 6033)"); + ok(rc, "Row is inserted"); + + // Execute statement and get a result set in std::unique_ptr. will be automatically destroyed later.yy + std::unique_ptr result = std::unique_ptr(db->execute_statement("SELECT * FROM TEST")); + ok(nullptr != result, "Query result is not empty"); + + // Execute statement and gets number of columns and error message (error message should be empty) + int cols=0; + char *error=NULL; + std::unique_ptr result_2 = std::unique_ptr(db->execute_statement("SELECT * FROM TEST", &error, &cols)); + ok(nullptr != result_2, "Query result is not empty"); + ok(cols == 2, "Query returns correct number of columns"); + ok(!error, "No error message expected"); + + // Execute statement and gets number of columns and error message (error message should be empty) + error=NULL; + std::unique_ptr result_3 = std::unique_ptr(db->execute_statement("SELECT * FROM TEST1", &error)); + ok(nullptr == result_3, "Query result is empty"); + ok(error != NULL, "There is an error message expected"); + + return exit_status(); +} +