Class tsqlquery

Unit

Declaration

type tsqlquery = class(tmsebufdataset, isqlclient, icursorclient)

Description

Holds a buffer of all records fetched by SQL; the db*edit widgets work from and to this buffer, not directly against the database. Post transfers the current record's edited values into that buffer, marking it changed/inserted/deleted and keeping a copy of the original values, so Cancel can still revert the current record before Post. applyupdates then posts every changed record to the database using the SQLInsert/SQLDelete/ SQLUpdate statements (generated automatically from TField.ProviderFlags when left empty, if there is a primary key) — override applyrecupdate for full control, e.g. for multi-table queries; applyupdates itself calls CheckBrowseMode (which posts a record left in edit/insert state), so an explicit Post right before it is not required. Before applyupdates, CancelUpdates can still revert all pending changes. Applied changes still need an explicit TTransaction.Commit/ CommitRetaining; set bdo_autoapply and bdo_autocommitret in options to do both automatically.

Hierarchy

Overview

Fields

Protected fmstate: sqlquerystatesty;
Protected FTableName: string;
Protected FReadOnly: boolean;
Protected fprimarykeyfield: tfield;
Protected futf8: boolean;
Protected foptionsmasterlink: optionsmasterlinkty;

Methods

Protected function getdatabase: tcustomconnection;
Protected procedure settransactionwrite(const avalue: tmdbtransaction); override;
Protected procedure checkpendingupdates; virtual;
Protected procedure notification(acomponent: tcomponent; operation: toperation); override;
Protected function Fetch: boolean; override;
Protected function getblobdatasize: integer; override;
Protected function getnumboolean: boolean; virtual;
Protected function getfloatdate: boolean; virtual;
Protected function getint64currency: boolean; virtual;
Protected function blobscached: boolean; override;
Protected function loadfield(const afieldno: integer; const afieldtype: tfieldtype; const buffer: pointer; var bufsize: integer): boolean; override;
Protected procedure updateindexdefs; override;
Protected procedure setdatabase(const value: tmdatabase); override;
Protected procedure settransaction(const value : tmdbtransaction); override;
Protected procedure internaladdrecord(buffer: pointer; aappend: boolean); override;
Protected procedure internalclose; override;
Protected procedure internalinitfielddefs; override;
Protected procedure connect(const aexecute: boolean);
Protected procedure freemodifyqueries;
Protected procedure freequery;
Protected procedure disconnect;
Protected procedure checkrecursivedatasource(const avalue: tdatasource);
Protected procedure internalopen; override;
Protected procedure internalrefresh; override;
Protected procedure refreshtransaction; override;
Protected procedure dobeforeedit; override;
Protected procedure dobeforeinsert; override;
Protected procedure dataevent(event: tdataevent; info: ptrint); override;
Protected function getcanmodify: boolean; override;
Protected procedure updatewherepart(var sql_where : msestring; const afield: tfield);
Protected procedure internalapplyrecupdate(updatekind : tupdatekind);
Protected procedure dobeforeapplyupdate; override;
Protected procedure applyrecupdate(updatekind : tupdatekind); override;
Protected function isprepared: boolean; virtual;
Protected Procedure SetActive(Value : Boolean); override;
Protected procedure SetFiltered(Value: Boolean); override;
Protected procedure SetFilterText(const Value: string); override;
Protected Function GetDataSource: TDatasource; override;
Protected Procedure SetDataSource(AValue : TDatasource);
Protected function stringmemo: boolean; virtual;
Public constructor Create(AOwner : TComponent); override;
Public destructor Destroy; override;
Public function isutf8: boolean; override;
Public procedure applyupdate(const cancelonerror: boolean; const cancelondeleteerror: boolean = false; const editonerror: boolean = false); override;
Public procedure applyupdates(const maxerrors: integer; const cancelonerror: boolean; const cancelondeleteerror: boolean = false; const editonerror: boolean = false); override;
Public function refreshrecquery(const update: boolean): msestring;
Public procedure checktablename;
Public function updaterecquery: msestring;
Public function insertrecquery: msestring;
Public function deleterecquery: msestring;
Public function writetransaction: tsqltransaction;
Public procedure refresh(const aparams: array of variant); overload;
Public procedure Prepare; virtual;
Public procedure UnPrepare; virtual;
Public procedure ExecSQL; virtual;
Public function executedirect(const asql: msestring): integer;
Public function rowsreturned: integer;
Public function rowsaffected: integer;
Public function CreateBlobStream(Field: TField; Mode: TBlobStreamMode): TStream; override;

