IBX.IBDatabase.TIBDatabase.CreateDatabase

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure CreateDatabase;

C++

void __fastcall CreateDatabase();

Properties

Type Visibility Source Unit Parent
procedure
function
public
IBX.IBDatabase.pas
IBX.IBDatabase.hpp
IBX.IBDatabase TIBDatabase

Description

Creates a database using Params.

Call CreateDatabase to create a database using Params as the rest of the CREATE DATABASE command.

For example, if you want to create a local InterBase database, you can do the following:

  1. Set the database name to the drive, path, and filename of the database file.
  2. Set Params to the parameter for the CREATE DATABASE statement: USER "SYSDBA" PASSWORD "masterkey" PAGE_SIZE 4096
  3. Set the SQLDialect value.
  4. Call the CreateDatabase method.

Here are examples of how to call the CreateDatabase procedure:

Delphi:

CreateDatabase('localhost','C:\ProgramData\Embarcadero\InterBase\gds_db\examples\database\test.ib');

C++:

 createDatabase("localhost", "C:\\ProgramData\\Embarcadero\\InterBase\\gds_db\\examples\\database\\test.ib");

The following are Delphi and C++ examples of programmatically using CreateDatabase.

Example (Delphi)

Procedure CreateDatabase(ServerName,RemotePath: string);
var
  IBDatabaseTest: TIBDatabase;
begin
  IBDatabaseTest := TIBDatabase.Create(nil);
  try
    try
      IBDatabaseTest.DatabaseName := ServerName + ':' + RemotePath;
      IBDatabaseTest.SQLDialect := 3;
      IBDatabaseTest.Params.Clear;
      IBDatabaseTest.Params.Add('USER "SYSDBA"');
      IBDatabaseTest.Params.Add('PASSWORD "masterkey"');
      IBDatabaseTest.Params.Add('PAGE_SIZE 4096');
      IBDatabaseTest.LoginPrompt := False;
      IBDatabaseTest.CreateDatabase;
    except
      on E: exception do
        Showmessage(E.ClassName + ': ' + E.Message);
    end;
  finally
    IBDatabaseTest.Free;
  end;
end;

Example (C++)

void createDatabase(UnicodeString ServerName, UnicodeString RemotePath) {
	TIBDatabase *IBDatabaseTest = new TIBDatabase(NULL);
		try {
		IBDatabaseTest->DatabaseName = ServerName + ":" + RemotePath;
		IBDatabaseTest->SQLDialect = 3;
		IBDatabaseTest->Params->Clear();
		IBDatabaseTest->Params->Add("USER \"SYSDBA\"");
		IBDatabaseTest->Params->Add("PASSWORD \"masterkey\"");
		IBDatabaseTest->Params->Add("PAGE_SIZE 4096");
		IBDatabaseTest->LoginPrompt = false;
		IBDatabaseTest->CreateDatabase();
	}
	catch (Exception &e) {
		ShowMessage(e.ClassName()+":"+e.Message);
	}

}

See Also