Commit 1537ead3 authored by Pavel Vainerman's avatar Pavel Vainerman

minor fixes add added some comments

parent f40c4b0c
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
namespace uniset namespace uniset
{ {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// no thread safety
class MySQLInterface: class MySQLInterface:
public DBNetInterface public DBNetInterface
{ {
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#include <sstream> #include <sstream>
#include <cstdio> #include <cstdio>
#include <UniSetTypes.h> #include "UniSetTypes.h"
#include "unisetstd.h"
#include "PostgreSQLInterface.h" #include "PostgreSQLInterface.h"
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
using namespace std; using namespace std;
...@@ -52,7 +53,7 @@ bool PostgreSQLInterface::ping() const ...@@ -52,7 +53,7 @@ bool PostgreSQLInterface::ping() const
try try
{ {
// pqxx doesn't work with unique_ptr (
nontransaction n(*(db.get())); nontransaction n(*(db.get()));
n.exec("select 1;"); n.exec("select 1;");
return true; return true;
...@@ -89,7 +90,7 @@ bool PostgreSQLInterface::nconnect(const string& host, const string& user, const ...@@ -89,7 +90,7 @@ bool PostgreSQLInterface::nconnect(const string& host, const string& user, const
try try
{ {
db = make_shared<pqxx::connection>( std::move(conninfo.str()) ); db = unisetstd::make_unique<pqxx::connection>( std::move(conninfo.str()) );
return db->is_open(); return db->is_open();
} }
catch( const std::exception& e ) catch( const std::exception& e )
...@@ -122,10 +123,11 @@ bool PostgreSQLInterface::copy( const std::string& tblname, const std::vector<st ...@@ -122,10 +123,11 @@ bool PostgreSQLInterface::copy( const std::string& tblname, const std::vector<st
try try
{ {
// pqxx doesn't work with unique_ptr
work w( *(db.get()) ); work w( *(db.get()) );
tablewriter t(w, tblname, cols.begin(), cols.end()); tablewriter t(w, tblname, cols.begin(), cols.end());
t.reserve(data.size()); // size() не дорогая операция для list? t.reserve(data.size());
for( const auto& d : data ) for( const auto& d : data )
t.push_back(d.begin(), d.end()); t.push_back(d.begin(), d.end());
...@@ -153,6 +155,7 @@ bool PostgreSQLInterface::insert( const string& q ) ...@@ -153,6 +155,7 @@ bool PostgreSQLInterface::insert( const string& q )
try try
{ {
// pqxx doesn't work with unique_ptr
work w( *(db.get()) ); work w( *(db.get()) );
lastQ = q; lastQ = q;
w.exec(q); w.exec(q);
...@@ -180,6 +183,7 @@ bool PostgreSQLInterface::insertAndSaveRowid( const string& q ) ...@@ -180,6 +183,7 @@ bool PostgreSQLInterface::insertAndSaveRowid( const string& q )
try try
{ {
// pqxx doesn't work with unique_ptr
work w( *(db.get()) ); work w( *(db.get()) );
lastQ = q; lastQ = q;
pqxx::result res = w.exec(qplus); pqxx::result res = w.exec(qplus);
...@@ -203,7 +207,7 @@ DBResult PostgreSQLInterface::query( const string& q ) ...@@ -203,7 +207,7 @@ DBResult PostgreSQLInterface::query( const string& q )
try try
{ {
// pqxx doesn't work with unique_ptr
nontransaction n(*(db.get())); nontransaction n(*(db.get()));
lastQ = q; lastQ = q;
/* Execute SQL query */ /* Execute SQL query */
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
namespace uniset namespace uniset
{ {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// No thread safety!
class PostgreSQLInterface: class PostgreSQLInterface:
public DBNetInterface public DBNetInterface
{ {
...@@ -70,7 +71,7 @@ namespace uniset ...@@ -70,7 +71,7 @@ namespace uniset
private: private:
DBResult makeResult( const pqxx::result& res ); DBResult makeResult( const pqxx::result& res );
std::shared_ptr<pqxx::connection> db; std::unique_ptr<pqxx::connection> db;
std::string lastQ; std::string lastQ;
std::string lastE; std::string lastE;
double last_inserted_id; double last_inserted_id;
......
...@@ -82,6 +82,9 @@ bool SQLiteInterface::connect( const string& dbfile, bool create, int extra_sqli ...@@ -82,6 +82,9 @@ bool SQLiteInterface::connect( const string& dbfile, bool create, int extra_sqli
// if( !create && !uniset::file_exist(dbfile) ) // if( !create && !uniset::file_exist(dbfile) )
// return false; // return false;
if( db && ping() )
return true;
int flags = create ? 0 : SQLITE_OPEN_READWRITE; int flags = create ? 0 : SQLITE_OPEN_READWRITE;
if( extra_sqlite_flags ) if( extra_sqlite_flags )
......
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