EPUB | CHM | PDF

TPSQLDatabase.Methods.SelectStringXXX

Top Previous Next

Since v2.4.0

Methods of this group execute SQL Query and return result as single value casted to the string type.

Syntax:

function SelectString(aSQL : string; var IsOk : boolean; aFieldNumber : integer = 0):string; overload;
function SelectString(aSQL : string; var IsOk : boolean; aFieldName : string):string; overload;
function SelectStringDef(aSQL : string; aDefaultValue : string; aFieldNumber : integer = 0):string; overload;
function SelectStringDef(aSQL : string; aDefaultValue : string; aFieldName : string):string; overload;

Description:

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

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

Parameters:

aSQL

A String value containing the statement to be executed.

IsOk

(SelectString() methods) Variable filled with True after successful execution or False if requested value can't be fetched.

aDefaultValue

(SelectStringDef() 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 it is assumed to be 0. This means that first field's value will be returned.

aFieldName

Field name to return its value by method.

Example:

This example will show PostgreSQL server version (like TPSQLDatabase.ServerVersion property):

ShowMessage(PSQLDatabase1.SelectStringDef('SELECT version()', 'Something wrong happened!'));

See also: Execute() method