1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-29 15:47:46 +00:00

More dbm...

This commit is contained in:
Mordred 2018-12-08 01:11:46 +01:00
parent fc56a48731
commit 43892f7add
2 changed files with 31 additions and 10 deletions

View file

@ -123,18 +123,39 @@ bool DbManager::modeInit()
const std::string insertFile = "sql/schema/inserts.sql"; const std::string insertFile = "sql/schema/inserts.sql";
bool result = false; bool result = false;
bool dbCreated = false;
if( selectSchema() ) if( selectSchema() )
{ {
// TODO: allow init if database is empty std::string query = "SELECT COUNT(*) "
// select count(*) "FROM information_schema.tables "
// from information_schema.tables "WHERE table_type = 'BASE TABLE' "
// where table_type = 'BASE TABLE' "AND table_schema = '" + m_database + "';";
// and table_schema = 'your_database_name_here' dbCreated = true;
m_lastError = "Database already existing, use <liquidate> mode first to remove it."; try
{
auto stmt = m_pConnection->createStatement();
auto resultSet = stmt->executeQuery( query );
if( !resultSet->next() )
return false;
auto count = resultSet->getUInt( 1 );
if( count )
{
m_lastError = "Database " + m_database + " still contains tables. <Liquidate> it first!";
return false; return false;
} }
}
catch( std::runtime_error& e )
{
m_lastError = e.what();
return false;
}
}
if( !dbCreated )
if( !execute( "CREATE DATABASE " + m_database ) ) if( !execute( "CREATE DATABASE " + m_database ) )
return false; return false;