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