A.7.1.1. Datatypes for placeholders
The \%attr parameter can be used to hint at which
datatype the placeholder should have. Typically, the driver is
interested in knowing only if the placeholder should be bound as a
number or a string. For example:
$sth->bind_param(1, $value, { TYPE => SQL_INTEGER });
As a shortcut for this common case, the datatype can be passed
directly, in place of the \%attr hash reference.
This example is equivalent to the one above:
$sth->bind_param(1, $value, SQL_INTEGER);
The TYPE value indicates the standard
(non-driver-specific) type for this parameter. To specify the
driver-specific type, the driver may support a driver-specific
attribute, such as { ora_type
=> 97 }.
The datatype for a placeholder cannot be changed after the first
bind_ param call. However, it can be left
unspecified, in which case it defaults to the previous value.
Perl only has string and number scalar datatypes. All database types
that aren't numbers are bound as strings and must be in a
format the database will understand.
As an alternative to specifying the datatype in the bind_
param call, you can let the driver pass the value as the
default type (VARCHAR). You can then use an SQL
function to convert the type within the statement. For example:
INSERT INTO price(code, price) VALUES (?, CONVERT(MONEY,?))
The CONVERT function used here is just an example.
The actual function and syntax will vary between different databases
and is non-portable.
$rc = $sth->bind_param_inout($p_num, \$bind_value, $max_len) || die $sth->errstr;
$rv = $sth->bind_param_inout($p_num, \$bind_value, $max_len, \%attr) || ...
$rv = $sth->bind_param_inout($p_num, \$bind_value, $max_len, $bind_type) || ... | |
This method acts like bind_
param
,
but also enables values to be updated by the statement. The statement
is typically a call to a stored procedure. The
$bind_value must be passed as a reference to the
actual value to be used.
Note that unlike bind_ param, the
$bind_value variable is not read when
bind_ param_inout is called. Instead, the value in
the variable is read at the time execute is
called.
The additional $max_len parameter specifies the
minimum amount of memory to allocate to
$bind_value for the new value. If the value
returned from the database is too big to fit, then the execution
should fail. If unsure what value to use, pick a generous length,
i.e., a length larger than the longest value that would ever be
returned. The only cost of using a larger value than needed is wasted
memory.
It is expected that few drivers will support this method. The only
driver currently known to do so is DBD::Oracle
(DBD::ODBC may support it in a future release).
Therefore, it should not be used for database-independent
applications.
Undefined values or undef are used to indicate
null values. See also "Placeholders and Bind
Values" for more information.