Created
December 15, 2013 21:12
-
-
Save kgadek/7978182 to your computer and use it in GitHub Desktop.
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
[ 20%] Building CXX object CMakeFiles/daemon.dir/src/sqlite.cpp.o | |
In file included from /home/konrad/lachesis/cpp/src/sqlite.cpp:1: | |
In file included from /home/konrad/lachesis/cpp/src/sqlite.hpp:7: | |
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/memory:81: | |
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/unique_ptr.h:137:9: error: static_assert failed "constructed with null function pointer deleter" | |
{ static_assert(!is_pointer<deleter_type>::value, | |
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
/home/konrad/lachesis/cpp/src/sqlite.cpp:32:20: note: in instantiation of member function 'std::unique_ptr<sqlite3, int (*)(sqlite3 *)>::unique_ptr' requested here | |
LachesisSQLite3db::LachesisSQLite3db(const char *db_path) throw(sqlExecException) { | |
^ | |
In file included from /home/konrad/lachesis/cpp/src/sqlite.cpp:1: | |
In file included from /home/konrad/lachesis/cpp/src/sqlite.hpp:7: | |
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/memory:81: | |
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/unique_ptr.h:137:9: error: static_assert failed "constructed with null function pointer deleter" | |
{ static_assert(!is_pointer<deleter_type>::value, | |
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
/home/konrad/lachesis/cpp/src/sqlite.cpp:32:20: note: in instantiation of member function 'std::unique_ptr<sqlite3_stmt, int (*)(sqlite3_stmt *)>::unique_ptr' requested here | |
LachesisSQLite3db::LachesisSQLite3db(const char *db_path) throw(sqlExecException) { | |
^ | |
/home/konrad/lachesis/cpp/src/sqlite.cpp:37:11: error: no matching constructor for initialization of 'std::unique_ptr<std::unique_ptr<sqlite3, decltype(&sqlite3_close)> >' | |
_db = std::unique_ptr<std::unique_ptr<sqlite3, decltype(&sqlite3_close)>> (db, &sqlite3_close); | |
^ ~~~~~~~~~~~~~~~~~~ | |
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/unique_ptr.h:146:7: note: candidate constructor not viable: cannot convert argument of incomplete type 'sqlite3 *' to | |
'pointer' (aka 'std::unique_ptr<sqlite3, int (*)(sqlite3 *)> *') | |
unique_ptr(pointer __p, | |
^ | |
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/unique_ptr.h:151:7: note: candidate constructor not viable: cannot convert argument of incomplete type 'sqlite3 *' to | |
'pointer' (aka 'std::unique_ptr<sqlite3, int (*)(sqlite3 *)> *') | |
unique_ptr(pointer __p, | |
^ | |
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/unique_ptr.h:169:2: note: candidate constructor template not viable: requires single argument '__u', but 2 arguments | |
were provided | |
unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept | |
^ | |
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/unique_ptr.h:176:2: note: candidate constructor template not viable: requires single argument '__u', but 2 arguments | |
were provided | |
unique_ptr(auto_ptr<_Up>&& __u) noexcept; | |
^ | |
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/unique_ptr.h:135:17: note: candidate constructor not viable: requires 0 arguments, but 2 were provided | |
constexpr unique_ptr() noexcept | |
^ | |
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/unique_ptr.h:141:7: note: candidate constructor not viable: requires single argument '__p', but 2 arguments were | |
provided | |
unique_ptr(pointer __p) noexcept | |
^ | |
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/unique_ptr.h:157:17: note: candidate constructor not viable: requires 1 argument, but 2 were provided | |
constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { } | |
^ | |
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/unique_ptr.h:160:7: note: candidate constructor not viable: requires single argument '__u', but 2 arguments were | |
provided | |
unique_ptr(unique_ptr&& __u) noexcept | |
^ | |
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/unique_ptr.h:273:7: note: candidate constructor not viable: requires 1 argument, but 2 were provided | |
unique_ptr(const unique_ptr&) = delete; | |
^ | |
3 errors generated. | |
make[2]: *** [CMakeFiles/daemon.dir/src/sqlite.cpp.o] Błąd 1 | |
make[1]: *** [CMakeFiles/daemon.dir/all] Błąd 2 | |
make: *** [all] Błąd 2 |
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
/home/konrad/lachesis/cpp/src/sqlite.cpp: In constructor ‘LachesisSQLite3db::sqlExecException::sqlExecException(const char*, char*)’: | |
/home/konrad/lachesis/cpp/src/sqlite.cpp:23:1: warning: ‘LachesisSQLite3db::sqlExecException::_what_msg’ should be initialized in the member initialization list [-Weffc++] | |
LachesisSQLite3db::sqlExecException::sqlExecException(const char *msgA, char *msgB) : _msgA(msgA), _msgB(msgB) { | |
^ | |
/home/konrad/lachesis/cpp/src/sqlite.cpp: In constructor ‘LachesisSQLite3db::LachesisSQLite3db(const char*)’: | |
/home/konrad/lachesis/cpp/src/sqlite.cpp:32:1: warning: ‘LachesisSQLite3db::_db’ should be initialized in the member initialization list [-Weffc++] | |
LachesisSQLite3db::LachesisSQLite3db(const char *db_path) throw(sqlExecException) { | |
^ | |
In file included from /usr/include/c++/4.8.2/memory:81:0, | |
from /home/konrad/lachesis/cpp/src/sqlite.hpp:7, | |
from /home/konrad/lachesis/cpp/src/sqlite.cpp:1: | |
/usr/include/c++/4.8.2/bits/unique_ptr.h: In instantiation of ‘constexpr std::unique_ptr<_Tp, _Dp>::unique_ptr() [with _Tp = sqlite3; _Dp = int (*)(sqlite3*)]’: | |
/home/konrad/lachesis/cpp/src/sqlite.cpp:32:81: required from here | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:137:9: error: static assertion failed: constructed with null function pointer deleter | |
{ static_assert(!is_pointer<deleter_type>::value, | |
^ | |
/home/konrad/lachesis/cpp/src/sqlite.cpp:32:1: warning: ‘LachesisSQLite3db::_insertStmt’ should be initialized in the member initialization list [-Weffc++] | |
LachesisSQLite3db::LachesisSQLite3db(const char *db_path) throw(sqlExecException) { | |
^ | |
In file included from /usr/include/c++/4.8.2/memory:81:0, | |
from /home/konrad/lachesis/cpp/src/sqlite.hpp:7, | |
from /home/konrad/lachesis/cpp/src/sqlite.cpp:1: | |
/usr/include/c++/4.8.2/bits/unique_ptr.h: In instantiation of ‘constexpr std::unique_ptr<_Tp, _Dp>::unique_ptr() [with _Tp = sqlite3_stmt; _Dp = int (*)(sqlite3_stmt*)]’: | |
/home/konrad/lachesis/cpp/src/sqlite.cpp:32:81: required from here | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:137:9: error: static assertion failed: constructed with null function pointer deleter | |
{ static_assert(!is_pointer<deleter_type>::value, | |
^ | |
/home/konrad/lachesis/cpp/src/sqlite.cpp:37:98: error: no matching function for call to ‘std::unique_ptr<std::unique_ptr<sqlite3, int (*)(sqlite3*)> >::unique_ptr(sqlite3*&, int (*)(sqlite3*))’ | |
_db = std::unique_ptr<std::unique_ptr<sqlite3, decltype(&sqlite3_close)>> (db, &sqlite3_close); | |
^ | |
/home/konrad/lachesis/cpp/src/sqlite.cpp:37:98: note: candidates are: | |
In file included from /usr/include/c++/4.8.2/memory:81:0, | |
from /home/konrad/lachesis/cpp/src/sqlite.hpp:7, | |
from /home/konrad/lachesis/cpp/src/sqlite.cpp:1: | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:176:2: note: template<class _Up, class> std::unique_ptr<_Tp, _Dp>::unique_ptr(std::auto_ptr<_Up>&&) | |
unique_ptr(auto_ptr<_Up>&& __u) noexcept; | |
^ | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:176:2: note: template argument deduction/substitution failed: | |
/home/konrad/lachesis/cpp/src/sqlite.cpp:37:98: note: mismatched types ‘std::auto_ptr<_Up>’ and ‘sqlite3*’ | |
_db = std::unique_ptr<std::unique_ptr<sqlite3, decltype(&sqlite3_close)>> (db, &sqlite3_close); | |
^ | |
In file included from /usr/include/c++/4.8.2/memory:81:0, | |
from /home/konrad/lachesis/cpp/src/sqlite.hpp:7, | |
from /home/konrad/lachesis/cpp/src/sqlite.cpp:1: | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:169:2: note: template<class _Up, class _Ep, class> std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Up, _Ep>&&) | |
unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept | |
^ | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:169:2: note: template argument deduction/substitution failed: | |
/home/konrad/lachesis/cpp/src/sqlite.cpp:37:98: note: mismatched types ‘std::unique_ptr<_Tp, _Dp>’ and ‘sqlite3*’ | |
_db = std::unique_ptr<std::unique_ptr<sqlite3, decltype(&sqlite3_close)>> (db, &sqlite3_close); | |
^ | |
In file included from /usr/include/c++/4.8.2/memory:81:0, | |
from /home/konrad/lachesis/cpp/src/sqlite.hpp:7, | |
from /home/konrad/lachesis/cpp/src/sqlite.cpp:1: | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:160:7: note: std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Tp, _Dp>&&) [with _Tp = std::unique_ptr<sqlite3, int (*)(sqlite3*)>; _Dp = std::default_delete<std::unique_ptr<sqlite3, int (*)(sqlite3*)> >] | |
unique_ptr(unique_ptr&& __u) noexcept | |
^ | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:160:7: note: candidate expects 1 argument, 2 provided | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:157:17: note: constexpr std::unique_ptr<_Tp, _Dp>::unique_ptr(std::nullptr_t) [with _Tp = std::unique_ptr<sqlite3, int (*)(sqlite3*)>; _Dp = std::default_delete<std::unique_ptr<sqlite3, int (*)(sqlite3*)> >; std::nullptr_t = std::nullptr_t] | |
constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { } | |
^ | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:157:17: note: candidate expects 1 argument, 2 provided | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:151:7: note: std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Tp, _Dp>::pointer, typename std::remove_reference<_To>::type&&) [with _Tp = std::unique_ptr<sqlite3, int (*)(sqlite3*)>; _Dp = std::default_delete<std::unique_ptr<sqlite3, int (*)(sqlite3*)> >; std::unique_ptr<_Tp, _Dp>::pointer = std::unique_ptr<sqlite3, int (*)(sqlite3*)>*; typename std::remove_reference<_To>::type = std::default_delete<std::unique_ptr<sqlite3, int (*)(sqlite3*)> >] | |
unique_ptr(pointer __p, | |
^ | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:151:7: note: no known conversion for argument 1 from ‘sqlite3*’ to ‘std::unique_ptr<std::unique_ptr<sqlite3, int (*)(sqlite3*)> >::pointer {aka std::unique_ptr<sqlite3, int (*)(sqlite3*)>*}’ | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:146:7: note: std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Tp, _Dp>::pointer, typename std::conditional<std::is_reference<_Dp>::value, _Dp, const _Dp&>::type) [with _Tp = std::unique_ptr<sqlite3, int (*)(sqlite3*)>; _Dp = std::default_delete<std::unique_ptr<sqlite3, int (*)(sqlite3*)> >; std::unique_ptr<_Tp, _Dp>::pointer = std::unique_ptr<sqlite3, int (*)(sqlite3*)>*; typename std::conditional<std::is_reference<_Dp>::value, _Dp, const _Dp&>::type = const std::default_delete<std::unique_ptr<sqlite3, int (*)(sqlite3*)> >&] | |
unique_ptr(pointer __p, | |
^ | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:146:7: note: no known conversion for argument 1 from ‘sqlite3*’ to ‘std::unique_ptr<std::unique_ptr<sqlite3, int (*)(sqlite3*)> >::pointer {aka std::unique_ptr<sqlite3, int (*)(sqlite3*)>*}’ | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:141:7: note: std::unique_ptr<_Tp, _Dp>::unique_ptr(std::unique_ptr<_Tp, _Dp>::pointer) [with _Tp = std::unique_ptr<sqlite3, int (*)(sqlite3*)>; _Dp = std::default_delete<std::unique_ptr<sqlite3, int (*)(sqlite3*)> >; std::unique_ptr<_Tp, _Dp>::pointer = std::unique_ptr<sqlite3, int (*)(sqlite3*)>*] | |
unique_ptr(pointer __p) noexcept | |
^ | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:141:7: note: candidate expects 1 argument, 2 provided | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:135:17: note: constexpr std::unique_ptr<_Tp, _Dp>::unique_ptr() [with _Tp = std::unique_ptr<sqlite3, int (*)(sqlite3*)>; _Dp = std::default_delete<std::unique_ptr<sqlite3, int (*)(sqlite3*)> >] | |
constexpr unique_ptr() noexcept | |
^ | |
/usr/include/c++/4.8.2/bits/unique_ptr.h:135:17: note: candidate expects 0 arguments, 2 provided | |
make[2]: *** [CMakeFiles/daemon.dir/src/sqlite.cpp.o] Błąd 1 | |
make[1]: *** [CMakeFiles/daemon.dir/all] Błąd 2 | |
make: *** [all] Błąd 2 |
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
#include "sqlite.hpp" | |
#include <sstream> | |
#include <iostream> | |
using std::ostringstream; | |
int LachesisSQLite3db::exec(const char* sql) { | |
char *zErrMsg = 0; | |
int conn = sqlite3_exec(_db.get(), sql, nullptr, 0, &zErrMsg); | |
if(conn != SQLITE_OK) { | |
// odpowiedzialność za zwolnienie zErrMsg przekazana do sqlExecExeception | |
throw new sqlExecException("LachesisSQLite3db exec error! :(", zErrMsg); | |
} | |
return conn; | |
} | |
const char* LachesisSQLite3db::sqlExecException::what() const throw() { | |
return _what_msg.c_str(); | |
} | |
LachesisSQLite3db::sqlExecException::sqlExecException(const char *msgA, char *msgB) : _msgA(msgA), _msgB(msgB) { | |
if(msgB) { | |
sqlite3_free(msgB); | |
} | |
ostringstream ss; | |
ss << "SQLite3.exec exception: " << _msgA << "\n" << _msgB; | |
_what_msg = ss.str(); | |
} | |
LachesisSQLite3db::LachesisSQLite3db(const char *db_path) throw(sqlExecException) { | |
sqlite3 *db; | |
if( sqlite3_open(db_path, &db) ) { | |
throw new sqlExecException("LachesisSQLite3db open error! :(", nullptr); | |
} | |
_db = std::unique_ptr<std::unique_ptr<sqlite3, decltype(&sqlite3_close)>> (db, &sqlite3_close); | |
exec( | |
"create table if not exists lachesis(" | |
"id integer not null unique primary key autoincrement," | |
"timestamp text constraint time_default default (strftime('%Y-%m-%d %H:%M:%f'))," | |
"key text," | |
"value text" | |
");" | |
); | |
exec( | |
"create index if not exists lachesis_timestamp_idx on lachesis(timestamp desc);" | |
); | |
sqlite3_stmt *insertStmt; | |
if( sqlite3_prepare_v2(_db.get(), "insert into lachesis(key,value) values (?, ?)", -1, &insertStmt, nullptr) ) { | |
throw new sqlExecException("LachesisSQLite3db exec error! :(", nullptr); | |
} | |
_insertStmt.reset(insertStmt); | |
} | |
void LachesisSQLite3db::store(const char *key, const char *value) { | |
sqlite3_bind_text(_insertStmt.get(), 1, key, -1, SQLITE_STATIC); | |
sqlite3_bind_text(_insertStmt.get(), 2, value, -1, SQLITE_STATIC); | |
sqlite3_step(_insertStmt.get()); // silently drop data on errors | |
sqlite3_reset(_insertStmt.get()); | |
} |
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
#ifndef LACHESIS_SQLITE_HPP | |
#define LACHESIS_SQLITE_HPP | |
#include <exception> | |
#include <sqlite3.h> | |
#include <string> | |
#include <memory> | |
class LachesisSQLite3db { | |
std::unique_ptr<sqlite3, decltype(&sqlite3_close)> _db; | |
std::unique_ptr<sqlite3_stmt, decltype(&sqlite3_finalize)> _insertStmt; | |
int exec(const char* sql); | |
public: | |
class sqlExecException : public std::exception { | |
std::string _msgA, _msgB; | |
std::string _what_msg; | |
virtual const char* what() const throw(); | |
public: | |
sqlExecException(const char *msgA, char *msgB); | |
}; | |
LachesisSQLite3db(const char *db_path) throw(sqlExecException); | |
~LachesisSQLite3db() throw(); | |
void store(const char *key, const char *value); | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment