Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jgsogo committed Dec 4, 2016
1 parent 1a12c47 commit f6e2723
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class QuerysetCPP(ConanFile):
name = "queryset-cpp"
version = "0.4"
requires = "Boost/1.60.0@lasote/stable", "spdlog/0.9.0@memsharded/stable"
requires = "Boost/1.60.0@lasote/stable", "spdlog/0.9.0@memsharded/stable", "SQLite3cc/0.1.1@monsdar/testing"
generators = "cmake"
settings = "os", "compiler", "build_type", "arch"
exports = "conanfile.py", "CMakeLists.txt", "queryset/*" , "tests/*"
Expand Down
36 changes: 36 additions & 0 deletions queryset/backends/sqlite3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

#pragma once

#include <sqlite3.h>
#include "../datasource.h"

namespace qs {
namespace _impl {

template <typename Type, typename... Args>
class Sqlite3Queryset : public _impl::ImplDataSource<Type, Args...> {
public:
Sqlite3Queryset(sqlite3 *db, const std::string& table_name) : _db(db), _table_name(table_name){}
Sqlite3Queryset(const Sqlite3Queryset& other) : _db(other._db), _table_name(other._table_name), _impl::ImplDataSource<Type, Args...>(other) {}
virtual ~Sqlite3Queryset() {}

virtual qs_type apply(const _impl::FilterContainer<Type, Args...>& filters) const {
qs_type ret;
return ret;
}

protected:
sqlite3 *_db;
const std::string _table_name;
};

}

namespace backends {
template <typename... Args>
using Sqlite3Queryset = _impl::Sqlite3Queryset<void, Args...>;

template <typename Type, typename... Args>
using TypedSqlite3Queryset = _impl::Sqlite3Queryset<Type, Args...>;
}
}
1 change: 1 addition & 0 deletions tests/backends/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_executable (test_backends ../print_helper.hpp
${_TESTS})
target_link_libraries (test_backends
${Boost_LIBRARIES}
${CONAN_LIBS_SQLITE3CC}
Threads::Threads
)
set_target_properties(test_backends PROPERTIES FOLDER tests)
Expand Down
81 changes: 81 additions & 0 deletions tests/backends/test_sqlite3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>

#include "../print_helper.hpp"
#include "../../queryset/backends/sqlite3.h"
#include "../config_tests.h"

namespace fs = boost::filesystem;

typedef qs::backends::Sqlite3Queryset<int, std::string, float> myQuerySet;
typedef myQuerySet::qs_type::value_type mytuple;


struct Fixture {
Fixture() {
database = fs::temp_directory_path() / fs::unique_path();
/*
int rc = sqlite3_open(database.string().c_str(), &db);
std::string sql = "CREATE TABLE " + table_name + "(" \
"ID INT PRIMARY KEY NOT NULL," \
"NAME TEXT NOT NULL," \
"SALARY REAL);";
char *zErrMsg = 0;
rc = sqlite3_exec(db, sql.c_str(), callback, 0, &zErrMsg);
if (rc != SQLITE_OK) {
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
else {
fprintf(stderr, "Opened database successfully\n");
}
// Create SQL statement
sql = "INSERT INTO " + table_name + " (ID,NAME,SALARY) " \
"VALUES (1, 'Paul', 20000.00 ); " \
"INSERT INTO " + table_name + " (ID,NAME,SALARY) " \
"VALUES (2, 'Allen', 15000.00 ); " \
"INSERT INTO " + table_name + " (ID,NAME,SALARY)" \
"VALUES (3, 'Teddy', 20000.00 );" \
"INSERT INTO " + table_name + " (ID,NAME,SALARY)" \
"VALUES (4, 'Mark', 65000.00 );";
// Execute SQL statement
rc = sqlite3_exec(db, sql.c_str(), callback, 0, &zErrMsg);
if (rc != SQLITE_OK) {
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
else {
fprintf(stdout, "Records created successfully\n");
}
*/
}

~Fixture() {
//sqlite3_close(db);
//boost::filesystem::remove(database);
}

//sqlite3 *db;
const std::string table_name = "COMPANY";
fs::path database;
};

BOOST_FIXTURE_TEST_SUITE(backends_sqlite3, Fixture)

BOOST_AUTO_TEST_CASE(basic)
{
/*
myQuerySet backend(db, table_name);
qs::FilterContainer<int, std::string, float> filters;
auto qs = backend.apply(filters);
BOOST_CHECK_EQUAL(qs.size(), 3);
*/
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit f6e2723

Please sign in to comment.