CreateDatabase method

Previous  Top  Next

See Also Properties Methods Events Example
Unit
MySQLServer

Applies to
TMySQLServer component

Declaration
procedure CreateDatabase(Value: string; Conn: pointer = nil); overload;
function  CreateDatabase(const AExecSQL: boolean=False): string; overload;

Description
These two function may have the same name, but they perform almost completely different functions.

The first CreateDatabase takes a Value parameter detonating the new database's name. The Conn parameter is optional and if left at nil, will use the TMySQLServer's connection to the MySQL server to actually create the new database, i.e. "CREATE DATABASE Value;"

The second CreateDatabase will do the following:
1.Form a "CREATE DATABASE IF NOT EXISTS" statement using the current DatabaseName property value.  
2.Collect all CreateTable SQL statements from all dynamically created datasets which have the Option doAutoCreateTable set.  
3.Collect all CreateTable SQL statements from all TMySQLDataset\Query\Table components that use this TMySQLServer (via their Server property) which have the Option doAutoCreateTable set.  
4.If AExecSQL is True, the TMySQLServer component will use ExecSQLBatch to send all collected SQL to the MySQL Server and in so doing your database with all tables/table structures in it will be recreated from scratch.  

If soDropIfExists is enabled in the Options, then the compiled script will be prefixed with a "drop database if exists"

If AExecSQL is False (default), then you can get the complete SQL script as the result of this call to use as you please. Maybe to save your complete database structure to a backup file?

Of course, the main purpose of the second CreateDatabase is to allow you to develop a complete application, have your end-user install it on their machine and when your application runs, all the end-user has to specify is the MySQL server to use. If your soAutoCreate Option is specified, your TMySQLServer will automatically try to recreate the complete database and table structures your application expects to find when it connects. Another added benefit is that you can design your complete database right within the Delphi/Kylix IDE.