Commit 97db46bc authored by Pavel Vainerman's avatar Pavel Vainerman

(PGSQLInterface): добавил функцию быстрой вставки (на основе COPY)

parent a5a16445
......@@ -86,6 +86,33 @@ bool PostgreSQLInterface::close()
return true;
}
// -----------------------------------------------------------------------------------------
bool PostgreSQLInterface::copy( const std::string& tblname, const std::list<std::string>& cols, const std::list<std::list<std::string>>& data )
{
if( !db )
return false;
try
{
work w( *(db.get()) );
tablewriter t(w,tblname,cols.begin(),cols.end());
t.reserve(data.size());
for( const auto& d: data )
t.push_back(d.begin(),d.end());
t.complete();
w.commit();
return true;
}
catch( const std::exception& e )
{
//cerr << e.what() << std::endl;
lastE = string(e.what());
}
return false;
}
// -----------------------------------------------------------------------------------------
bool PostgreSQLInterface::insert( const string& q )
{
if( !db )
......
......@@ -48,6 +48,9 @@ class PostgreSQLInterface:
virtual double insert_id() override;
void save_inserted_id( const pqxx::result& res );
// fast insert: Use COPY..from SDTIN..
virtual bool copy( const std::string& tblname, const std::list<std::string>& cols, const std::list<std::list<std::string>>& data );
virtual const std::string error() override;
protected:
......
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