mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-23 21:27:45 +00:00
More dbm...
This commit is contained in:
parent
c58edb540d
commit
de77e94e56
2 changed files with 31 additions and 10 deletions
2
deps/mysqlConnector/Statement.cpp
vendored
2
deps/mysqlConnector/Statement.cpp
vendored
|
@ -60,7 +60,7 @@ std::shared_ptr< Mysql::ResultSet > Mysql::Statement::getResultSet()
|
||||||
{
|
{
|
||||||
if( errNo() != 0 )
|
if( errNo() != 0 )
|
||||||
throw std::runtime_error( "Error during getResultSet() : " + std::to_string( errNo() ) + ": " +
|
throw std::runtime_error( "Error during getResultSet() : " + std::to_string( errNo() ) + ": " +
|
||||||
m_pConnection->getError() );
|
m_pConnection->getError() );
|
||||||
|
|
||||||
return std::make_shared< ResultSet >( mysql_store_result( m_pConnection->getRawCon() ), shared_from_this() );
|
return std::make_shared< ResultSet >( mysql_store_result( m_pConnection->getRawCon() ), shared_from_this() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,20 +123,41 @@ 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
|
||||||
return false;
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch( std::runtime_error& e )
|
||||||
|
{
|
||||||
|
m_lastError = e.what();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !execute( "CREATE DATABASE " + m_database ) )
|
if( !dbCreated )
|
||||||
return false;
|
if( !execute( "CREATE DATABASE " + m_database ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
if( !selectSchema() )
|
if( !selectSchema() )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue