Commit c8a39cf6 authored by Cedric Caffy's avatar Cedric Caffy
Browse files

[schema-verify] Added warnings for TYPES and SYNONYMS

parent 3b04912f
...@@ -137,6 +137,14 @@ std::list<std::string> DatabaseMetadataGetter::getStoredProcedures() { ...@@ -137,6 +137,14 @@ std::list<std::string> DatabaseMetadataGetter::getStoredProcedures() {
return m_conn.getStoredProcedureNames(); return m_conn.getStoredProcedureNames();
} }
std::list<std::string> DatabaseMetadataGetter::getSynonyms(){
return m_conn.getSynonymNames();
}
std::list<std::string> DatabaseMetadataGetter::getTypes() {
return m_conn.getTypeNames();
}
DatabaseMetadataGetter::~DatabaseMetadataGetter() {} DatabaseMetadataGetter::~DatabaseMetadataGetter() {}
SQLiteDatabaseMetadataGetter::SQLiteDatabaseMetadataGetter(cta::rdbms::Conn & conn):DatabaseMetadataGetter(conn){} SQLiteDatabaseMetadataGetter::SQLiteDatabaseMetadataGetter(cta::rdbms::Conn & conn):DatabaseMetadataGetter(conn){}
......
...@@ -63,6 +63,8 @@ class DatabaseMetadataGetter: public MetadataGetter { ...@@ -63,6 +63,8 @@ class DatabaseMetadataGetter: public MetadataGetter {
virtual std::list<std::string> getParallelTableNames(); virtual std::list<std::string> getParallelTableNames();
virtual cta::rdbms::Login::DbType getDbType() = 0; virtual cta::rdbms::Login::DbType getDbType() = 0;
virtual std::list<std::string> getStoredProcedures(); virtual std::list<std::string> getStoredProcedures();
virtual std::list<std::string> getSynonyms();
virtual std::list<std::string> getTypes();
}; };
/** /**
......
...@@ -105,13 +105,33 @@ SchemaCheckerResult SchemaChecker::checkTableContainsColumns(const std::string& ...@@ -105,13 +105,33 @@ SchemaCheckerResult SchemaChecker::checkTableContainsColumns(const std::string&
SchemaCheckerResult SchemaChecker::warnProcedures() { SchemaCheckerResult SchemaChecker::warnProcedures() {
SchemaCheckerResult res; SchemaCheckerResult res;
std::list<std::string> procedureNames = m_databaseMetadataGetter->getStoredProcedures(); std::list<std::string> procedureNames = m_databaseMetadataGetter->getStoredProcedures();
for(auto procedure: procedureNames){ for(auto & procedure: procedureNames){
std::string warning = "PROCEDURE " + procedure + " exists in the " + m_databaseToCheckName + " database"; std::string warning = "PROCEDURE " + procedure + " exists in the " + m_databaseToCheckName + " database";
res.addWarning(warning); res.addWarning(warning);
} }
return res; return res;
} }
SchemaCheckerResult SchemaChecker::warnSynonyms() {
SchemaCheckerResult res;
std::list<std::string> synonymsNames = m_databaseMetadataGetter->getSynonyms();
for(auto & synonym: synonymsNames){
std::string warning = "SYNONYM " + synonym + " exists in the " + m_databaseToCheckName + " database";
res.addWarning(warning);
}
return res;
}
SchemaCheckerResult SchemaChecker::warnTypes() {
SchemaCheckerResult res;
std::list<std::string> typeNames = m_databaseMetadataGetter->getTypes();
for(auto & type: typeNames) {
std::string warning = "TYPE " + type + " exists in the " + m_databaseToCheckName + " database";
res.addWarning(warning);
}
return res;
}
///////////////////////////////////////// /////////////////////////////////////////
// SchemaChecker::Builder // SchemaChecker::Builder
......
...@@ -81,11 +81,23 @@ public: ...@@ -81,11 +81,23 @@ public:
SchemaCheckerResult checkTableContainsColumns(const std::string &tableName, const std::list<std::string> columnNames); SchemaCheckerResult checkTableContainsColumns(const std::string &tableName, const std::list<std::string> columnNames);
/** /**
* Checks if there are stored procedures in the schema. * Checks if there are stored procedures in the database.
* @return a SchemaCheckerResult containing warnings if there are stored procedures. * @return a SchemaCheckerResult containing warnings if there are stored procedures.
*/ */
SchemaCheckerResult warnProcedures(); SchemaCheckerResult warnProcedures();
/**
* Checks if there are synonyms in the database.
* @return a SchemaCheckerResult containing warnings if there are synonyms
*/
SchemaCheckerResult warnSynonyms();
/**
* Checks if there are types in the database
* @return a SchemaCheckerResult containing warnings if there are types in the database
*/
SchemaCheckerResult warnTypes();
class Builder { class Builder {
public: public:
Builder(const std::string databaseToCheckName, const cta::rdbms::Login::DbType dbType, cta::rdbms::Conn &conn); Builder(const std::string databaseToCheckName, const cta::rdbms::Login::DbType dbType, cta::rdbms::Conn &conn);
......
...@@ -84,6 +84,8 @@ int VerifySchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar ...@@ -84,6 +84,8 @@ int VerifySchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar
result += schemaChecker->warnParallelTables(); result += schemaChecker->warnParallelTables();
result += schemaChecker->warnSchemaUpgrading(); result += schemaChecker->warnSchemaUpgrading();
result += schemaChecker->warnProcedures(); result += schemaChecker->warnProcedures();
result += schemaChecker->warnSynonyms();
result += schemaChecker->warnTypes();
result.displayWarnings(std::cout); result.displayWarnings(std::cout);
if(result.getStatus() == SchemaCheckerResult::Status::FAILED){ if(result.getStatus() == SchemaCheckerResult::Status::FAILED){
return 1; return 1;
......
...@@ -263,5 +263,27 @@ std::list<std::string> Conn::getStoredProcedureNames(){ ...@@ -263,5 +263,27 @@ std::list<std::string> Conn::getStoredProcedureNames(){
} }
} }
//------------------------------------------------------------------------------
// getSynonymNames
//------------------------------------------------------------------------------
std::list<std::string> Conn::getSynonymNames(){
if(nullptr != m_connAndStmts && nullptr != m_connAndStmts->conn) {
return m_connAndStmts->conn->getSynonymNames();
} else {
throw exception::Exception(std::string(__FUNCTION__) + " failed: Conn does not contain a connection");
}
}
//------------------------------------------------------------------------------
// getTypeNames
//------------------------------------------------------------------------------
std::list<std::string> Conn::getTypeNames() {
if(nullptr != m_connAndStmts && nullptr != m_connAndStmts->conn) {
return m_connAndStmts->conn->getTypeNames();
} else {
throw exception::Exception(std::string(__FUNCTION__) + " failed: Conn does not contain a connection");
}
}
} // namespace rdbms } // namespace rdbms
} // namespace cta } // namespace cta
...@@ -231,6 +231,26 @@ public: ...@@ -231,6 +231,26 @@ public:
*/ */
std::list<std::string> getStoredProcedureNames(); std::list<std::string> getStoredProcedureNames();
/**
* Returns the synonym names of the database
*
* If the underlying database technologies does not support synonym informations
* this method simply returns an empty list.
*
* @return the list of the names of the synonyms in the database
*/
std::list<std::string> getSynonymNames();
/**
* Returns the type names of the database
*
* If the underlying database technologies does not support type informations
* this method simply returns an empty list.
*
* @return the list of the names of the types in the database
*/
std::list<std::string> getTypeNames();
/** /**
* Get a pointer to the connection wrapper implementation * Get a pointer to the connection wrapper implementation
* *
......
...@@ -177,7 +177,27 @@ public: ...@@ -177,7 +177,27 @@ public:
* @return the list of the names of the stored procedures in the database * @return the list of the names of the stored procedures in the database
*/ */
virtual std::list<std::string> getStoredProcedureNames() = 0; virtual std::list<std::string> getStoredProcedureNames() = 0;
/**
* Returns the synonym names of the database
*
* If the underlying database technologies does not support synonym informations
* this method simply returns an empty list.
*
* @return the list of the names of the synonyms in the database
*/
virtual std::list<std::string> getSynonymNames() = 0;
/**
* Returns the type names of the database
*
* If the underlying database technologies does not support type informations
* this method simply returns an empty list.
*
* @return the list of the names of the types in the database
*/
virtual std::list<std::string> getTypeNames() = 0;
}; // class ConnWrapper }; // class ConnWrapper
} // namespace wrapper } // namespace wrapper
......
...@@ -359,6 +359,22 @@ std::list<std::string> MysqlConn::getStoredProcedureNames() { ...@@ -359,6 +359,22 @@ std::list<std::string> MysqlConn::getStoredProcedureNames() {
return std::list<std::string>(); return std::list<std::string>();
} }
//------------------------------------------------------------------------------
// getSynonymNames
//------------------------------------------------------------------------------
std::list<std::string> MysqlConn::getSynonymNames() {
return std::list<std::string>();
}
//------------------------------------------------------------------------------
// getTypeNames
//------------------------------------------------------------------------------
std::list<std::string> MysqlConn::getTypeNames() {
return std::list<std::string>();
}
} // namespace wrapper } // namespace wrapper
} // namespace rdbms } // namespace rdbms
} // namespace cta } // namespace cta
...@@ -204,6 +204,27 @@ public: ...@@ -204,6 +204,27 @@ public:
* @return the list of the names of the stored procedures in the database * @return the list of the names of the stored procedures in the database
*/ */
std::list<std::string> getStoredProcedureNames() override; std::list<std::string> getStoredProcedureNames() override;
/**
* Returns the synonym names of the database
*
* If the underlying database technologies does not support synonym informations
* this method simply returns an empty list.
*
* @return the list of the names of the synonyms in the database
*/
std::list<std::string> getSynonymNames() override;
/**
* Returns the type names of the database
*
* If the underlying database technologies does not support type informations
* this method simply returns an empty list.
*
* @return the list of the names of the types in the database
*/
std::list<std::string> getTypeNames() override;
private: private:
......
...@@ -342,7 +342,7 @@ std::list<std::string> OcciConn::getConstraintNames(const std::string& tableName ...@@ -342,7 +342,7 @@ std::list<std::string> OcciConn::getConstraintNames(const std::string& tableName
// getStoredProcedureNames // getStoredProcedureNames
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
std::list<std::string> OcciConn::getStoredProcedureNames() { std::list<std::string> OcciConn::getStoredProcedureNames() {
try { try {
std::list<std::string> names; std::list<std::string> names;
const char *const sql = const char *const sql =
"SELECT " "SELECT "
...@@ -361,6 +361,51 @@ std::list<std::string> OcciConn::getStoredProcedureNames() { ...@@ -361,6 +361,51 @@ std::list<std::string> OcciConn::getStoredProcedureNames() {
} }
} }
//------------------------------------------------------------------------------
// getSynonymNames
//------------------------------------------------------------------------------
std::list<std::string> OcciConn::getSynonymNames() {
try {
std::list<std::string> names;
const char *const sql =
"SELECT "
"SYNONYM_NAME "
"FROM "
"USER_SYNONYMS";
auto stmt = createStmt(sql);
auto rset = stmt->executeQuery();
while (rset->next()) {
auto name = rset->columnOptionalString("SYNONYM_NAME");
names.push_back(name.value());
}
return names;
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
//------------------------------------------------------------------------------
// getTypeNames
//------------------------------------------------------------------------------
std::list<std::string> OcciConn::getTypeNames() {
try {
std::list<std::string> names;
const char *const sql =
"SELECT "
"TYPE_NAME "
"FROM "
"USER_TYPES";
auto stmt = createStmt(sql);
auto rset = stmt->executeQuery();
while (rset->next()) {
auto name = rset->columnOptionalString("TYPE_NAME");
names.push_back(name.value());
}
return names;
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// isOpen // isOpen
......
...@@ -187,6 +187,26 @@ public: ...@@ -187,6 +187,26 @@ public:
* @return the list of the names of the stored procedures in the database * @return the list of the names of the stored procedures in the database
*/ */
std::list<std::string> getStoredProcedureNames() override; std::list<std::string> getStoredProcedureNames() override;
/**
* Returns the synonym names of the database
*
* If the underlying database technologies does not support synonym informations
* this method simply returns an empty list.
*
* @return the list of the names of the synonyms in the database
*/
std::list<std::string> getSynonymNames() override;
/**
* Returns the type names of the database
*
* If the underlying database technologies does not support type informations
* this method simply returns an empty list.
*
* @return the list of the names of the types in the database
*/
std::list<std::string> getTypeNames() override;
private: private:
......
...@@ -370,6 +370,20 @@ std::list<std::string> PostgresConn::getStoredProcedureNames() { ...@@ -370,6 +370,20 @@ std::list<std::string> PostgresConn::getStoredProcedureNames() {
} }
//------------------------------------------------------------------------------
// getSynonymNames
//------------------------------------------------------------------------------
std::list<std::string> PostgresConn::getSynonymNames() {
return std::list<std::string>();
}
//------------------------------------------------------------------------------
// getTypeNames
//------------------------------------------------------------------------------
std::list<std::string> PostgresConn::getTypeNames() {
return std::list<std::string>();
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// isOpen // isOpen
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
...@@ -140,7 +140,27 @@ public: ...@@ -140,7 +140,27 @@ public:
* @return the list of the names of the stored procedures in the database * @return the list of the names of the stored procedures in the database
*/ */
std::list<std::string> getStoredProcedureNames() override; std::list<std::string> getStoredProcedureNames() override;
/**
* Returns the synonym names of the database
*
* If the underlying database technologies does not support synonym informations
* this method simply returns an empty list.
*
* @return the list of the names of the synonyms in the database
*/
std::list<std::string> getSynonymNames() override;
/**
* Returns the type names of the database
*
* If the underlying database technologies does not support type informations
* this method simply returns an empty list.
*
* @return the list of the names of the types in the database
*/
std::list<std::string> getTypeNames() override;
/** /**
* Returns the names of all the column and their type as a map for the given * Returns the names of all the column and their type as a map for the given
* table in the database schema. * table in the database schema.
......
...@@ -441,6 +441,20 @@ std::list<std::string> SqliteConn::getStoredProcedureNames() { ...@@ -441,6 +441,20 @@ std::list<std::string> SqliteConn::getStoredProcedureNames() {
return std::list<std::string>(); return std::list<std::string>();
} }
//------------------------------------------------------------------------------
// getSynonymNames
//------------------------------------------------------------------------------
std::list<std::string> SqliteConn::getSynonymNames() {
return std::list<std::string>();
}
//------------------------------------------------------------------------------
// getTypeNames
//------------------------------------------------------------------------------
std::list<std::string> SqliteConn::getTypeNames() {
return std::list<std::string>();
}
} // namespace wrapper } // namespace wrapper
} // namespace rdbms } // namespace rdbms
......
...@@ -190,6 +190,25 @@ public: ...@@ -190,6 +190,25 @@ public:
*/ */
std::list<std::string> getStoredProcedureNames() override; std::list<std::string> getStoredProcedureNames() override;
/**
* Returns the synonym names of the database
*
* If the underlying database technologies does not support synonym informations
* this method simply returns an empty list.
*
* @return the list of the names of the synonyms in the database
*/
std::list<std::string> getSynonymNames() override;
/**
* Returns the type names of the database
*
* If the underlying database technologies does not support type informations
* this method simply returns an empty list.
*
* @return the list of the names of the types in the database
*/
std::list<std::string> getTypeNames() override;
/** /**
* This is an SqliteConn specific method that prints the database schema to * This is an SqliteConn specific method that prints the database schema to
......
Supports Markdown
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