EPUB | CHM | PDF

TMySQLDatabase.Methods.SelectXXX

Top Previous Next

note Since v2.5.5, v2.6.1 (SelectInt64 and SelectDateTime)

Methods of this group execute SQL query and return result as single value casted to XXX type.

Syntax:

function SelectString(aSQL : string; var IsOk : boolean; aFieldNumber : integer = 0):string;
function SelectString(aSQL : string; var IsOk : boolean; aFieldName : string):string;overload;
function SelectStringDef(aSQL : string; aDefaultValue : string; aFieldNumber : integer = 0):string;
function SelectStringDef(aSQL : string; aDefaultValue : string; aFieldName : string):string;
function SelectInteger(aSQL : string; var IsOk : boolean; aFieldNumber : integer = 0):integer;
function SelectInteger(aSQL : string; var IsOk : boolean; aFieldName : string):integer;
function SelectIntegerDef(aSQL : string; aDefaultValue : integer; aFieldNumber : integer = 0):integer;
function SelectIntegerDef(aSQL : string; aDefaultValue : integer; aFieldName : string):integer;
function SelectInt64(aSQL : string; var IsOk : boolean; aFieldNumber : integer = 0):int64;
function SelectInt64(aSQL : string; var IsOk : boolean; aFieldName : string):int64;
function SelectInt64Def(aSQL : string; aDefaultValue : int64; aFieldNumber : integer = 0):int64;
function SelectInt64Def(aSQL : string; aDefaultValue : int64; aFieldName : string):int64;
function SelectDouble(aSQL : string; var IsOk : boolean; aFieldNumber : integer = 0):double;
function SelectDouble(aSQL : string; var IsOk : boolean; aFieldName : string):double;
function SelectDoubleDef(aSQL : string; aDefaultValue : double; aFieldNumber : integer = 0):double;
function SelectDoubleDef(aSQL : string; aDefaultValue : double; aFieldName : string):double;
function SelectDateTime(aSQL : string; var IsOk : boolean; aFieldNumber : integer = 0):TDateTime;
function SelectDateTime(aSQL : string; var IsOk : boolean; aFieldName : string):TDateTime;
function SelectDateTimeDef(aSQL : string; aDefaultValue : TDateTime; aFieldNumber : integer = 0):TDateTime;
function SelectDateTimeDef(aSQL : string; aDefaultValue : TDateTime; aFieldName : string):TDateTime;

Description:

Use these methods to execute an SQL statement against the database without the overhead of using a TMySQLQuery object. Methods return single value as a value of the field specified by number (aFieldNumber parameter) or by name (aFieldName parameter) in the first row of the first resultset. If the aFieldNumber parameter is omitted, methods return the value of the first field.

If the query doesn't return at least one row or specified field is not found, the IsOk param is set to False (SelectXxx methods) or aDefaultValue param value is returned (SelectXxxDef methods).

Parameters:

aSQL

A String value containing the statement to be executed.

IsOk

(SelectXxx methods) variable is set to True after successful execution, or False if requested value couldn't be fetched.

aDefaultValue

(SelectXxxDef methods) value to return by method if requested value can't be fetched.

aFieldNumber

Field number to return its value by method. Fields are numbered from zero. If this parameter is omitted, then it is assumed to be 0. In this case the value of the first field will be returned.

aFieldName

Field name to return its value by method.

Examples:

This example will show MySQL server version (like TMySQLDatabase.GetServerInfo method):

ShowMessage(mySQLDatabase1.SelectStringDef('SELECT version', 'Something wrong happend!'));

This example will show current UNIX timestamp value returned by MySQL server:

ShowMessage(IntToStr(mySQLDatabase1.SelectIntDef('SELECT unix_timestamp', -1)));

See also: Execute method