Mercurial > hg > orthanc-databases
changeset 214:ab96698c73a3
removed useless information about read-only in ITransaction and IPrecompiledStatement
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 25 Mar 2021 13:56:26 +0100 |
parents | c2e4a909de0e |
children | b40b30075c51 |
files | Framework/Common/IPrecompiledStatement.h Framework/Common/ITransaction.h Framework/Common/ImplicitTransaction.cpp Framework/Common/ImplicitTransaction.h Framework/MySQL/MySQLStatement.cpp Framework/MySQL/MySQLStatement.h Framework/MySQL/MySQLTransaction.cpp Framework/MySQL/MySQLTransaction.h Framework/PostgreSQL/PostgreSQLDatabase.cpp Framework/PostgreSQL/PostgreSQLStatement.cpp Framework/PostgreSQL/PostgreSQLStatement.h Framework/PostgreSQL/PostgreSQLTransaction.cpp Framework/PostgreSQL/PostgreSQLTransaction.h Framework/SQLite/SQLiteStatement.cpp Framework/SQLite/SQLiteStatement.h Framework/SQLite/SQLiteTransaction.cpp Framework/SQLite/SQLiteTransaction.h PostgreSQL/UnitTests/PostgreSQLTests.cpp |
diffstat | 18 files changed, 24 insertions(+), 129 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Common/IPrecompiledStatement.h Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/Common/IPrecompiledStatement.h Thu Mar 25 13:56:26 2021 +0100 @@ -31,7 +31,5 @@ virtual ~IPrecompiledStatement() { } - - virtual bool IsReadOnly() const = 0; }; }
--- a/Framework/Common/ITransaction.h Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/Common/ITransaction.h Thu Mar 25 13:56:26 2021 +0100 @@ -35,8 +35,6 @@ } virtual bool IsImplicit() const = 0; - - virtual bool IsReadOnly() const = 0; virtual void Rollback() = 0;
--- a/Framework/Common/ImplicitTransaction.cpp Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/Common/ImplicitTransaction.cpp Thu Mar 25 13:56:26 2021 +0100 @@ -33,8 +33,7 @@ ImplicitTransaction::ImplicitTransaction() : - state_(State_Ready), - readOnly_(true) + state_(State_Ready) { } @@ -127,11 +126,6 @@ CheckStateForExecution(); std::unique_ptr<IResult> result(ExecuteInternal(statement, parameters)); - if (!statement.IsReadOnly()) - { - readOnly_ = false; - } - state_ = State_Executed; return result.release(); } @@ -143,11 +137,6 @@ CheckStateForExecution(); ExecuteWithoutResultInternal(statement, parameters); - if (!statement.IsReadOnly()) - { - readOnly_ = false; - } - state_ = State_Executed; }
--- a/Framework/Common/ImplicitTransaction.h Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/Common/ImplicitTransaction.h Thu Mar 25 13:56:26 2021 +0100 @@ -38,7 +38,6 @@ }; State state_; - bool readOnly_; void CheckStateForExecution(); @@ -59,11 +58,6 @@ return true; } - virtual bool IsReadOnly() const ORTHANC_OVERRIDE - { - return readOnly_; - } - virtual void Rollback() ORTHANC_OVERRIDE; virtual void Commit() ORTHANC_OVERRIDE;
--- a/Framework/MySQL/MySQLStatement.cpp Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/MySQL/MySQLStatement.cpp Thu Mar 25 13:56:26 2021 +0100 @@ -348,7 +348,6 @@ MySQLStatement::MySQLStatement(MySQLDatabase& db, const Query& query) : db_(db), - readOnly_(query.IsReadOnly()), statement_(NULL), formatter_(Dialect_MySQL) {
--- a/Framework/MySQL/MySQLStatement.h Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/MySQL/MySQLStatement.h Thu Mar 25 13:56:26 2021 +0100 @@ -39,7 +39,6 @@ void Close(); MySQLDatabase& db_; - bool readOnly_; MYSQL_STMT *statement_; GenericFormatter formatter_; std::vector<ResultField*> result_; @@ -51,11 +50,6 @@ virtual ~MySQLStatement(); - virtual bool IsReadOnly() const ORTHANC_OVERRIDE - { - return readOnly_; - } - MYSQL_STMT* GetObject(); size_t GetResultFieldsCount() const
--- a/Framework/MySQL/MySQLTransaction.cpp Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/MySQL/MySQLTransaction.cpp Thu Mar 25 13:56:26 2021 +0100 @@ -33,7 +33,6 @@ { MySQLTransaction::MySQLTransaction(MySQLDatabase& db) : db_(db), - readOnly_(true), active_(false) { db_.Execute("START TRANSACTION", false); @@ -65,7 +64,6 @@ { db_.Execute("ROLLBACK", false); active_ = false; - readOnly_ = true; } else { @@ -81,7 +79,6 @@ { db_.Execute("COMMIT", false); active_ = false; - readOnly_ = true; } else { @@ -94,14 +91,7 @@ IResult* MySQLTransaction::Execute(IPrecompiledStatement& statement, const Dictionary& parameters) { - std::unique_ptr<IResult> result(dynamic_cast<MySQLStatement&>(statement).Execute(*this, parameters)); - - if (!statement.IsReadOnly()) - { - readOnly_ = false; - } - - return result.release(); + return dynamic_cast<MySQLStatement&>(statement).Execute(*this, parameters); } @@ -109,10 +99,5 @@ const Dictionary& parameters) { dynamic_cast<MySQLStatement&>(statement).ExecuteWithoutResult(*this, parameters); - - if (!statement.IsReadOnly()) - { - readOnly_ = false; - } } }
--- a/Framework/MySQL/MySQLTransaction.h Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/MySQL/MySQLTransaction.h Thu Mar 25 13:56:26 2021 +0100 @@ -34,7 +34,6 @@ { private: MySQLDatabase& db_; - bool readOnly_; bool active_; public: @@ -47,11 +46,6 @@ return false; } - virtual bool IsReadOnly() const ORTHANC_OVERRIDE - { - return readOnly_; - } - virtual void Rollback() ORTHANC_OVERRIDE; virtual void Commit() ORTHANC_OVERRIDE;
--- a/Framework/PostgreSQL/PostgreSQLDatabase.cpp Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/PostgreSQL/PostgreSQLDatabase.cpp Thu Mar 25 13:56:26 2021 +0100 @@ -194,7 +194,7 @@ "SELECT 1 FROM pg_catalog.pg_class c " "JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace " "WHERE n.nspname = 'public' AND c.relkind='r' " - "AND c.relname=$1", true); + "AND c.relname=$1"); statement.DeclareInputString(0); statement.BindString(0, lower);
--- a/Framework/PostgreSQL/PostgreSQLStatement.cpp Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/PostgreSQL/PostgreSQLStatement.cpp Thu Mar 25 13:56:26 2021 +0100 @@ -288,10 +288,8 @@ PostgreSQLStatement::PostgreSQLStatement(PostgreSQLDatabase& database, - const std::string& sql, - bool readOnly) : + const std::string& sql) : database_(database), - readOnly_(readOnly), sql_(sql), inputs_(new Inputs), formatter_(Dialect_PostgreSQL) @@ -303,7 +301,6 @@ PostgreSQLStatement::PostgreSQLStatement(PostgreSQLDatabase& database, const Query& query) : database_(database), - readOnly_(query.IsReadOnly()), inputs_(new Inputs), formatter_(Dialect_PostgreSQL) {
--- a/Framework/PostgreSQL/PostgreSQLStatement.h Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/PostgreSQL/PostgreSQLStatement.h Thu Mar 25 13:56:26 2021 +0100 @@ -47,7 +47,6 @@ friend class PostgreSQLResult; PostgreSQLDatabase& database_; - bool readOnly_; std::string id_; std::string sql_; std::vector<unsigned int /*Oid*/> oids_; @@ -66,19 +65,13 @@ public: PostgreSQLStatement(PostgreSQLDatabase& database, - const std::string& sql, - bool readOnly); + const std::string& sql); PostgreSQLStatement(PostgreSQLDatabase& database, const Query& query); ~PostgreSQLStatement(); - virtual bool IsReadOnly() const ORTHANC_OVERRIDE - { - return readOnly_; - } - void DeclareInputInteger(unsigned int param); void DeclareInputInteger64(unsigned int param);
--- a/Framework/PostgreSQL/PostgreSQLTransaction.cpp Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/PostgreSQL/PostgreSQLTransaction.cpp Thu Mar 25 13:56:26 2021 +0100 @@ -31,8 +31,7 @@ { PostgreSQLTransaction::PostgreSQLTransaction(PostgreSQLDatabase& database) : database_(database), - isOpen_(false), - readOnly_(true) + isOpen_(false) { Begin(); } @@ -66,7 +65,6 @@ database_.Execute("BEGIN"); database_.Execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"); - readOnly_ = true; isOpen_ = true; } @@ -102,14 +100,7 @@ IResult* PostgreSQLTransaction::Execute(IPrecompiledStatement& statement, const Dictionary& parameters) { - std::unique_ptr<IResult> result(dynamic_cast<PostgreSQLStatement&>(statement).Execute(*this, parameters)); - - if (!statement.IsReadOnly()) - { - readOnly_ = false; - } - - return result.release(); + return dynamic_cast<PostgreSQLStatement&>(statement).Execute(*this, parameters); } @@ -117,10 +108,5 @@ const Dictionary& parameters) { dynamic_cast<PostgreSQLStatement&>(statement).ExecuteWithoutResult(*this, parameters); - - if (!statement.IsReadOnly()) - { - readOnly_ = false; - } } }
--- a/Framework/PostgreSQL/PostgreSQLTransaction.h Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/PostgreSQL/PostgreSQLTransaction.h Thu Mar 25 13:56:26 2021 +0100 @@ -36,7 +36,6 @@ private: PostgreSQLDatabase& database_; bool isOpen_; - bool readOnly_; public: explicit PostgreSQLTransaction(PostgreSQLDatabase& database); @@ -48,11 +47,6 @@ return false; } - virtual bool IsReadOnly() const ORTHANC_OVERRIDE - { - return readOnly_; - } - void Begin(); virtual void Rollback() ORTHANC_OVERRIDE;
--- a/Framework/SQLite/SQLiteStatement.cpp Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/SQLite/SQLiteStatement.cpp Thu Mar 25 13:56:26 2021 +0100 @@ -34,7 +34,6 @@ { SQLiteStatement::SQLiteStatement(SQLiteDatabase& database, const Query& query) : - readOnly_(query.IsReadOnly()), formatter_(Dialect_SQLite) { std::string sql;
--- a/Framework/SQLite/SQLiteStatement.h Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/SQLite/SQLiteStatement.h Thu Mar 25 13:56:26 2021 +0100 @@ -40,7 +40,6 @@ { private: std::unique_ptr<Orthanc::SQLite::Statement> statement_; - bool readOnly_; GenericFormatter formatter_; void BindParameters(const Dictionary& parameters); @@ -49,11 +48,6 @@ SQLiteStatement(SQLiteDatabase& database, const Query& query); - virtual bool IsReadOnly() const ORTHANC_OVERRIDE - { - return readOnly_; - } - Orthanc::SQLite::Statement& GetObject(); IResult* Execute(ITransaction& transaction,
--- a/Framework/SQLite/SQLiteTransaction.cpp Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/SQLite/SQLiteTransaction.cpp Thu Mar 25 13:56:26 2021 +0100 @@ -30,8 +30,7 @@ namespace OrthancDatabases { SQLiteTransaction::SQLiteTransaction(SQLiteDatabase& database) : - transaction_(database.GetObject()), - readOnly_(true) + transaction_(database.GetObject()) { transaction_.Begin(); @@ -44,24 +43,12 @@ IResult* SQLiteTransaction::Execute(IPrecompiledStatement& statement, const Dictionary& parameters) { - std::unique_ptr<IResult> result(dynamic_cast<SQLiteStatement&>(statement).Execute(*this, parameters)); - - if (!statement.IsReadOnly()) - { - readOnly_ = false; - } - - return result.release(); + return dynamic_cast<SQLiteStatement&>(statement).Execute(*this, parameters); } void SQLiteTransaction::ExecuteWithoutResult(IPrecompiledStatement& statement, const Dictionary& parameters) { dynamic_cast<SQLiteStatement&>(statement).ExecuteWithoutResult(*this, parameters); - - if (!statement.IsReadOnly()) - { - readOnly_ = false; - } } }
--- a/Framework/SQLite/SQLiteTransaction.h Wed Mar 24 15:59:23 2021 +0100 +++ b/Framework/SQLite/SQLiteTransaction.h Thu Mar 25 13:56:26 2021 +0100 @@ -36,7 +36,6 @@ { private: Orthanc::SQLite::Transaction transaction_; - bool readOnly_; public: explicit SQLiteTransaction(SQLiteDatabase& database); @@ -46,11 +45,6 @@ return false; } - virtual bool IsReadOnly() const ORTHANC_OVERRIDE - { - return readOnly_; - } - virtual void Rollback() ORTHANC_OVERRIDE { transaction_.Rollback();
--- a/PostgreSQL/UnitTests/PostgreSQLTests.cpp Wed Mar 24 15:59:23 2021 +0100 +++ b/PostgreSQL/UnitTests/PostgreSQLTests.cpp Thu Mar 25 13:56:26 2021 +0100 @@ -66,7 +66,7 @@ static int64_t CountLargeObjects(PostgreSQLDatabase& db) { // Count the number of large objects in the DB - PostgreSQLStatement s(db, "SELECT COUNT(*) FROM pg_catalog.pg_largeobject", true); + PostgreSQLStatement s(db, "SELECT COUNT(*) FROM pg_catalog.pg_largeobject"); PostgreSQLResult r(s); return r.GetInteger64(0); } @@ -80,7 +80,7 @@ pg->Execute("CREATE TABLE Test(name INTEGER, value BIGINT)"); ASSERT_TRUE(pg->DoesTableExist("Test")); - PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)", false); + PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)"); s.DeclareInputInteger(0); s.DeclareInputInteger64(1); @@ -99,7 +99,7 @@ s.Run(); { - PostgreSQLStatement t(*pg, "SELECT name, value FROM Test ORDER BY name", true); + PostgreSQLStatement t(*pg, "SELECT name, value FROM Test ORDER BY name"); PostgreSQLResult r(t); ASSERT_FALSE(r.IsDone()); @@ -121,7 +121,7 @@ } { - PostgreSQLStatement t(*pg, "SELECT name, value FROM Test WHERE name=$1", true); + PostgreSQLStatement t(*pg, "SELECT name, value FROM Test WHERE name=$1"); t.DeclareInputInteger(0); { @@ -151,7 +151,7 @@ pg->Execute("CREATE TABLE Test(name INTEGER, value VARCHAR(40))"); - PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)", false); + PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)"); s.DeclareInputInteger(0); s.DeclareInputString(1); @@ -168,7 +168,7 @@ s.Run(); { - PostgreSQLStatement t(*pg, "SELECT name, value FROM Test ORDER BY name", true); + PostgreSQLStatement t(*pg, "SELECT name, value FROM Test ORDER BY name"); PostgreSQLResult r(t); ASSERT_FALSE(r.IsDone()); @@ -198,7 +198,7 @@ pg->Execute("CREATE TABLE Test(name INTEGER, value INTEGER)"); { - PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)", false); + PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)"); s.DeclareInputInteger(0); s.DeclareInputInteger(1); s.BindInteger(0, 42); @@ -214,7 +214,7 @@ s.BindInteger(1, 4444); s.Run(); - PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test", true); + PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test"); PostgreSQLResult r(u); ASSERT_EQ(3, r.GetInteger64(0)); @@ -222,7 +222,7 @@ } { - PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test", true); + PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test"); PostgreSQLResult r(u); ASSERT_EQ(1, r.GetInteger64(0)); // Just "1" because of implicit rollback } @@ -237,7 +237,7 @@ s.Run(); { - PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test", true); + PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test"); PostgreSQLResult r(u); ASSERT_EQ(3, r.GetInteger64(0)); @@ -248,7 +248,7 @@ } { - PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test", true); + PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test"); PostgreSQLResult r(u); ASSERT_EQ(3, r.GetInteger64(0)); } @@ -270,7 +270,7 @@ pg->Execute("CREATE RULE TestDelete AS ON DELETE TO Test DO SELECT lo_unlink(old.value);"); { - PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)", false); + PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)"); s.DeclareInputString(0); s.DeclareInputLargeObject(1); @@ -298,7 +298,7 @@ { PostgreSQLTransaction t(*pg); - PostgreSQLStatement s(*pg, "SELECT * FROM Test ORDER BY name DESC", true); + PostgreSQLStatement s(*pg, "SELECT * FROM Test ORDER BY name DESC"); PostgreSQLResult r(s); ASSERT_FALSE(r.IsDone()); @@ -319,7 +319,7 @@ { PostgreSQLTransaction t(*pg); - PostgreSQLStatement s(*pg, "DELETE FROM Test WHERE name='Index 9'", false); + PostgreSQLStatement s(*pg, "DELETE FROM Test WHERE name='Index 9'"); s.Run(); t.Commit(); } @@ -328,7 +328,7 @@ { // Count the number of items in the DB PostgreSQLTransaction t(*pg); - PostgreSQLStatement s(*pg, "SELECT COUNT(*) FROM Test", true); + PostgreSQLStatement s(*pg, "SELECT COUNT(*) FROM Test"); PostgreSQLResult r(s); ASSERT_EQ(9, r.GetInteger64(0)); }