101 errors

This commit is contained in:
malloc 2018-05-03 11:06:32 -05:00
parent ff7338d9d4
commit d423a805b9
4 changed files with 75 additions and 11 deletions

View file

@ -18,7 +18,7 @@ void sosc::db::init_databases() {
sqlite3_open("scape.db", &_ctx.hard_db);
db::Query query("SELECT * FROM MIGRATIONS ORDER BY ID ASC");
auto results = query.GetResults();
while()
//while()
_ctx.ready = true;
}
@ -64,6 +64,39 @@ void sosc::db::Query::SetQuery(const std::string &query, int db) {
this->open = true;
}
void sosc::db::Query::Bind<double>(double value, int i) {
sqlite3_bind_double(this->statement, i, value);
}
void sosc::db::Query::Bind<int32_t>(int32_t value, int i) {
sqlite3_bind_int(this->statement, i, value);
}
void sosc::db::Query::Bind<int64_t>(int64_t value, int i) {
sqlite3_bind_int64(this->statement, i, value);
}
void sosc::db::Query::Bind<sosc::time>(sosc::time value, int i) {
sqlite3_bind_int64(this->statement, i, clk::to_unix_time(value));
}
void sosc::db::Query::Bind<std::string>
(const std::string& value, int i, int type)
{
if(type == DB_COL_TEXT)
sqlite3_bind_text(
this->statement, i,
value.c_str(), -1,
SQLITE_TRANSIENT
);
else
sqlite3_bind_blob(
this->statement, i,
value.c_str(), value.length(),
SQLITE_TRANSIENT
);
}
void sosc::db::Query::NonQuery() {
if(!_ctx.ready || !this->open)
return;

View file

@ -34,11 +34,13 @@ private:
friend class Query;
};
/*double ResultSet::Get<double>(int column);
int32_t ResultSet::Get<int32_t>(int column);
int64_t ResultSet::Get<int64_t>(int column);
sosc::time ResultSet::Get<sosc::time>(int column);
std::string ResultSet::Get<std::string>(int column, int type = DB_COL_TEXT);*/
/*
template<> double ResultSet::Get<double>(int column);
template<> int32_t ResultSet::Get<int32_t>(int column);
template<> int64_t ResultSet::Get<int64_t>(int column);
template<> sosc::time ResultSet::Get<sosc::time>(int column);
template<> std::string ResultSet::Get<std::string>(int column, int type);
*/
class Query {
public:
@ -46,6 +48,11 @@ public:
Query(const std::string& query, int db = DB_USE_HARD);
void SetQuery(const std::string& query, int db = DB_USE_HARD);
template<typename T>
void Bind(T value, int i);
template<typename T>
void Bind(const T& value, int i, int type);
void NonQuery();
template<typename T>
@ -69,11 +76,20 @@ private:
friend class ResultSet;
};
/*double Query::Scalar<double>();
int32_t Query::Scalar<int32_t>();
int64_t Query::Scalar<int64_t>();
sosc::time Query::Scalar<sosc::time>();
std::string Query::Scalar<std::string>(int type = DB_COL_TEXT);*/
/*
template<> void Query::Bind<double>(double value, int i);
template<> void Query::Bind<int32_t>(int32_t value, int i);
template<> void Query::Bind<int64_t>(int64_t value, int i);
template<> void Query::Bind<sosc::time>(sosc::time value, int i);
template<> std::string Query::Bind<std::string>
(const std::string& value, int i, int type);
template<> double Query::Scalar<double>();
template<> int32_t Query::Scalar<int32_t>();
template<> int64_t Query::Scalar<int64_t>();
template<> sosc::time Query::Scalar<sosc::time>();
template<> std::string Query::Scalar<std::string>(int type);
*/
// THE FOLLOWING ARE NOT THREAD SAFE !!
// CALL THEM ONLY WHEN MASTER POOL IS INACTIVE

View file

@ -12,6 +12,20 @@ sosc::time sosc::clk::from_unix_time(uint64_t unix) {
+ std::chrono::seconds(unix);
}
uint64_t sosc::clk::to_unix_time(sosc::time time) {
std::tm raw = std::tm();
raw.tm_year = 70;
raw.tm_yday = 0;
raw.tm_hour = 0;
raw.tm_min = 0;
raw.tm_sec = 0;
sosc::time epoch = sosc::clock::from_time_t(mktime(&raw));
return (uint64_t)
std::chrono::duration_cast
<std::chrono::seconds>(time - epoch).count();
}
std::tm sosc::clk::to_utc(sosc::time time) {
time_t ctime = sosc::clock::to_time_t(time);
return to_utc(&ctime);

View file

@ -15,6 +15,7 @@ typedef std::chrono::time_point<sosc::clock> time;
namespace clk {
sosc::time from_unix_time(uint64_t unix);
uint64_t to_unix_time(sosc::time time);
std::tm to_utc(sosc::time time);
std::tm to_utc(const time_t* time);