-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using sqlite3cc lib from https://conan.io/source/SQLite3cc/0.1.1/mons…
- Loading branch information
Showing
4 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
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
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
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...>; | ||
} | ||
} |
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
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
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() |