procedure IPDOStatement.bindColumn (columnIndex: Cardinal; variableAddress: Pointer); overload;
procedure IPDOStatement.bindColumn (columnIndex: Cardinal; variableAddress: Pointer; TypeOverride: TPDODataTypes); overload;
procedure IPDOStatement.bindColumn (columnIndex: AnsiString; variableAddress: Pointer); overload;
procedure IPDOStatement.bindColumn (columnIndex: AnsiString; variableAddress: Pointer; TypeOverride: TPDODataTypes); overload;
This overloaded function binds a column to a variable. Each IPDOStatement.fetch_bound call updates all the bound variables.
Parameters
columnIndex: column identifier. The column can be referenced by either it's 0-indexed position, or its field name.
variableAddress: This is a pointer to the address of the variable.
TypeOverride: If the procedure does not specify the variable type, it is assumed to be the same as defined in the database table. This assumption is a bit risky especially if the value in the database can be negative. Due to the way negative values are stored at the bit level, if there is a mismatch between bit lengths of the database field result and the pascal variable, the value bound to the variable could be wrong. It's always better to specify the type at the beginning, using the TPDODataTypes type.
TPDODataTypes = ( integer_8, integer_8_signed, integer_16, integer_16_signed, integer_32, integer_32_signed, integer_64_signed, {int64signed supported by mysql, not delphi} float_32, float_64, string_1, string_unlimited, generic_time, byte_buffer {last must be as big as maxBLOBSize} );
For numeric variables, choose the number of bits and whether or not the database value is signed. Float_32 is equivalent to a single real number, and float_64 is equivalent to a double. String_1 can hold 255 characters and string_unlimited is just that. The generic_time type must be bound to a TPDOGenericTime data structure. Finally, BLOBs can be retrieved, but don't forget to set the MaxBLOBSize.
Examples
Binding columns in the result set to Pascal variables is an effective way to make the data contained in each row immediately available to your application. The following example demonstrates how PDO allows you to bind and retrieve columns with a variety of options and with intelligent defaults.
procedure retrieve_basic_league_data; var sql: PDO_selectRecord; tmp1: Byte; Fname: AnsiString; FLeagueSize: Byte; Freg_season_length: Byte; FBaseFlags: LongWord; jointime: TPDOGenericTime; FPlayerPools: SmallInt; begin with sql do begin sqlColumns := 'full_name, Joined, structure, number_teams, ' + 'baseline_flags, regular_season_length, player_pools'; sqlTables := 'league_setup'; sqlConditions := 'season = ?'; sqlOrderBy := 'season ASC'; sqlLimit := 0; sqlOffset := 0; end; stmt := db.prepare_select(sql); stmt.bindValue(0,2004); stmt.bindColumn(0,@FName); stmt.bindColumn(1,@jointime,generic_time); stmt.bindColumn(2,@tmp1,integer_8); stmt.bindColumn(3,@FLeagueSize, integer_8); stmt.bindColumn(4,@baseline_flags,integer_32); stmt.bindColumn(5,@Freg_season_length, integer_8); stmt.bindColumn(6,@FPlayerPools, integer_16_signed); if (stmt.execute) then while (stmt.fetch_bound) do begin {do stuff with variables} end; end;