I have been a very happy Devart Delphi MySQL access components for many years, not a very GOOD user, I admit, but what I've previously written worked, and worked well.
Now I have been asked to add new functionality to my program, specifically creating code that will allow the program to determine if the database I access exists, and if it doesn't create it, create a user if one doesn't exist, assign privileges, and create all the tables, if they don't exist. Since the code is still under active development, I have a habit of adding new tables occasionally, and to be able to detect its non-existence and create a new table would also be good.
Previously, all this sort of thing I manage from MySQL administrator. I configured each of the bespoke machines individually, no problem.
I have managed to write a snippet that creates an instance of Tmyconnection to check if the DB exists, in the project level of my app, expecting I could access it in the application proper, instead of the component Tmyconnection I used in my main app, but it seems to be only local to the project code.
How else can I do this ? Tmycommand or Tmyscript have to be bound to an existing database connection.
Sorry to sound like a newbie, but I feel like one right now.
Steve
Bootstrapping my database
Re: Bootstrapping my database
Please write in more detail what is the essence of your question and what you mean by the phrase "to be only local to the project code".
-
- Posts: 3
- Joined: Tue 17 Apr 2018 18:49
Re: Bootstrapping my database
Imagine I have a completely clean system, with only a working MYSQL installation. I install my Delphi app, it detects that there is no DB, and it needs to create a DB, tables and a user. How do I do that ?
Re: Bootstrapping my database
To determine the existence of the database at the moment of connection, you can use the following code by preliminarily setting the TMyConnection.Database property to the required value:
To execute the required scripts for creating a database and its required objects, you can use the TMyScript component: devart.com/mydac/docs/devart.mydac.tmyscript.htm
Code: Select all
MyConnection.Database := 'DBName';
try
MyConnection.Connect;
except
on E: Exception do
if Pos('Unknown database', E.Message) < 0 then
ShowMessage('Database "DBName" does not exist')
else
raise;
end;
-
- Posts: 3
- Joined: Tue 17 Apr 2018 18:49
Re: Bootstrapping my database
Thanks Viktor,
That was the clue I needed. Many thanks
That was the clue I needed. Many thanks
Re: Bootstrapping my database
Thank you for the interest in our products.
If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.
If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.