⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boldmysqlinterfaces.pas

📁 BDA mysql component for accessing mysql databases
💻 PAS
📖 第 1 页 / 共 2 页
字号:

/////////////////////////////////////////////////////////
//                                                     //
//            Bold MySQL DataBase Adapter              //
//           Copyright (c) 2006 Borland, Grikon        //
//                                                     //
/////////////////////////////////////////////////////////

{ Global compiler directives }

{$include bold.inc}

unit BoldMYSQLInterfaces;

                                   INTERFACE
uses
  Classes,
  Db, mySQLDbTables,
  BoldSQLDatabaseConfig,
  BoldDBInterfaces;
type
  { forward declarations }

  TBoldMYSQLParameter = class;
  TBoldMYSQLDatabase = class;
  TBoldMYSQLQuery = class;
  TBoldMYSQLQueryClass = class of TBoldMYSQLQuery;


  { TBoldMYSQLParameter }
  TBoldMYSQLParameter = class(TBoldParameterWrapper, IBoldParameter)
  private
    fParameter: TParam;
    function GetAsVariant: Variant;
    procedure SetAsVariant(const NewValue: Variant);
    function GetName: String;
    procedure Clear;
    function GetDataType: TFieldType;
    procedure SetDataType(Value: TFieldType);
    function GetAsBCD: Currency;
    function GetAsBoolean: Boolean;
    function GetAsDateTime: TDateTime;
    function GetAsCurrency: Currency;
    function GetAsFloat: Double;
    function GetAsInteger: Longint;
    function GetAsMemo: string;
    function GetAsString: string;
    function GetIsNull: Boolean;
    procedure SetAsBCD(const Value: Currency);
    procedure SetAsBlob(const Value: TBlobData);
    procedure SetAsBoolean(Value: Boolean);
    procedure SetAsCurrency(const Value: Currency);
    procedure SetAsDate(const Value: TDateTime);
    procedure SetAsDateTime(const Value: TDateTime);
    procedure SetAsFloat(const Value: Double);
    procedure SetAsInteger(Value: Longint);
    procedure SetAsMemo(const Value: string);
    procedure SetAsString(const Value: string);
    procedure SetAsSmallInt(Value: LongInt);
    procedure SetAsTime(const Value: TDateTime);
    procedure SetAsWord(Value: LongInt);
    procedure SetText(const Value: string);
    function GetParameter: TParam;
    procedure AssignFieldValue(source: IBoldField);
    property Parameter: TParam read GetParameter;
  public
    constructor create(MYSQLParameter: TParam; DatasetWrapper: TBoldDatasetWrapper);
  end;
 
  { TBoldMYSQLQuery }
  TBoldMYSQLQuery = class(TBoldDataSetWrapper, IBoldQuery, IBoldExecQuery, IBoldParameterized)
  private
    FQuery: TmySQLQuery;
    function GetParamCount: integer;
    function GetParams(i: integer): IBoldParameter;
    function GetQuery: TmySQLQuery;
    function GetRecordCount: integer;
    function GetRequestLiveQuery: Boolean;
    procedure ClearParams;
    function GetRowsAffected: integer;
    function GetSQLText: String;
    function ParamByName(const Value: string): IBoldParameter;
    procedure AssignParams(Sourceparams: TParams);
    procedure AssignSQL(SQL: TStrings);
    procedure AssignSQLText(SQL: String);
    procedure SetRequestLiveQuery(NewValue: Boolean);
    function Createparam(FldType: TFieldType; const ParamName: string; ParamType: TParamType; Size: integer): IBoldParameter;
  protected
    function GetDataSet: TDataSet; override;
    procedure EndSQLBatch; virtual;
    procedure ExecSQL;
    procedure FailSQLBatch; virtual;
    procedure Open; override;
    procedure StartSQLBatch; virtual;
    property Query: TmySQLQuery read GetQuery;
  public
    constructor Create(Query: TmySQLQuery; DatabaseWrapper: TBoldDatabaseWrapper);
  end;

  { TBoldMYSQLDataBase }
  TBoldMYSQLDatabase = class(TBolddatabaseWrapper, IBoldDataBase)
  private
    FDatabase: TmySQLDatabase;
    FCachedQuery: TmySQLQuery;
    function GetConnected: Boolean;
    function GetDataBase: TmySQLDatabase;
    function GetInTransaction: Boolean;
    function GetIsSQLBased: Boolean;
    function GetKeepConnection: Boolean;
    function GetLogInPrompt: Boolean;
    function SupportsTableCreation: boolean;
    procedure Close;
    procedure Commit;
    procedure Open;
    function GetTable: IBoldTable;
    procedure ReleaseTable(var Table: IBoldTable);
    procedure Rollback;
    procedure SetKeepConnection(NewValue: Boolean);
    procedure SetlogInPrompt(NewValue: Boolean);
    procedure StartTransaction;
    property Database: TmySQLDatabase read GetDatabase;
    procedure ReleaseCachedObjects;
  protected
    procedure AllTableNames(Pattern: String; ShowSystemTables: Boolean; TableNameList: TStrings); override;
    function GetQuery: IBoldQuery; override;
    procedure ReleaseQuery(var Query: IBoldQuery); override;
  public
    constructor create(Database: TmySQLDatabase; SQLDataBaseConfig: TBoldSQLDatabaseConfig);
    destructor destroy; override;
  end;

var
  BoldMYSQLQueryClass: TBoldMYSQLQueryClass = TBoldMYSQLQuery;

                                  IMPLEMENTATION

