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

minor fixes add added some comments

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