📄 boldpersistencehandlemysql.pas
字号:
/////////////////////////////////////////////////////////
// //
// Bold for Delphi //
// Copyright (c) 2003 Borland //
// //
/////////////////////////////////////////////////////////
{ Global compiler directives }
{$include bold.inc}
unit BoldPersistenceHandleMYSQL;
interface
uses
Classes,
mySQLDbTables,
BoldDBInterfaces,
BoldDatabaseAdapterMYSQL,
BoldPersistenceHandleDB,
BoldPersistenceHandleDB_deprecated,
BoldMYSQLInterfaces;
type
{ forward declarations }
TBoldPersistenceHandleMYSQL = class;
{ TBoldPersistenceHandleMYSQL }
TBoldPersistenceHandleMYSQL = class(TBoldDBPersistenceHandle)
private
FDatabaseName: string;
FSDDatabase: TmySQLDatabase;
FDatabaseAdapter: TBoldMYSQLDatabase;
FEffectiveDataBase: TmySQLDatabase;
function GetEffectiveDatabase: TmySQLDatabase;
procedure SetDatabaseAdapter(const Value: TBoldMYSQLDatabase);
procedure SetDatabase(const Value: TmySQLDatabase);
procedure SetDatabaseName(const Value: string);
procedure SetEffectiveDatabase(const Value: TmySQLDatabase);
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
property DatabaseAdapter: TBoldMYSQLDatabase read FDatabaseAdapter write SetDatabaseAdapter;
property EffectiveDatabase: TmySQLDatabase read GetEffectiveDatabase write SetEffectiveDatabase;
{$IFNDEF T2H}
procedure InternalTransferproperties(const target: TBoldPersistenceHandleDB); override;
{$ENDIF}
public
destructor destroy; override;
function GetDataBaseInterface: IBoldDatabase; override;
published
property DatabaseName: string read FDatabaseName write SetDatabaseName;
property SDDatabase: TmySQLDatabase read FSDDatabase write SetDatabase;
end deprecated;
implementation
uses
Dialogs,
SysUtils,
BoldRev;
{ TBoldPersistenceHandleMYSQL }
destructor TBoldPersistenceHandleMYSQL.destroy;
begin
Active := false;
FreeAndNil(FEffectiveDatabase);
FreeAndNil(FDatabaseAdapter);
inherited;
end;
function TBoldPersistenceHandleMYSQL.GetDataBaseInterface: IBoldDatabase;
begin
if not assigned(FDatabaseAdapter) then
FDatabaseAdapter := TBoldMYSQLDatabase.create(EffectiveDatabase, SQLDataBaseConfig);
result := FDataBaseAdapter;
end;
function TBoldPersistenceHandleMYSQL.GetEffectiveDatabase: TmySQLDatabase;
begin
if assigned(FSDDatabase) then
result := FSDDatabase
else
raise Exception.CreateFmt('%s.GetEffectiveDatabase: SDDatabase property must be assigned', [ClassName]);
end;
procedure TBoldPersistenceHandleMYSQL.InternalTransferproperties(
const target: TBoldPersistenceHandleDB);
var
Adapter: TBoldDatabaseAdapterMYSQL;
DesInfo: longint;
begin
inherited;
DesInfo := Target.DesignInfo;
if not assigned(Target.DatabaseAdapter) then
begin
Target.DatabaseAdapter := TBoldDatabaseAdapterMYSQL.Create(Target.Owner);
Target.DatabaseAdapter.Name := GetNewComponentName(Target.DatabaseAdapter, 'BoldDatabaseAdapterMYSQL');
LongRec(DesInfo).Lo := LongRec(DesInfo).lo+16;
LongRec(DesInfo).Hi := LongRec(DesInfo).hi+16;
Target.DatabaseAdapter.DesignInfo := DesInfo;
showmessage('Created a new DatabaseAdapterMYSQL');
end
else if not (target.DatabaseAdapter is tBoldDatabaseAdapterMYSQL) then
raise Exception.CreateFmt('The persistencehandle is connected to a %s, properties can only be transfered to a TBoldDatabaseAdapterMYSQL', [target.DatabaseAdapter.ClassName] );
Adapter := target.DatabaseAdapter as tBoldDatabaseAdapterMYSQL;
if assigned(SDDatabase) then
Adapter.DataBase := SDDatabase;
if not assigned(Adapter.Database) then
begin
Adapter.DataBase := TmySQLDatabase.Create(Target.owner);
Adapter.DataBase.Name := GetNewComponentName(Adapter.DataBase, 'SDDatabase');
showmessage('Created a new Database');
LongRec(DesInfo).Lo := LongRec(DesInfo).lo+16;
LongRec(DesInfo).Hi := LongRec(DesInfo).hi+16;
Adapter.DataBase.DesignInfo := DesInfo;
end;
end;
procedure TBoldPersistenceHandleMYSQL.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited;
if (aComponent = FSDDatabase) and (Operation = opRemove) then
begin
if aComponent = EffectiveDatabase then
begin
Active := false;
FDatabaseAdapter := nil;
end;
FSDDatabase := nil;
end;
end;
procedure TBoldPersistenceHandleMYSQL.SetDataBase(const Value: TmySQLDatabase);
begin
if FSDDatabase <> Value then
begin
if assigned(FEffectiveDatabase) then
begin
FreeAndNil(FEffectiveDatabase);
FreeAndNil(FDatabaseAdapter);
end;
FSDDatabase := Value;
if assigned(FSDDatabase) then
FSDDatabase.FreeNotification(self);
end;
end;
procedure TBoldPersistenceHandleMYSQL.SetDatabaseAdapter(const Value: TBoldMYSQLDatabase);
begin
FDatabaseAdapter := Value;
end;
procedure TBoldPersistenceHandleMYSQL.SetDatabaseName(const Value: string);
begin
FDatabaseName := Value;
end;
procedure TBoldPersistenceHandleMYSQL.SetEffectiveDataBase(const Value: TmySQLDatabase);
begin
FEffectiveDatabase := Value;
end;
initialization
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -