Firebird DB Create
Delphi Fdconnection nesnesi ile firebird database oluşturmak için kullandığım kod parçası.
function CreateFirebirdDB(const ClientLibPath :string;
const DbPath:string;
const Username:string;
const Password:string;
const Dialect :SmallInt=3;
const CharacterSet :string ='UTF8';
const Page_Size:integer=16384;
DefCharacterSet:string ='UTF8'):Boolean;
var
FdConn :TFDConnection;
FdScript :TFDScript;
sVal :string;
begin
sVal := '';
sVal := sVal +'SET SQL DIALECT '+Dialect.ToString+sLineBreak;
sVal := sVal +'SET NAMES '+CharacterSet+';'+sLineBreak;
sVal := sVal +'SET CLIENTLIB '+QuotedStr(ClientLibPath)+';'+sLineBreak;
sVal := sVal +'CREATE DATABASE '+QuotedStr(DbPath)+sLineBreak;
sVal := sVal +'USER '+QuotedStr(Username)+' PASSWORD '+QuotedStr(Password)+sLineBreak;
sVal := sVal +'PAGE_SIZE '+IntToStr(Page_Size)+sLineBreak;
sVal := sVal +'DEFAULT CHARACTER SET '+DefCharacterSet+';'+sLineBreak;
sVal := sVal +'SET TERM ^ ;';
FdConn := TFDConnection.Create(nil);
FdScript := TFDScript.Create(nil);
try
FdConn.DriverName := 'FB';
FdScript.Connection := FdConn;
FdScript.SQLScripts.Add;
FdScript.SQLScripts.Items[0].SQL.Add(sVal);
FdScript.ExecuteAll;
Result := CreateTestFb(DbPath,Username,Password);
finally
FdConn.Free;
FdScript.Free;
end;
end;
function CreateTestFb (const DbPath:string; const Username:string; const Password:string):Boolean;
var
conn : TFDConnection;
begin
conn := TFDConnection.Create(nil);
try
try
conn.DriverName:='FB';
conn.Params.Database := DbPath;
conn.Params.UserName := Username;
conn.Params.Password := Password;
conn.Connected := True;
if conn.Connected then Result := True
except
on e: Exception do
begin
showmessage(E.ClassName+' error raised, with message : '+E.Message);
Result := False;
end;
end;
finally
conn.Free;
end;
end;