[odb-users] SQLite not creating table?

Rafal Gm grasmanek94 at gmail.com
Fri Jul 5 03:12:06 EDT 2013


Well after I switched from MySQL to SQlite at my surprise there was no
generated .sql file to be used when the following command is issued:

odb -d sqlite -I../Database/libodb-2.2.3 --std c++11 --generate-schema
--generate-query "C:/path_to_file/classes/user.hxx", it generates the
user-odb hxx and cxx files which I include and compile with my project,
then I use this code:

namespace Database
{
odb::sqlite::database * users/* ("accounts.db")*/ = NULL;
};
#define REPORT_ERROR_IF_ANY(e)
Report_Error(e.what(),__FILE__,__FUNCTION__,__LINE__)

void Report_Error(std::string error,std::string file,std::string
function,int line)
{
ServerLog::Printf("Exception ('%s') in
%s::%s::%d",error.c_str(),file.c_str(),function.c_str(),line);
return;
}

main()
{
if(!Database::users)
{
Database::users = new odb::sqlite::database("accounts.db",
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
}
if(Database::users)
{
try
{
user server("SERVER","X",0,0,0,0,0,0,0,0,0);
odb::transaction t (Database::users->begin ());

Database::users->persist (server);

typedef odb::query<user> user_query;

for (user& u: Database::users->query<user> (user_query::nickname ==
"SERVER"))
std::cout << u.nickname().c_str() << std::endl;

server.admin(1337);
Database::users->update (server);

t.commit ();
}
catch(odb::exception &e)
{
REPORT_ERROR_IF_ANY(e);
}
return true;
}

and when I execute this code it give me this:

[08:58:12] Exception ('1: no such table: user') in
exe24.cpp::OnGameModeInit::138

What am I doing wrong?

My user.hxx is this [quite simple file because I'm not that advanced with
ODB :( ]:

#ifdef EXE24_EXPORTS
#pragma once
#endif

#include <string>
#include <vector>
#include <tuple>

#include <odb/core.hxx>

#define acmf(variable_name,variable_type) \
const variable_type& variable_name () const \
{ \
return variable_name ## _; \
} \
void variable_name (variable_type variable_name) \
{ \
variable_name ## _ = variable_name; \
}

#define accessor(variable_name,variable_type) \
const variable_type& variable_name () const \
{ \
return variable_name ## _; \
}

#pragma db value
struct ban_type
{
  std::string reason;
  unsigned long long date_end;
  std::string by_who;
  unsigned long long date_when;
};

#pragma db object
class user
{
public:
user () {}
user
(
std::string nickname,
std::string password,
unsigned long long register_date,
unsigned int kills,
unsigned int deaths,
unsigned int joins,
unsigned int disconnects,
unsigned int kicks,
unsigned long long experience,
unsigned long long admin,
unsigned long long banned
):
nickname_(nickname),
password_(password),
register_date_(register_date),
kills_(kills),
deaths_(deaths),
joins_(joins),
disconnects_(disconnects),
kicks_(kicks),
experience_(experience),
admin_(admin),
banned_(banned)
{

}
// Standard accessor/modifier names. Auto-discovered by ODB.
//
acmf(nickname,std::string);
acmf(password,std::string);
acmf(register_date,unsigned long long);
acmf(kills,unsigned int);
acmf(deaths,unsigned int);
acmf(joins,unsigned int);
acmf(disconnects,unsigned int);
acmf(kicks,unsigned int);
acmf(experience,unsigned long long);
acmf(admin,unsigned long long);
acmf(banned,unsigned long long);

accessor(id,unsigned long);
 // bans.
// v<t<reason,how_long,by_who,when>>
/*typedef std::tuple<std::string,
unsigned long long,
std::string,
unsigned long long> ban_type;
#pragma db value(ban_type) transient
#pragma db member(ban_type::reason) virtual(std::string) access(std::get<0>
(this))
#pragma db member(ban_type::date_end) virtual(unsigned long long)
access(std::get<1> (this))
#pragma db member(ban_type::by_who) virtual(std::string) access(std::get<2>
(this))
#pragma db member(ban_type::date_when) virtual(unsigned long long)
access(std::get<3> (this))*/

typedef std::vector<ban_type> bans_type;

acmf(bans,bans_type);

private:
friend class odb::access;

#pragma db id auto
unsigned long id_;

std::string nickname_;
std::string password_;
unsigned long long register_date_;
unsigned int kills_;
unsigned int deaths_;
unsigned int joins_;
unsigned int disconnects_;
unsigned int kicks_;
unsigned long long experience_;
unsigned long long admin_;
unsigned long long banned_;

bans_type bans_;
};

Thanks in advance for help!


More information about the odb-users mailing list