Skip to content
Snippets Groups Projects
Commit 97cd87bc authored by Victor Kotlyar's avatar Victor Kotlyar Committed by Michael Davis
Browse files

Add implementation of getIndexNames for Mysql DB.

parent 659e6e46
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ namespace catalogue {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
MysqlCatalogueSchema::MysqlCatalogueSchema(): sql(
MysqlCatalogueSchema::MysqlCatalogueSchema(): CatalogueSchema(
// CTA_SQL_SCHEMA - The contents of sqlite_catalogue_schema.cpp go here
), sql_trigger(
// CTA_SQL_TRIGGER - The contents of mysql_catalogue_schema_trigger.cpp go here
......
......@@ -18,6 +18,8 @@
#pragma once
#include "CatalogueSchema.hpp"
#include <string>
#include <vector>
......@@ -39,17 +41,12 @@ namespace catalogue {
* The purpose of this class is to help IDEs by isolating the "non-compilable"
* issues into a small cpp file.
*/
struct MysqlCatalogueSchema {
struct MysqlCatalogueSchema: public CatalogueSchema {
/**
* Constructor.
*/
MysqlCatalogueSchema();
/**
* The schema.
*/
const std::string sql;
/**
* The trigger.
*/
......
......@@ -94,8 +94,17 @@ int VerifySchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar
break;
case rdbms::Login::DBTYPE_MYSQL:
{
// TODO
//MysqlCatalogueSchema schema;
// TODO
MysqlCatalogueSchema schema;
std::cerr << "Checking table names..." << std::endl;
const auto schemaTableNames = schema.getSchemaTableNames();
const auto dbTableNames = conn.getTableNames();
std::cerr << "error code: "<< static_cast<int>(verifyTableNames(schemaTableNames, dbTableNames)) << std::endl;
std::cerr << "Checking index names..." << std::endl;
const auto schemaIndexNames = schema.getSchemaIndexNames();
const auto dbIndexNames = conn.getIndexNames();
std::cerr << "error code: "<< static_cast<int>(verifyIndexNames(schemaIndexNames, dbIndexNames)) << std::endl;
//conn.executeNonQueries(schema.sql);
// execute triggers
......@@ -177,6 +186,10 @@ VerifySchemaCmd::VerifyStatus VerifySchemaCmd::verifyTableNames(const std::list<
}
}
}
if (status != VerifyStatus::WARNING && status != VerifyStatus::ERROR) {
std::cerr << " OK: no problems found" << std::endl;
status = VerifyStatus::OK;
}
return status;
}
......@@ -204,6 +217,10 @@ VerifySchemaCmd::VerifyStatus VerifySchemaCmd::verifyIndexNames(const std::list<
}
}
}
if (status != VerifyStatus::WARNING && status != VerifyStatus::ERROR) {
std::cerr << " OK: no problems found" << std::endl;
status = VerifyStatus::OK;
}
return status;
}
......
......@@ -27,7 +27,7 @@
#
# or:
#
# mysql://username:passord@hostname[:port]/database
# mysql://username:password@hostname[:port]/database
#
# or:
#
......
......@@ -232,9 +232,30 @@ std::list<std::string> MysqlConn::getTableNames() {
// getIndexNames
//------------------------------------------------------------------------------
std::list<std::string> MysqlConn::getIndexNames() {
std::list<std::string> names;
// TODO
return names;
try {
std::list<std::string> names;
const char *const sql =
"SELECT DISTINCT "
"INDEX_NAME "
"FROM "
"INFORMATION_SCHEMA.STATISTICS "
"WHERE "
"Non_unique=1 "
"ORDER BY "
"INDEX_NAME";
auto stmt = createStmt(sql);
auto rset = stmt->executeQuery();
while (rset->next()) {
auto name = rset->columnOptionalString("INDEX_NAME");
if(name) {
names.push_back(name.value());
}
}
return names;
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
//------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment