Commit 00911199 authored by Pavel Vainerman's avatar Pavel Vainerman

make style, new release

parent 04cf4bc4
......@@ -92,6 +92,7 @@ DBResult MySQLInterface::query( const std::string& q )
if( !res || mysql_num_rows(res) == 0 )
return DBResult();
DBResult dbres;
makeResult(dbres, res, true);
return dbres;
......
......@@ -33,7 +33,8 @@
#include <mysql/mysql.h>
#include <DBInterface.h>
// ----------------------------------------------------------------------------
class MySQLInterface : public DBNetInterface
class MySQLInterface:
public DBNetInterface
{
public:
......@@ -42,17 +43,17 @@ class MySQLInterface : public DBNetInterface
// DBResult listFields( const std::string& table, const std::string& wild );
bool nconnect( const std::string& host, const std::string& user, const std::string& pswd,
virtual bool nconnect( const std::string& host, const std::string& user, const std::string& pswd,
const std::string& dbname) override;
bool close() override;
virtual bool close() override;
bool query_ok( const std::string& q );
// \param finalize - освободить буфер после запроса
DBResult query( const std::string& q ) override;
virtual DBResult query( const std::string& q ) override;
const std::string lastQuery() override;
bool insert( const std::string& q ) override;
virtual const std::string lastQuery() override;
virtual bool insert( const std::string& q ) override;
std::string addslashes(const std::string& str);
......@@ -60,14 +61,14 @@ class MySQLInterface : public DBNetInterface
проверка связи с БД.
в случае отсутсвия попытка восстановить...
*/
bool ping() override;
virtual bool ping() override;
/*! связь с БД установлена (была) */
bool isConnection() override;
virtual bool isConnection() override;
double insert_id() override;
virtual double insert_id() override;
const std::string error() override;
virtual const std::string error() override;
// *******************
const char* gethostinfo();
......
......@@ -10,27 +10,28 @@
#include <PassiveTimer.h>
#include <DBInterface.h>
// ----------------------------------------------------------------------------
class PostgreSQLInterface : public DBNetInterface
class PostgreSQLInterface:
public DBNetInterface
{
public:
PostgreSQLInterface();
~PostgreSQLInterface();
bool nconnect( const std::string& host, const std::string& user, const std::string& pswd, const std::string& dbname ) override;
bool close() override;
bool isConnection() override;
bool ping() override; // проверка доступности БД
virtual bool nconnect( const std::string& host, const std::string& user, const std::string& pswd, const std::string& dbname ) override;
virtual bool close() override;
virtual bool isConnection() override;
virtual bool ping() override; // проверка доступности БД
DBResult query( const std::string& q ) override;
const std::string lastQuery() override;
virtual DBResult query( const std::string& q ) override;
virtual const std::string lastQuery() override;
bool insert( const std::string& q ) override;
virtual bool insert( const std::string& q ) override;
bool insertAndSaveRowid( const std::string& q );
double insert_id() override;
virtual double insert_id() override;
void save_inserted_id( const pqxx::result& res );
const std::string error() override;
virtual const std::string error() override;
protected:
......
......@@ -56,13 +56,16 @@ bool SQLiteInterface::connect( const std::string& param )
{
std::string dbfile;
std::string::size_type pos = param.find_first_of(":");
if( pos != std::string::npos )
{
dbfile = param.substr(0, pos);
std::string create_str = param.substr(pos + 1, std::string::npos);
if( create_str == "true" )
return connect( dbfile, true );
}
return connect( dbfile, false );
}
// -----------------------------------------------------------------------------------------
......
......@@ -82,18 +82,19 @@
// PRAGMA journal_mode = MEMORY
// При этом конечно есть риск потерять данные при выключении..
// ----------------------------------------------------------------------------
class SQLiteInterface : public DBInterface
class SQLiteInterface:
public DBInterface
{
public:
SQLiteInterface();
~SQLiteInterface();
bool connect( const std::string& param ) override;
virtual bool connect( const std::string& param ) override;
bool connect( const std::string& dbfile, bool create );
bool close() override;
bool isConnection() override;
bool ping() override; // проверка доступности БД
virtual bool close() override;
virtual bool isConnection() override;
virtual bool ping() override; // проверка доступности БД
void setOperationTimeout( timeout_t msec );
inline timeout_t getOperationTimeout()
......@@ -110,13 +111,13 @@ class SQLiteInterface : public DBInterface
return opCheckPause;
}
DBResult query( const std::string& q ) override;
const std::string lastQuery() override;
virtual DBResult query( const std::string& q ) override;
virtual const std::string lastQuery() override;
bool insert( const std::string& q ) override;
double insert_id() override;
virtual bool insert( const std::string& q ) override;
virtual double insert_id() override;
const std::string error() override;
virtual const std::string error() override;
protected:
......
......@@ -14,8 +14,8 @@ class DBInterface
{
public:
DBInterface(){};
virtual ~DBInterface(){};
DBInterface() {};
virtual ~DBInterface() {};
// Функция подключения к БД, параметры подключения зависят от типа БД
virtual bool connect( const std::string& param ) = 0;
......@@ -34,8 +34,8 @@ class DBNetInterface : public DBInterface
{
public:
DBNetInterface(){};
virtual ~DBNetInterface(){};
DBNetInterface() {};
virtual ~DBNetInterface() {};
// Для сетевых БД параметры должны быть в формате user@host:pswd:dbname
virtual bool connect( const std::string& param );
......@@ -47,7 +47,7 @@ class DBResult
public:
DBResult() {}
virtual ~DBResult(){};
virtual ~DBResult() {};
typedef std::vector<std::string> COL;
typedef std::deque<COL> ROW;
......
......@@ -8,20 +8,28 @@ bool DBNetInterface::connect( const std::string& param )
std::string dbname;
std::string::size_type pos = param.find_first_of("@");
std::string::size_type prev = 0;
if( pos != std::string::npos )
user = param.substr(prev, pos);
prev = pos + 1;
pos = param.find_first_of(":", prev);
if( pos != std::string::npos )
host = param.substr(prev, pos);
prev = pos + 1;
pos = param.find_first_of(":", prev);
if( pos != std::string::npos )
pswd = param.substr(prev, pos);
prev = pos + 1;
pos = param.find_first_of(":", prev);
if( pos != std::string::npos )
dbname = param.substr(prev, pos);
return nconnect( host, user, pswd, dbname );
}
//--------------------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment