Recent

Author Topic: How connect to MySQL database without database name with sqldb?  (Read 2077 times)

aradeonas

  • Hero Member
  • *****
  • Posts: 824
It will use for many purposes but I want it to Drop databse and create it and DropDB function atleaste for MySQL used this :
Quote
DROP DATABASE
But I like to do this :
Quote
DROP DATABASE IF EXISTS   

balazsszekely

  • Guest
Re: How connect to MySQL database without database name with sqldb?
« Reply #1 on: April 30, 2016, 10:06:35 am »
Quote
@aradeonas
How connect to MySQL database without database name with sqldb
You can't! Fortunately "information_schema" is always present. It holds details about all the other databases on the server such as the names and types of tables, columns and users. So you connect to "information_schema" then execute whatever query you like:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   MySQL55Connection1.UserName := '';
  4.   MySQL55Connection1.Password := '';
  5.   MySQL55Connection1.DatabaseName := 'information_schema';
  6.   MySQL55Connection1.HostName := 'localhost';
  7.   //...
  8.   MySQL55Connection1.Connected := True;
  9.   MySQL55Connection1.ExecuteDirect('DROP DATABASE TEST');
  10.   SQLTransaction1.CommitRetaining;
  11. end;

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Re: How connect to MySQL database without database name with sqldb?
« Reply #2 on: April 30, 2016, 11:42:19 am »
Quote
You can't! Fortunately
Bummer! So it seems a bug because there is a need for that.
Quote
Fortunately "information_schema" is always present. It holds details about all the other databases on the server such as the names and types of tables, columns and users. So you connect to "information_schema" then execute whatever query you like
Good point! thanks.

 

TinyPortal © 2005-2018