Module: DBI::DBD::SQLAnywhere::Utility
Overview
This module provides functionality that is used by all the DBD classes
Constant Summary collapse
- NO_DIRECTION =
0
- INPUT_ONLY =
1
- OUTPUT_ONLY =
2
- INPUT_OUTPUT =
3
Instance Method Summary collapse
-
#do_bind!(prep_stmt, param, bindvar, i, bound) ⇒ Object
do_bind takes the following arguments: *
prep_stmt
: a handle the prepared Statement object *param
: the parameter to bound, obtained by sqlany_describe_bind_param *bindvar
: the actual value to bind the the parameter.
Instance Method Details
#do_bind!(prep_stmt, param, bindvar, i, bound) ⇒ Object
do_bind takes the following arguments:
-
prep_stmt
: a handle the prepared Statement object -
param
: the parameter to bound, obtained by sqlany_describe_bind_param -
bindvar
: the actual value to bind the the parameter. Can be aVALUE
, or aHASH
. -
i
: the parameter number to bind. Should be the same as used in sqlany_describe_bind_param -
bound
: hash used to track INOUT, and OUT parameters
IN
parameters will be bound once with INPUT_ONLY
. OUT
parameters will be bound once with OUTPUT_ONLY
. INOUT
parameters will be be bound twice, once as INPUT_ONLY
, and once as OUTPUT_ONLY
. INOUT
parameters will use different buffers to pass the input and output values to the DLL.
If the parameter to be bound is INPUT_ONLY
, bindvar
must be a regular value type such as Bignum, Fixnum, String, etc. This value will be bound to the input parameter
If the parameter to be bound is OUTPUT_ONLY
, bindvar
must be a hash with keys: ::name => This is the name that you will be used later to retrieve the output value ::length => If the output will be a string or binary, the expected length must be stated. If this length is exceeded
a DatabaseError (truncation) will be raised.
If the parameter to be bound is INPUT_OUTPUT
, bindvar
must be a hash with keys: ::name => This is the name that you will be used later to retrieve the output value ::value => The value to bind to the input. ::length => If the output will be a string or binary, the expected length must be stated. If this length is exceeded
a DatabaseError (truncation) will be raised.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/dbd/SQLAnywhere.rb', line 136 def do_bind!(prep_stmt, param, bindvar, i, bound) # Get the direction orig_direction = param.get_direction; # Bind INPUT if orig_direction == INPUT_ONLY or orig_direction == INPUT_OUTPUT param.set_direction(INPUT_ONLY) # Obtain the value out of the hash if neccessary if bindvar.class == Hash raise DBI::ProgrammingError.new("Parameter hash must contain :value key") if !bindvar.has_key?(:value) param.set_value(bindvar[:value]) else param.set_value(bindvar) end raise error() if SA.instance.api.sqlany_bind_param(prep_stmt, i, param) == 0 end # Bind OUTPUT if orig_direction == OUTPUT_ONLY or orig_direction == INPUT_OUTPUT param.set_direction(OUTPUT_ONLY) # Add the +::name+ to the +bound+ hash so its output value can be retrieved later raise DBI::ProgrammingError.new("Parameter hash must contain :name key") if !bindvar.has_key?(:name) bound[bindvar[:name]] = i if !bound.nil? # set the buffer length if appropriate if bindvar.has_key?(:length) param.set_buffer_size(bindvar[:length]) end # +set_value+ sets up the receiveing buffer param.set_value(nil) raise error() if SA.instance.api.sqlany_bind_param(prep_stmt, i, param) == 0 end end |