mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 796724 - Can't overwrite gnucash DB on MariaDB
This commit is contained in:
parent
f067e8328e
commit
875781847a
@ -652,8 +652,24 @@ GncDbiBackend<Type>::session_begin (QofSession* session, const char* book_id,
|
||||
LEAVE("Error");
|
||||
return;
|
||||
}
|
||||
if (create && !force && save_may_clobber_data (conn,
|
||||
uri.quote_dbname(Type)))
|
||||
if (create && save_may_clobber_data (conn, uri.quote_dbname(Type)))
|
||||
{
|
||||
if (force)
|
||||
{
|
||||
// Drop DB
|
||||
if (Type == DbType::DBI_PGSQL)
|
||||
dbi_conn_select_db (conn, "template1");
|
||||
else if (Type == DbType::DBI_MYSQL)
|
||||
dbi_conn_select_db (conn, "mysql");
|
||||
else
|
||||
PWARN ("Unknown database type, don't know how to connect to a system database. Dropping existing database may fail.");
|
||||
|
||||
if (!dbi_conn_queryf (conn, "DROP DATABASE %s",
|
||||
uri.quote_dbname(Type).c_str()))
|
||||
PWARN ("Failed to drop database %s prior to recreating it. Creation will likely fail.",
|
||||
uri.quote_dbname(Type).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
set_error (ERR_BACKEND_STORE_EXISTS);
|
||||
PWARN ("Databse already exists, Might clobber it.");
|
||||
@ -661,12 +677,10 @@ GncDbiBackend<Type>::session_begin (QofSession* session, const char* book_id,
|
||||
LEAVE("Error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (m_exists)
|
||||
else if (m_exists)
|
||||
{
|
||||
PERR ("Unable to connect to database '%s'\n", uri.dbname());
|
||||
set_error (ERR_BACKEND_SERVER_ERR);
|
||||
@ -674,6 +688,15 @@ GncDbiBackend<Type>::session_begin (QofSession* session, const char* book_id,
|
||||
LEAVE("Error");
|
||||
return;
|
||||
}
|
||||
else if (!create)
|
||||
{
|
||||
PERR ("Database '%s' does not exist\n", uri.dbname());
|
||||
set_error(ERR_BACKEND_NO_SUCH_DB);
|
||||
std::string msg{"Database "};
|
||||
set_message(msg + uri.dbname() + " not found");
|
||||
LEAVE("Error");
|
||||
return;
|
||||
}
|
||||
|
||||
if (create)
|
||||
{
|
||||
@ -705,13 +728,6 @@ GncDbiBackend<Type>::session_begin (QofSession* session, const char* book_id,
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
set_error(ERR_BACKEND_NO_SUCH_DB);
|
||||
std::string msg{"Database "};
|
||||
set_message(msg + uri.dbname() + " not found");
|
||||
}
|
||||
}
|
||||
|
||||
connect(nullptr);
|
||||
try
|
||||
|
Loading…
Reference in New Issue
Block a user