Database existence checking before MyServerControl.CreateDatabase
Database existence checking before MyServerControl.CreateDatabase
Is there a way to have something like
If Exists(a_Database) then
MyServerControl1.CreateDatabase (a_Database) ?
Previously I tried a workaround with MyConnection.GetDatabseNames(a_List) but a_List remains NIL. What’s wrong ?
TIA
Philippe
If Exists(a_Database) then
MyServerControl1.CreateDatabase (a_Database) ?
Previously I tried a workaround with MyConnection.GetDatabseNames(a_List) but a_List remains NIL. What’s wrong ?
TIA
Philippe
Perhaps a better and faster way:
Replace the DATABASENAME with name you need, and mysql will create the database if it doesn't exists.
Code: Select all
myConnection.ExecSQL('create database if not exists DATABASENAME',[]);
"...specify a always existing database like mysql."
That's the workaround I use.
A little bit frustrating however.
A MySQL database is simply a directory, prone to accidental loss or destruction due to an external attack. A more rigourous verification of Database existence before any further processing would be wise.
Many thanks
Philippe
That's the workaround I use.
A little bit frustrating however.
A MySQL database is simply a directory, prone to accidental loss or destruction due to an external attack. A more rigourous verification of Database existence before any further processing would be wise.
Many thanks
Philippe
"...you can leave it blank..."
Yes in Object Inspector but not in Login Prompt which arise very early (maybe due to my TMyConnectDialog, but I did not check this enough...)
"if mysql database is somehow deleted, then you'll have bigger problems than creating new databses, you won't allow to login or do anything, since it's where user & privilege information is stored."
My application must survive in a downgraded mode in case something is wrong with MySQL, or at least offer to the system administrator a clear debugging guide. I try to have as few assumptions as possible about an external process availability, integrity and s.o.
Philippe
Yes in Object Inspector but not in Login Prompt which arise very early (maybe due to my TMyConnectDialog, but I did not check this enough...)
"if mysql database is somehow deleted, then you'll have bigger problems than creating new databses, you won't allow to login or do anything, since it's where user & privilege information is stored."
My application must survive in a downgraded mode in case something is wrong with MySQL, or at least offer to the system administrator a clear debugging guide. I try to have as few assumptions as possible about an external process availability, integrity and s.o.
Philippe
Second point, if mysql database is dropped, then you'll have to reinstall, i'm sure this is the smallest problem of all... You won't be able to connect if this database doesn't exist.
This is exactly where the problem is. I want the application regenerates itself the missing database - and this is the case at least with the first time run - but one cannot connect immediately to it. I expected TMyServerControl appropriate for that since it contains already CreateDatabase and DropDatabase...
Thanks J. Pieter for useful insight.
Philippe
This is exactly where the problem is. I want the application regenerates itself the missing database - and this is the case at least with the first time run - but one cannot connect immediately to it. I expected TMyServerControl appropriate for that since it contains already CreateDatabase and DropDatabase...
Thanks J. Pieter for useful insight.
Philippe
Geswin is almost rights.CreateDatabase method is a thin wrapper over CREATE DATABASE statement. So, there is no practical difference between their calls. Regarding the main problem, I can advise to use something like this:
Code: Select all
MyServerControl1.Connection := MyConnection1;
MyConnection1.Database := 'qwerty';
try
MyConnection1.Connect;
except
on E: EMyError do
if E.ErrorCode ER_BAD_DB_ERROR then
raise
else
begin
s := MyConnection1.Database;
MyConnection1.Database := '';
MyConnection1.Connect;
MyServerControl1.CreateDatabase(s);
MyConnection1.Database := s;
end;
end;