Properties

Public property updaterowsaffected: integer read fupdaterowsaffected;
Public property Prepared : boolean read IsPrepared;
Public property connected: boolean read getconnected write setconnected;
Published property ReadOnly : Boolean read FReadOnly write SetReadOnly default false;
Published property ParseSQL : Boolean read FParseSQL write SetParseSQL default true;
Published property params : tmseparams read fparams write setparams;
Published property SQL : tsqlstringlist read FSQL write setFSQL;
Published property SQLUpdate : tupdatestringlist read Fapplysql[ukmodify] write setFSQLUpdate;
Published property SQLInsert : tupdatestringlist read Fapplysql[ukinsert] write setFSQLInsert;
Published property SQLDelete : tupdatestringlist read Fapplysql[ukdelete] write setFSQLDelete;
Published property beforeexecute: tcustomsqlstatement read fbeforeexecute write setbeforeexecute;
Published property aftercursorclose: tcustomsqlstatement read faftercursorclose write setaftercursorclose;
Published property IndexDefs : TIndexDefs read GetIndexDefs;
Published property UpdateMode : TUpdateMode read FUpdateMode write SetUpdateMode;
Published property UsePrimaryKeyAsKey : boolean read FUsePrimaryKeyAsKey write SetUsePrimaryKeyAsKey;
Published property tablename: string read ftablename write settablename;
Published property StatementType : TStatementType read fstatementtype write setstatementtype default stnone;
Published property DataSource : TDatasource Read GetDataSource Write SetDatasource;
Published property masterdelayus: integer read fmasterdelayus write fmasterdelayus default -1;
Published property optionsmasterlink: optionsmasterlinkty read foptionsmasterlink write foptionsmasterlink default [];
Published property database: tcustomsqlconnection read getdatabase1 write setdatabase1;
Published property Active;
Published property Filter;
Published property Filtered;
Published property BeforeOpen;
Published property AfterOpen;
Published property BeforeClose;
Published property AfterClose;
Published property BeforeInsert;
Published property AfterInsert;
Published property BeforeEdit;
Published property AfterEdit;
Published property BeforePost;
Published property AfterPost;
Published property BeforeCancel;
Published property AfterCancel;
Published property BeforeDelete;
Published property AfterDelete;
Published property BeforeScroll;
Published property AfterScroll;
Published property BeforeRefresh;
Published property AfterRefresh;
Published property OnCalcFields;
Published property OnDeleteError;
Published property OnEditError;
Published property OnFilterRecord;
Published property OnNewRecord;
Published property OnPostError;
Published property onmodified;
Published property AutoCalcFields;
Published property Transaction: tsqltransaction read getsqltransaction write setsqltransaction;
Published property transactionwrite: tsqltransaction read getsqltransactionwrite write setsqltransactionwrite;

Description

Fields

Protected fmstate: sqlquerystatesty;

This item has no description.

Protected FTableName: string;

This item has no description.

Protected FReadOnly: boolean;

This item has no description.

Protected fprimarykeyfield: tfield;

This item has no description.

Protected futf8: boolean;

This item has no description.

Protected foptionsmasterlink: optionsmasterlinkty;

This item has no description.

Methods

Protected function getdatabase: tcustomconnection;

This item has no description.

Protected procedure settransactionwrite(const avalue: tmdbtransaction); override;

This item has no description.

Protected procedure checkpendingupdates; virtual;

This item has no description.

Protected procedure notification(acomponent: tcomponent; operation: toperation); override;

This item has no description.

Protected function Fetch: boolean; override;

This item has no description.

Protected function getblobdatasize: integer; override;

This item has no description.

Protected function getnumboolean: boolean; virtual;

This item has no description.

Protected function getfloatdate: boolean; virtual;

This item has no description.

Protected function getint64currency: boolean; virtual;

This item has no description.

Protected function blobscached: boolean; override;

This item has no description.

Protected function loadfield(const afieldno: integer; const afieldtype: tfieldtype; const buffer: pointer; var bufsize: integer): boolean; override;

This item has no description.

Protected procedure updateindexdefs; override;

This item has no description.

Protected procedure setdatabase(const value: tmdatabase); override;

This item has no description.

Protected procedure settransaction(const value : tmdbtransaction); override;

This item has no description.

Protected procedure internaladdrecord(buffer: pointer; aappend: boolean); override;

This item has no description.

Protected procedure internalclose; override;

This item has no description.

Protected procedure internalinitfielddefs; override;

This item has no description.

Protected procedure connect(const aexecute: boolean);

This item has no description.

Protected procedure freemodifyqueries;

This item has no description.

Protected procedure freequery;

This item has no description.

Protected procedure disconnect;

This item has no description.

Protected procedure checkrecursivedatasource(const avalue: tdatasource);

This item has no description.

Protected procedure internalopen; override;

This item has no description.

Protected procedure internalrefresh; override;

This item has no description.

Protected procedure refreshtransaction; override;

This item has no description.

Protected procedure dobeforeedit; override;

This item has no description.

Protected procedure dobeforeinsert; override;

This item has no description.

Protected procedure dataevent(event: tdataevent; info: ptrint); override;

This item has no description.

Protected function getcanmodify: boolean; override;

This item has no description.

Protected procedure updatewherepart(var sql_where : msestring; const afield: tfield);

This item has no description.

Protected procedure internalapplyrecupdate(updatekind : tupdatekind);

This item has no description.

Protected procedure dobeforeapplyupdate; override;

This item has no description.

Protected procedure applyrecupdate(updatekind : tupdatekind); override;

The dataset is locked for the duration of applyrecupdate (and of the whole applyupdates it is called from) — avoid user interaction (e.g. showmessage) from an override or from the underlying "on apply record update" mechanism.

Protected function isprepared: boolean; virtual;

This item has no description.

Protected Procedure SetActive(Value : Boolean); override;

This item has no description.

Protected procedure SetFiltered(Value: Boolean); override;

This item has no description.

Protected procedure SetFilterText(const Value: string); override;

This item has no description.

Protected Function GetDataSource: TDatasource; override;

This item has no description.

Protected Procedure SetDataSource(AValue : TDatasource);

This item has no description.

Protected function stringmemo: boolean; virtual;

This item has no description.

Public constructor Create(AOwner : TComponent); override;

This item has no description.

Public destructor Destroy; override;

This item has no description.

Public function isutf8: boolean; override;

This item has no description.

Public procedure applyupdate(const cancelonerror: boolean; const cancelondeleteerror: boolean = false; const editonerror: boolean = false); override;

This item has no description.

Public procedure applyupdates(const maxerrors: integer; const cancelonerror: boolean; const cancelondeleteerror: boolean = false; const editonerror: boolean = false); override;

This item has no description.

Public function refreshrecquery(const update: boolean): msestring;

This item has no description.

Public procedure checktablename;

This item has no description.

Public function updaterecquery: msestring;

This item has no description.

Public function insertrecquery: msestring;

This item has no description.

Public function deleterecquery: msestring;

This item has no description.

Public function writetransaction: tsqltransaction;

This item has no description.

Public procedure refresh(const aparams: array of variant); overload;

This item has no description.

Public procedure Prepare; virtual;

This item has no description.

Public procedure UnPrepare; virtual;

This item has no description.

Public procedure ExecSQL; virtual;

This item has no description.

Public function executedirect(const asql: msestring): integer;

This item has no description.

Public function rowsreturned: integer;

This item has no description.

Public function rowsaffected: integer;

This item has no description.

Public function CreateBlobStream(Field: TField; Mode: TBlobStreamMode): TStream; override;

This item has no description.

Properties

Public property updaterowsaffected: integer read fupdaterowsaffected;

This item has no description.

Public property Prepared : boolean read IsPrepared;

This item has no description.

Public property connected: boolean read getconnected write setconnected;

This item has no description.

Published property ReadOnly : Boolean read FReadOnly write SetReadOnly default false;

This item has no description.

Published property ParseSQL : Boolean read FParseSQL write SetParseSQL default true;

This item has no description.

Published property params : tmseparams read fparams write setparams;

This item has no description.

Published property SQL : tsqlstringlist read FSQL write setFSQL;

Stored as ANSI text — avoid non-ASCII characters (> #127) in the SQL text itself, since their meaning would depend on the current locale at design time. For portable, locale-independent SQL text, pass values as query parameters instead (they are converted to/from the current locale, or to/from UTF-8 if dso_utf8 is set).

Published property SQLUpdate : tupdatestringlist read Fapplysql[ukmodify] write setFSQLUpdate;

SQLUpdate/SQLInsert/SQLDelete each hold a single SQL statement, even though they are string lists (only for readability of a multi-line statement) — for anything needing more than one statement, use applyrecupdate instead.

Published property SQLInsert : tupdatestringlist read Fapplysql[ukinsert] write setFSQLInsert;

This item has no description.

Published property SQLDelete : tupdatestringlist read Fapplysql[ukdelete] write setFSQLDelete;

This item has no description.

Published property beforeexecute: tcustomsqlstatement read fbeforeexecute write setbeforeexecute;

This item has no description.

Published property aftercursorclose: tcustomsqlstatement read faftercursorclose write setaftercursorclose;

This item has no description.

Published property IndexDefs : TIndexDefs read GetIndexDefs;

Only populated while UsePrimaryKeyAsKey is True, since that is what makes tsqlquery parse the index definitions — and only for a query whose "from" part names a single table (no comma-separated table list).

Published property UpdateMode : TUpdateMode read FUpdateMode write SetUpdateMode;

This item has no description.

Published property UsePrimaryKeyAsKey : boolean read FUsePrimaryKeyAsKey write SetUsePrimaryKeyAsKey;

When True (the default), the primary key field(s) automatically get of_InKey added to optionsfield (the pfInKey equivalent), so they are used in the "where" part of the update statement — whether the field is persistent or not. A calculated field must still have of_InUpdate removed from optionsfield manually to be excluded from the update statement. Also determines whether IndexDefs is populated.

Published property tablename: string read ftablename write settablename;

This item has no description.

Published property StatementType : TStatementType read fstatementtype write setstatementtype default stnone;

This item has no description.

Published property DataSource : TDatasource Read GetDataSource Write SetDatasource;

This item has no description.

Published property masterdelayus: integer read fmasterdelayus write fmasterdelayus default -1;

This item has no description.

Published property optionsmasterlink: optionsmasterlinkty read foptionsmasterlink write foptionsmasterlink default [];

This item has no description.

Published property database: tcustomsqlconnection read getdatabase1 write setdatabase1;

This item has no description.

Published property Active;

This item has no description.

Published property Filter;

Unlike the base tdataset behavior, setting Filter or Filtered on a tsqlquery inserts Filter into the "where" part of the SQL statement and re-executes the query against the database — it is not a local, in-memory filter of already fetched records. ParseSQL must be True. For a purely local filter of the fetched records use OnFilterRecord instead.

Published property Filtered;

This item has no description.

Published property BeforeOpen;

This item has no description.

Published property AfterOpen;

This item has no description.

Published property BeforeClose;

This item has no description.

Published property AfterClose;

This item has no description.

Published property BeforeInsert;

This item has no description.

Published property AfterInsert;

This item has no description.

Published property BeforeEdit;

This item has no description.

Published property AfterEdit;

This item has no description.

Published property BeforePost;

This item has no description.

Published property AfterPost;

This item has no description.

Published property BeforeCancel;

This item has no description.

Published property AfterCancel;

This item has no description.

Published property BeforeDelete;

This item has no description.

Published property AfterDelete;

This item has no description.

Published property BeforeScroll;

This item has no description.

Published property AfterScroll;

This item has no description.

Published property BeforeRefresh;

This item has no description.

Published property AfterRefresh;

This item has no description.

Published property OnCalcFields;

This item has no description.

Published property OnDeleteError;

This item has no description.

Published property OnEditError;

This item has no description.

Published property OnFilterRecord;

This item has no description.

Published property OnNewRecord;

This item has no description.

Published property OnPostError;

This item has no description.

Published property onmodified;

This item has no description.

Published property AutoCalcFields;

This item has no description.

Published property Transaction: tsqltransaction read getsqltransaction write setsqltransaction;

This item has no description.

Published property transactionwrite: tsqltransaction read getsqltransactionwrite write setsqltransactionwrite;

For disconnected (offline) updates: transaction is used exclusively for reading, while transactionwrite (which can be shared by several queries) is used for writing; set controller.options to include dso_offline. On open, the read transaction is started, the data is fetched, and the read transaction is closed. On applyupdates, the write transaction is started and the updates are written, then committed if dso_autocommitret is set. In this mode the connection can be closed without closing the dataset; reconnect by setting connected to True. If logfilename is set, a snapshot of the data and the applied modifications are logged to that file, and can be reloaded into a closed dataset with recover.


Generated by PasDoc 1.0.4.