Page 1 of 1

ZeosLib and Delphi XE7 - new database

Posted: 11.01.2017, 02:20
by Alancj
I'm attempting to set up an app that starts up when the user first activates the software. The first task is to create the system's database. Bluntly - I'm getting no where. The database is MySQL5.5

As far as I can figure I'm doing what needs to be done. But nothing happens.

I'm using a ZConnection component.

Autocommit is off. The hostname is LocalHost - because the first installation must be activated on the server PC. The user is "root" and their password is also "root". The MySQL libraries are being found no trouble.

The code is as follows:

with ZConnection1 do
begin
try
Connect;
Properties.Add('CreateNewDatabase=CREATE DATABASE' + QuotedStr('test1') + 'IF NOT EXISTS' + 'DEFAULT CHARACTER SET UTF8');
Commit;

except
Properties.Clear;
Connect;
end;
end;

No error is triggered. But no database is created either.

Any assistance would be appreciated.

Thanks

Alan

Re: ZeosLib and Delphi XE7 - new database

Posted: 11.01.2017, 16:15
by marsupilami
Hello Alan,

the CreateNewDatabase parameter only exists for the Interbase and Firebird drivers. The MySQL driver ignores this parameter. Why don't you connect to the mysql database, create your database and then disconnect and reconnect to your new database?
Something like this is on my mind:

Code: Select all

with ZConnection1 do
begin
  try
    Database := 'mysql';
    Connect;
    ExecuteDirect('CREATE DATABASE ' + QuotedStr('test1') + ' IF NOT EXISTS ' + ' DEFAULT CHARACTER SET UTF8';
    Commit;
    Disconnect;
    
    Database := 'test1';
    Connect;
  except
    if Active then Rollback;
    Disconnect;
    Raise;
  end;
end;

Re: ZeosLib and Delphi XE7 - new database

Posted: 24.11.2017, 02:32
by Alancj
THanks for that. Sorry it took so long to get back. But we've been busy redeveloping the code.

Alan