uses
  SysUtils,
  BoldRev,
  BoldUtils,
  BoldDefs,
  dialogs,
  variants;


{ TBoldMYSQLQuery }
//----------------------------------------------------------------------------------------
procedure TBoldMYSQLQuery.AssignParams(Sourceparams: tparams);
var
  i: integer;
  Opar : TParam;
begin
  Query.Params.Clear;
  if assigned(SourceParams) and (SourceParams.Count > 0) then
  begin
    for i := 0 to Sourceparams.Count - 1 do with OPar do
    begin
      OPar:=Query.Params.CreateParam( Sourceparams[i].DataType,Sourceparams[i].Name, ptInput) as TParam;
      Size:=0;
      Value:=SourceParams[i].Value;
    end;
  end;
end;
//----------------------------------------------------------------------------------------
procedure TBoldMYSQLParameter.Clear;
begin
end;
//----------------------------------------------------------------------------------------
procedure TBoldMYSQLQuery.AssignSQL(SQL: TStrings);
begin
  Query.SQL.BeginUpdate;
  Query.SQL.Assign(SQL);
  Query.SQL.EndUpdate;
end;
//----------------------------------------------------------------------------------------
procedure TBoldMYSQLQuery.AssignSQLText(SQL: String);
begin
  Query.SQL.BeginUpdate;
  Query.SQL.Clear;
  BoldAppendToStrings(Query.SQL, SQL, true);
  Query.SQL.EndUpdate;
end;
//----------------------------------------------------------------------------------------
procedure TBoldMYSQLQuery.ClearParams;
begin
  Query.Params.Clear;
end;
//----------------------------------------------------------------------------------------
constructor TBoldMYSQLQuery.Create(Query: TmySQLQuery; DatabaseWrapper: TBoldDatabaseWrapper);
begin
  inherited create(DatabaseWrapper);
  FQuery := Query;
end;
//----------------------------------------------------------------------------------------
function TBoldMYSQLQuery.CreateParam(FldType: TFieldType; const ParamName: string; ParamType: TParamType; Size: integer): IBoldParameter;
const
  ParamDir: Array[TParamType] of TParamType
           =(ptUnknown, ptInput, ptOutput, ptInputOutput,ptResult);
var MyPar : TParam;
begin
  MyPar:=Query.Params.CreateParam(fldType,ParamName,ParamDir[ParamType]) as TParam;
  result := TBoldMYSQLParameter.Create(MyPar, self);
end;
//----------------------------------------------------------------------------------------
procedure TBoldMYSQLQuery.EndSQLBatch;
begin
end;
//----------------------------------------------------------------------------------------
procedure TBoldMYSQLQuery.ExecSQL;
begin
try
  Query.ExecSQL;
  except
    on E: Exception do MessageDlg(E.Message + #13#10 +Query.SQL.Text, mtError, [mbOk], 0);
    end;
  end;
//----------------------------------------------------------------------------------------
procedure TBoldMYSQLQuery.FailSQLBatch;
begin
end;
//----------------------------------------------------------------------------------------
function TBoldMYSQLQuery.GetDataSet: TDataSet;
begin
  result := Query;
end;
//----------------------------------------------------------------------------------------
function TBoldMYSQLQuery.GetParamCount: integer;
begin
  result := Query.Params.count;
end;
//----------------------------------------------------------------------------------------
function TBoldMYSQLQuery.GetParams(i: integer): IBoldParameter;
begin
  result := TBoldMYSQLParameter.Create(Query.Params[i], self);
end;
//----------------------------------------------------------------------------------------
function TBoldMYSQLQuery.GetQuery: TmySQLQuery;
begin
  result := FQuery;
end;
//----------------------------------------------------------------------------------------
function TBoldMYSQLQuery.GetRecordCount: integer;
begin
  Result := Query.RecordCount;
end;
//----------------------------------------------------------------------------------------
function TBoldMYSQLQuery.GetRequestLiveQuery: Boolean;
begin
  result := false;
end;
//----------------------------------------------------------------------------------------
function TBoldMYSQLQuery.GetRowsAffected: integer;
begin
  result := Query.RowsAffected;
end;
//----------------------------------------------------------------------------------------
function TBoldMYSQLQuery.GetSQLText: String;
begin
  result := Query.SQL.Text;
end;
//----------------------------------------------------------------------------------------
procedure TBoldMYSQLQuery.Open;
begin
  BoldLogSQL(Query.SQL);
  inherited;
end;
//----------------------------------------------------------------------------------------
function TBoldMYSQLQuery.ParamByName(const Value: string): IBoldParameter;
var
  Param: TParam;
begin
  Param := Query.ParamByName(Value);
  if assigned(Param) then result := TBoldMYSQLParameter.Create(Param, self)
  else result := nil;
end;
//----------------------------------------------------------------------------------------
procedure TBoldMYSQLQuery.SetRequestLiveQuery(NewValue: Boolean);
begin
end;
//----------------------------------------------------------------------------------------
procedure TBoldMYSQLQuery.StartSQLBatch;
begin
end;
//----------------------------------------------------------------------------------------
{ TBoldMYSQLDataBase }
//----------------------------------------------------------------------------------------
procedure TBoldMYSQLDatabase.AllTableNames(Pattern: String; ShowSystemTables: Boolean; TableNameList: TStrings);
begin
end;
//----------------------------------------------------------------------------------------
procedure TBoldMYSQLDatabase.Close;
begin
  Database.Close;
end;
//----------------------------------------------------------------------------------------
procedure TBoldMYSQLDatabase.Commit;
begin
  Database.Commit;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -