Merge branch 'master' into iaadeflate_upgrade_qpl_v1.1.0

This commit is contained in:
Robert Schulze 2023-04-26 13:27:50 +02:00 committed by GitHub
commit f0710d7be1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -345,6 +345,7 @@ private:
PreparedInsert(pqxx::connection & connection_, const String & table, const String & schema,
const ColumnsWithTypeAndName & columns, const String & on_conflict_)
: Inserter(connection_)
, statement_name("insert_" + getHexUIntLowercase(thread_local_rng()))
{
WriteBufferFromOwnString buf;
buf << getInsertQuery(schema, table, columns, IdentifierQuotingStyle::DoubleQuotes);
@ -357,12 +358,14 @@ private:
}
buf << ") ";
buf << on_conflict_;
connection.prepare("insert", buf.str());
connection.prepare(statement_name, buf.str());
prepared = true;
}
void complete() override
{
connection.unprepare("insert");
connection.unprepare(statement_name);
prepared = false;
tx.commit();
}
@ -371,8 +374,24 @@ private:
pqxx::params params;
params.reserve(row.size());
params.append_multi(row);
tx.exec_prepared("insert", params);
tx.exec_prepared(statement_name, params);
}
~PreparedInsert() override
{
try
{
if (prepared)
connection.unprepare(statement_name);
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}
const String statement_name;
bool prepared = false;
};
StorageMetadataPtr metadata_snapshot;