| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- unit AppIcon;
- interface
- uses
- System.Classes, BaseDataProvider, InterfaceDataProvider;
- type
- TAppIconProvider = class(TBaseDataProvider, IAppIconProvider)
- protected
- function GetTableName: string; override;
- function GetCreateTableSQL: string; override;
- public
- procedure Insert(AAppKey: WideString; var ABuffer); stdcall;
- procedure FindIcon(AAppKey: WideString; var ABuffer); stdcall;
- end;
- implementation
- uses
- FireDAC.Comp.Client, BaseDataModule, System.SysUtils, System.VarUtils, System.Variants,
- Data.DB, LoggerImport;
- const
- APPICON_TABLE_NAME: string = 'AppIcons';
- APPICON_CREATE_TABLE: string = 'CREATE TABLE AppIcons('+
- 'AppKey string(50), ' +
- 'Icon BLOB, ' +
- 'Version Integer, ' +
- 'CreateTime Double)';
- APPICON_INSERT: string = 'INSERT INTO AppIcons(AppKey, Icon, Version, CreateTime) VALUES(:appkey, :icon, :version, :createTime)';
- APPICON_DELETE: string = 'DELETE FROM AppIcons WHERE AppKey = :appkey';
- APPICON_FINDICON: string = 'SELECT Icon FROM AppIcons WHERE AppKey = :appkey';
- { TAppIconProvider }
- procedure TAppIconProvider.FindIcon(AAppKey: WideString; var ABuffer); stdcall;
- var
- AQuery: TFDQuery;
- ACode: string;
- begin
- if not Inited and not ReInit then
- Exit;
- if (AAppKey = '') then
- Exit;
- ACode := Format('TAppIconProvider.FindIcon(%s)', [AAppKey]);
- try
- AQuery := BaseDataModel.GetQuery;
- if AQuery = nil then
- Exit;
- AQuery.Connection.Connected := True;
- AQuery.Open(APPICON_FINDICON, [AAppKey]);
- AQuery.First;
- if not AQuery.Eof then
- TBytes(ABuffer) := AQuery.FieldByName('Icon').AsBytes;
- except
- on E: Exception do
- begin
- Error(E.Message, ACode);
- BaseDataModel.GiveBackQuery(AQuery);
- end;
- end;
- BaseDataModel.GiveBackQuery(AQuery);
- end;
- function TAppIconProvider.GetCreateTableSQL: string;
- begin
- Result := APPICON_CREATE_TABLE;
- end;
- function TAppIconProvider.GetTableName: string;
- begin
- Result := APPICON_TABLE_NAME;
- end;
- procedure TAppIconProvider.Insert(AAppKey: WideString; var ABuffer);
- var
- AConnection: TFDCustomConnection;
- ALen: Cardinal;
- begin
- if not Inited and not ReInit then
- Exit;
- ALen := Length(TBytes(ABuffer));
- if (AAppKey = '') or (ALen = 0) then
- Exit;
- AConnection := BaseDataModel.GetConnection;
- if AConnection = nil then
- Exit;
- try
- AConnection.Connected := True;
- AConnection.ExecSQL(APPICON_DELETE, [AAppKey]);
- AConnection.ExecSQL(APPICON_INSERT, [AAppKey, TBytes(ABuffer), 0, Now]);
- finally
- BaseDataModel.GiveBackConnection(AConnection);
- end;
- end;
- end.
|