문제

dbexpress를 사용하여 프로그래밍 방식으로 Firebird 데이터베이스를 만들어야합니다. SQL Server에 대해 먼저 마스터에 연결 한 다음 스크립트를 쿼리에 전달하여 쿼리에 전달했지만 Firebird에는 작은 닭고기와 계란 문제가 있습니다.

도움이 되었습니까?

해결책

I got a good tip from a collegue that created some code for the Freepascal project. It doesn't use DB express, but according to him it is the only way to create a database with code. This code is based on the InterBase manual, and uses a call from the gdslib / fbclient dll:

procedure TIBConnection.CreateDB;

var ASQLDatabaseHandle,
    ASQLTransactionHandle : pointer;
    CreateSQL : String;
    pagesize : String;
begin
  CheckDisConnected;
  {$IfDef LinkDynamically}
    InitialiseIBase60;
  {$EndIf}
  ASQLDatabaseHandle := nil;
  ASQLTransactionHandle := nil;
  CreateSQL := 'CREATE DATABASE ';
  if HostName <> '' then
    CreateSQL := CreateSQL + ''''+ HostName+':'+DatabaseName + ''''
  else
    CreateSQL := CreateSQL + '''' + DatabaseName + '''';

  if UserName <> '' then
    CreateSQL := CreateSQL + ' USER ''' + Username + '''';
  if Password <> '' then
    CreateSQL := CreateSQL + ' PASSWORD ''' + Password + '''';
  pagesize := params.Values['PAGE_SIZE'];
  if pagesize <> '' then
    CreateSQL := CreateSQL + ' PAGE_SIZE '+pagesize;

  if isc_dsql_execute_immediate(@FStatus[0],@ASQLDatabaseHandle,@ASQLTransactionHandle,length(CreateSQL),@CreateSQL[1],Dialect,nil) <> 0 then
    CheckError('CreateDB', FStatus);

  if isc_detach_database(@FStatus[0], @ASQLDatabaseHandle) <> 0 then
    CheckError('CreateDB', FStatus);

  {$IfDef LinkDynamically}
    ReleaseIBase60;
  {$EndIf}
end;

The trick is the isc_dsql_execute_immediate function. I hope this code helps you. Here are the links to the Freepascal source files where this code comes from:

Unit containing CreateDB function

Unit containing API call isc_dsql_execute_immediate

다른 팁

Run a script isql

isql-i createDB.sql

CreateDB.sql the file includes the command to create the database as shown below.

SET SQL DIALECT 3;
CREATE DATABASE 'C:\DATABASE\DB.FDB'
USER 'SYSDBA' PASSWORD 'masterkey'
PAGE_SIZE 4096
DEFAULT CHARACTER SET WIN1252;
QUIT;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top