ultimatepp/bazaar/Protect/ProtectDB.h
koldo 3718a89f0c Protect: Added SQLITE support
git-svn-id: svn://ultimatepp.org/upp/trunk@4040 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2011-10-17 19:10:47 +00:00

78 lines
1.7 KiB
C++

#ifndef _Protect_ProtectDB_h_
#define _Protect_ProtectDB_h_
#include <Core/Core.h>
#ifndef flagUSE_SQLITE
#include <MySql/MySql.h>
#else
#include <plugin/sqlite3/Sqlite3.h>
#endif
NAMESPACE_UPP
#ifndef flagUSE_SQLITE
#define SCHEMADIALECT <MySql/MySqlSchema.h>
#else
#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
#endif
#define MODEL <Protect/ProtectDB.sch>
#include "Sql/sch_header.h"
// encapsulation of Protect database
class ProtectDB
{
private:
// host, db name, username and password
String host;
String dbName;
String userName;
String password;
// connected flag
bool connected;
// database upgraded flag
bool upgraded;
// database session
#ifndef flagUSE_SQLITE
MySqlSession session;
#else
Sqlite3Session session;
#endif
protected:
public:
ProtectDB();
~ProtectDB();
// setting of connection data
ProtectDB &SetHost(String const &_host) { host = _host; return *this; }
ProtectDB &SetDBName(String const &_dbName) { dbName = _dbName; return *this; }
ProtectDB &SetUserName(String const &_name) { userName = _name; return *this; }
ProtectDB &SetPassword(String const &_pwd) { password = _pwd; return *this; }
// connect/disconnect
bool Connect(void);
bool Disconnect(void);
bool IsConnected(void) { return connected; }
// refresh connection
bool RefreshConnection(void);
// get data -- email is the key -- non repeatable
VectorMap<String, Value>Get(String const &mail);
// set/append data
bool Set(VectorMap<String, Value> const &data);
// get default record
VectorMap<String, Value> Default(VectorMap<String, Value> const &base = VectorMap<String, Value>());
};
END_UPP_NAMESPACE
#endif