function TPDO.prepare_select (sql: PDO_selectRecord): IPDOStatement; overload;
function TPDO.prepare_select (sql: PDO_enhancedSelect): IPDOStatement; overload;
The TPDO.prepare_select method is just like a TPDO.prepare_as_is method, except that it only prepares SELECT statements as a function of the database protocol that is being used. Currently, despite not yet having drivers for these servers, server-specific SQL can be produced for:
- MySQL
- SQLite
- PostgreSQL
- MSSQL/Sybase
- Oracle
- Firebird
- DB2/ODBC
Parameters
sql: The components of the select statement must be placed in the PDO_selectRecord record without any syntax. It is best to always use the "sqlOrderBy" field. For some databases like MySQL and PostgreSQL this field isn't necessary for any select operations, but for other databases, selects involving limits and offsets require the "sqlOrderBy" field is used. It is best to explicitly use "ASC" or "DESC" keywords, especially for column lists. The "sqlLimit" field defaults to zero, meaning there is no limitation on rows retrieved.
PDO_selectRecord = record sqlColumns: AnsiString; sqlTables: AnsiString; sqlConditions: AnsiString; sqlOrderBy: AnsiString; sqlLimit: Int64; sqlOffset: Int64; end;
sql: A new structure now supports GROUP and HAVING by. Additionally, there is a little function called "full select" that can provide an initialized blank structure, or equally can be used to populate it in one statement.
TDistinct = (ALL_ROWS, DISTINCT); PDO_enhancedSelect = record DISTINCT : TDistinct; COLUMNS : Ansistring; FROM : Ansistring; WHERE : Ansistring; GROUP : Ansistring; HAVING : Ansistring; ORDER : Ansistring; LIMIT : int64; OFFSET : int64; end; function full_select (const distinct: TDistinct = ALL_ROWS; const columns: ansistring = ''; const table_joins: ansistring = ''; const condition: ansistring = ''; const orderby: ansistring = ''; const limit: int64 = 0; const offset: int64 = 0; const groupby: ansistring = ''; const having: ansistring = ''): PDO_enhancedSelect; begin Result.DISTINCT := distinct; Result.COLUMNS := columns; Result.FROM := table_joins; Result.WHERE := condition; Result.GROUP := groupby; Result.HAVING := having; Result.ORDER := orderby; Result.LIMIT := limit; Result.OFFSET := offset; end;
Return Values
TPDO.query returns a IPDOStatement object.
Example
Please see the examples on the TPDO.prepare_as_is and TPDO.query_select pages.