Commit 3b04912f authored by Cedric Caffy's avatar Cedric Caffy
Browse files

[schema-verify] added the stored procedures warnings to the

cta-catalogue-schema-verify tool
parent b271c7cd
......@@ -133,6 +133,10 @@ std::list<std::string> DatabaseMetadataGetter::getParallelTableNames(){
return m_conn.getParallelTableNames();
}
std::list<std::string> DatabaseMetadataGetter::getStoredProcedures() {
return m_conn.getStoredProcedureNames();
}
DatabaseMetadataGetter::~DatabaseMetadataGetter() {}
SQLiteDatabaseMetadataGetter::SQLiteDatabaseMetadataGetter(cta::rdbms::Conn & conn):DatabaseMetadataGetter(conn){}
......
......@@ -62,6 +62,7 @@ class DatabaseMetadataGetter: public MetadataGetter {
virtual std::list<std::string> getConstraintNames(const std::string& tableName);
virtual std::list<std::string> getParallelTableNames();
virtual cta::rdbms::Login::DbType getDbType() = 0;
virtual std::list<std::string> getStoredProcedures();
};
/**
......
......@@ -58,7 +58,7 @@ SchemaCheckerResult SchemaChecker::displayingCompareSchema(std::ostream & stdOut
return totalResult;
}
SchemaCheckerResult SchemaChecker::checkNoParallelTables(){
SchemaCheckerResult SchemaChecker::warnParallelTables(){
SchemaCheckerResult res;
std::list<std::string> parallelTables = m_databaseMetadataGetter->getParallelTableNames();
for(auto& table:parallelTables) {
......@@ -68,7 +68,7 @@ SchemaCheckerResult SchemaChecker::checkNoParallelTables(){
return res;
}
SchemaCheckerResult SchemaChecker::checkSchemaNotUpgrading(){
SchemaCheckerResult SchemaChecker::warnSchemaUpgrading(){
SchemaCheckerResult res;
SchemaVersion catalogueVersion = m_databaseMetadataGetter->getCatalogueVersion();
if(catalogueVersion.getStatus<SchemaVersion::Status>() == SchemaVersion::Status::UPGRADING){
......@@ -102,6 +102,17 @@ SchemaCheckerResult SchemaChecker::checkTableContainsColumns(const std::string&
return res;
}
SchemaCheckerResult SchemaChecker::warnProcedures() {
SchemaCheckerResult res;
std::list<std::string> procedureNames = m_databaseMetadataGetter->getStoredProcedures();
for(auto procedure: procedureNames){
std::string warning = "PROCEDURE " + procedure + " exists in the " + m_databaseToCheckName + " database";
res.addWarning(warning);
}
return res;
}
/////////////////////////////////////////
// SchemaChecker::Builder
/////////////////////////////////////////
......
......@@ -55,24 +55,37 @@ public:
/**
* Checks if the catalogue database contains PARALLEL tables
* It will display a warning with the table name if this is the case
* @return a SchemaCheckerResult
* @return a SchemaCheckerResult containing the warnings
*/
SchemaCheckerResult checkNoParallelTables();
SchemaCheckerResult warnParallelTables();
/**
* Checks if the catalogue database schema is upgrading or not
* @return a SchemaCheckerResult containing the warnings
*/
SchemaCheckerResult checkSchemaNotUpgrading();
SchemaCheckerResult warnSchemaUpgrading();
/**
* Compare the schema tables whose names are located in the tableList parameter
* @param tableList the table names we would like to compare
* @return a Status OK or FAILURE
* @return a SchemaCheckerResult containing the errors
*/
SchemaCheckerResult compareTablesLocatedInSchema();
/**
* Checks if the table tableName contains the columns whose names are in the columnNames list
* @param tableName the tableName to check
* @param columnNames the columnName the tableName is supposed to have
* @return a SchemaCheckerResult containing the errors
*/
SchemaCheckerResult checkTableContainsColumns(const std::string &tableName, const std::list<std::string> columnNames);
/**
* Checks if there are stored procedures in the schema.
* @return a SchemaCheckerResult containing warnings if there are stored procedures.
*/
SchemaCheckerResult warnProcedures();
class Builder {
public:
Builder(const std::string databaseToCheckName, const cta::rdbms::Login::DbType dbType, cta::rdbms::Conn &conn);
......
......@@ -81,8 +81,9 @@ int VerifySchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar
.build());
SchemaCheckerResult result = schemaChecker->displayingCompareSchema(std::cout,std::cerr);
result += schemaChecker->checkNoParallelTables();
result += schemaChecker->checkSchemaNotUpgrading();
result += schemaChecker->warnParallelTables();
result += schemaChecker->warnSchemaUpgrading();
result += schemaChecker->warnProcedures();
result.displayWarnings(std::cout);
if(result.getStatus() == SchemaCheckerResult::Status::FAILED){
return 1;
......
......@@ -252,5 +252,16 @@ std::list<std::string> Conn::getConstraintNames(const std::string &tableName) {
}
}
//------------------------------------------------------------------------------
// getStoredProcedureNames
//------------------------------------------------------------------------------
std::list<std::string> Conn::getStoredProcedureNames(){
if(nullptr != m_connAndStmts && nullptr != m_connAndStmts->conn) {
return m_connAndStmts->conn->getStoredProcedureNames();
} else {
throw exception::Exception(std::string(__FUNCTION__) + " failed: Conn does not contain a connection");
}
}
} // namespace rdbms
} // namespace cta
......@@ -221,6 +221,16 @@ public:
*/
std::list<std::string> getConstraintNames(const std::string &tableName);
/**
* Returns the stored procedure names of the database
*
* If the underlying database technologies does not support stored procedures informations
* this method simply returns an empty list.
*
* @return the list of the names of the stored procedures in the database
*/
std::list<std::string> getStoredProcedureNames();
/**
* Get a pointer to the connection wrapper implementation
*
......
......@@ -166,6 +166,17 @@ public:
* @return the list of the names of the constraints that the given table has.
*/
virtual std::list<std::string> getConstraintNames(const std::string &tableName) = 0;
/**
*
* Returns the stored procedure names of the database
*
* If the underlying database technologies does not support stored procedures informations
* this method simply returns an empty list.
*
* @return the list of the names of the stored procedures in the database
*/
virtual std::list<std::string> getStoredProcedureNames() = 0;
}; // class ConnWrapper
......
......@@ -352,6 +352,13 @@ std::list<std::string> MysqlConn::getConstraintNames(const std::string& tableNam
return std::list<std::string>();
}
//------------------------------------------------------------------------------
// getStoredProcedureNames
//------------------------------------------------------------------------------
std::list<std::string> MysqlConn::getStoredProcedureNames() {
return std::list<std::string>();
}
} // namespace wrapper
} // namespace rdbms
} // namespace cta
......@@ -185,11 +185,26 @@ public:
/**
* Returns the Constraint names of a given table in the database schema
*
* If the underlying database technologies does not support constraint
* then this method simply returns an empty list.
*
* @param tableName the table name to get the constraint names from
* @return the list of the names of the constraints that the given table has.
*/
std::list<std::string> getConstraintNames(const std::string &tableName) override;
/**
*
* Returns the stored procedure names of the database
*
* If the underlying database technologies does not support stored procedures informations
* this method simply returns an empty list.
*
* @return the list of the names of the stored procedures in the database
*/
std::list<std::string> getStoredProcedureNames() override;
private:
/**
......
......@@ -338,6 +338,30 @@ std::list<std::string> OcciConn::getConstraintNames(const std::string& tableName
}
}
//------------------------------------------------------------------------------
// getStoredProcedureNames
//------------------------------------------------------------------------------
std::list<std::string> OcciConn::getStoredProcedureNames() {
try {
std::list<std::string> names;
const char *const sql =
"SELECT "
"OBJECT_NAME "
"FROM "
"USER_PROCEDURES";
auto stmt = createStmt(sql);
auto rset = stmt->executeQuery();
while (rset->next()) {
auto name = rset->columnOptionalString("OBJECT_NAME");
names.push_back(name.value());
}
return names;
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
//------------------------------------------------------------------------------
// isOpen
//------------------------------------------------------------------------------
......
......@@ -176,6 +176,18 @@ public:
* @return the list of the names of the constraints that the given table has.
*/
std::list<std::string> getConstraintNames(const std::string &tableName) override;
/**
*
* Returns the stored procedure names of the database
*
* If the underlying database technologies does not support stored procedures informations
* this method simply returns an empty list.
*
* @return the list of the names of the stored procedures in the database
*/
std::list<std::string> getStoredProcedureNames() override;
private:
friend OcciStmt;
......
......@@ -362,6 +362,14 @@ std::list<std::string> PostgresConn::getConstraintNames(const std::string& table
}
}
//------------------------------------------------------------------------------
// getStoredProcedureNames
//------------------------------------------------------------------------------
std::list<std::string> PostgresConn::getStoredProcedureNames() {
return std::list<std::string>();
}
//------------------------------------------------------------------------------
// isOpen
//------------------------------------------------------------------------------
......
......@@ -130,6 +130,17 @@ public:
*/
std::list<std::string> getConstraintNames(const std::string &tableName) override;
/**
*
* Returns the stored procedure names of the database
*
* If the underlying database technologies does not support stored procedures informations
* this method simply returns an empty list.
*
* @return the list of the names of the stored procedures in the database
*/
std::list<std::string> getStoredProcedureNames() override;
/**
* Returns the names of all the column and their type as a map for the given
* table in the database schema.
......
......@@ -431,8 +431,17 @@ std::list<std::string> SqliteConn::getConstraintNames(const std::string &tableNa
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
//------------------------------------------------------------------------------
// getStoredProcedureNames
//------------------------------------------------------------------------------
std::list<std::string> SqliteConn::getStoredProcedureNames() {
return std::list<std::string>();
}
} // namespace wrapper
} // namespace rdbms
} // namespace cta
......@@ -179,6 +179,18 @@ public:
*/
std::list<std::string> getConstraintNames(const std::string &tableName) override;
/**
*
* Returns the stored procedure names of the database
*
* If the underlying database technologies does not support stored procedures informations
* this method simply returns an empty list.
*
* @return the list of the names of the stored procedures in the database
*/
std::list<std::string> getStoredProcedureNames() override;
/**
* This is an SqliteConn specific method that prints the database schema to
* the specified output stream.
......
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