//Bin mir grad nich sicher, ob es diese Header waren:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <stdio.h>
#include <sqlite3.h>
class SQLITE3 {
private:
sqlite3 *db;
char *zErrMsg;
char **result;
int rc;
int nrow,ncol;
public:
std::vector<std::string> vcol_head;
std::vector<std::string> vdata;
int db_open;
SQLITE3 (): zErrMsg(0), rc(0),db_open(0)
{
db_open = 0;
}
void init(std::string tablename="init.db")
{
if (!ExistFile(tablename))
{
std:

fstream out; out.open(tablename.c_str()); out.close();
}
rc = sqlite3_open(tablename.c_str(), &db);
if( rc )
{
fprintf(stderr, "Can't open database: %sn", sqlite3_errmsg(db));
sqlite3_close(db);
}
db_open=1;
}
void close()
{
sqlite3_close(db);
db_open=0;
}
int exe(std::string s_exe)
{
rc = sqlite3_get_table(
db, /* An open database */
s_exe.c_str(), /* SQL to be executed */
&result, /* Result written to a char *[] that this points to */
&nrow, /* Number of result rows written here */
&ncol, /* Number of result columns written here */
&zErrMsg /* Error msg written here */);
if(vcol_head.size()<0) vcol_head.clear();
if(vdata.size()<0) vdata.clear();
if( rc == SQLITE_OK )
{
for(int i=0; i < ncol; ++i)
vcol_head.push_back(result
); /* First row heading */
for(int i=0; i < ncol*nrow; ++i)
if (result[ncol+i]!=NULL) vdata.push_back(result[ncol+i]);
else vdata.push_back("");
} else if (rc != 0 && rc != 1) std::cout << "Error no.: " << rc << std::endl;
sqlite3_free_table(result);
return rc;
}
~SQLITE3()
{
sqlite3_close(db);
}
};
SQLITE3 sql;
int sql_close_if_open()
{
if (sql.db_open) sql.close();
return sql.db_open;
}
void sql_exe(std::string cmd)
{
sql.vcol_head.clear();
sql.vdata.clear();
sql.exe(cmd);
}
void sql_exe(std::string cmd, std::vector<std::string> *header, std::vector<std::string> *Data)
{
sql.vcol_head.clear();
sql.vdata.clear();
sql.exe(cmd);
*header = sql.vcol_head;
*Data = sql.vdata;
}