Class: SQLAnywhere::a_sqlany_bind_param
- Inherits:
-
Object
- Object
- SQLAnywhere::a_sqlany_bind_param
- Defined in:
- ext/sqlanywhere.c
Instance Method Summary collapse
-
#finish(VALUEbind) ⇒ nil
Frees the resources associated with the bound parameter.
-
#get_direction(VALUEbind) ⇒ Object
Gets the direction of the bound parameter.
-
#get_name(VALUEbind) ⇒ Object
Gets the name of the bound parameter.
-
#set_buffer_size(VALUEbind, VALUEsize) ⇒ nil
Sets the buffer size of INOUT and OUT parameters for string and binary data.
-
#set_direction(VALUEbind, VALUEdirection) ⇒ nil
Sets the direction of the bound parameter before binding.
-
#set_value(VALUEbind, VALUEval) ⇒ nil
Sets the value of a bind parameter.
Instance Method Details
#finish(VALUEbind) ⇒ nil
Frees the resources associated with the bound parameter.
<b>Parameters</b>:
- <tt>VALUE bind</tt> -- Bound parameter retrieved from sqlany_describe_bind_param().
<b>Returns</b>:
- <tt>nil</tt>.
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 |
# File 'ext/sqlanywhere.c', line 1556
static VALUE
static_Bind_finish(VALUE bind)
{
a_sqlany_bind_param* s_bind;
Data_Get_Struct(bind, a_sqlany_bind_param, s_bind);
// FIXME: use Ruby's allocation routines?
if (s_bind) { free(s_bind);};
return (Qnil);
}
|
#get_direction(VALUEbind) ⇒ Object
Gets the direction of the bound parameter.
<b>Parameters</b>:
- <tt>VALUE bind</tt> -- Bound parameter retrieved from sqlany_describe_bind_param().
<b>Returns</b>:
- <tt>VALUE name</tt>: The direction of the bound parameter.
1534 1535 1536 1537 1538 1539 1540 1541 |
# File 'ext/sqlanywhere.c', line 1534
static VALUE
static_Bind_get_direction(VALUE bind)
{
a_sqlany_bind_param* s_bind;
Data_Get_Struct(bind, a_sqlany_bind_param, s_bind);
return (CHR2FIX(s_bind->direction));
}
|
#get_name(VALUEbind) ⇒ Object
Gets the name of the bound parameter.
<b>Parameters</b>:
- <tt>VALUE bind</tt> -- Bound parameter retrieved from sqlany_describe_bind_param().
<b>Returns</b>:
- <tt>VALUE name</tt>: The bound variable's name.
1343 1344 1345 1346 1347 1348 1349 |
# File 'ext/sqlanywhere.c', line 1343
static VALUE
static_Bind_get_name(VALUE bind)
{
a_sqlany_bind_param* s_bind;
Data_Get_Struct(bind, a_sqlany_bind_param, s_bind);
return (rb_str_new2(s_bind->name));
}
|
#set_buffer_size(VALUEbind, VALUEsize) ⇒ nil
Sets the buffer size of INOUT and OUT parameters for string and binary
data.
<b>Parameters</b>:
- <tt>VALUE bind</tt> -- Bound parameter retrieved from sqlany_describe_bind_param().
- <tt>VALUE size</tt> -- The size of the buffer to hold the INOUT or OUT parameter.
<b>Returns</b>:
- <tt>nil</tt>.
1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 |
# File 'ext/sqlanywhere.c', line 1509
static VALUE
static_Bind_set_buffer_size(VALUE bind, VALUE size)
{
a_sqlany_bind_param* s_bind;
Data_Get_Struct(bind, a_sqlany_bind_param, s_bind);
s_bind->value.buffer_size = NUM2INT(size);
return (Qnil);
}
|
#set_direction(VALUEbind, VALUEdirection) ⇒ nil
Sets the direction of the bound parameter before binding.
<b>Parameters</b>:
- <tt>VALUE bind</tt> -- Bound parameter retrieved from sqlany_describe_bind_param().
- <tt>VALUE direction</tt> -- The direction of the binding variable.
<b>Returns</b>:
- <tt>nil</tt>.
1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 |
# File 'ext/sqlanywhere.c', line 1482
static VALUE
static_Bind_set_direction(VALUE bind, VALUE direction)
{
a_sqlany_bind_param* s_bind;
Data_Get_Struct(bind, a_sqlany_bind_param, s_bind);
s_bind->direction = NUM2CHR(direction);
return (Qnil);
}
|
#set_value(VALUEbind, VALUEval) ⇒ nil
Sets the value of a bind parameter.
This function is used to bind a Ruby VALUE to a given parameter in a
prepared statement. If the bind_direction is INPUT only, the type INPUT
will be bound based on the RUBY type:
+-------------+------------+
| Ruby Type | Bind Type |
+-------------+------------+
| T_STRING => A_STRING |
| T_FIXNUM => A_VAL_32 |
| T_BIGNUM => A_DOUBLE |
| T_FLOAT => A_DOUBLE |
| T_STRING => A_STRING |
| T_NIL => isnull = 1 |
+--------------------------+
If the bind direction is OUTPUT, instead use the DBCAPI type to set the
size of the buffer.
In the case of INOUT parameters, it is the application's job to call this
method twice, once to bind the INPUT, and once to bind the OUTPUT.
<b>Parameters</b>:
- <tt>VALUE bind</tt> -- Bound parameter retrieved from sqlany_describe_bind_param().
- <tt>VALUE val</tt> -- The value to bind into the bound variable.
<b>Returns</b>:
- <tt>nil</tt>.
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 |
# File 'ext/sqlanywhere.c', line 1385
static VALUE
static_Bind_set_value(VALUE bind, VALUE val)
{
a_sqlany_bind_param* s_bind;
int length;
Data_Get_Struct(bind, a_sqlany_bind_param, s_bind);
// FIXME: use Ruby's allocation routines?
s_bind->value.is_null = malloc(sizeof(sacapi_bool));
*s_bind->value.is_null = 0;
if (s_bind->direction == DD_INPUT)
{
switch(TYPE(val))
{
case T_STRING:
s_bind->value.length = malloc(sizeof(size_t));
length = RSTRING(val)->len;
*s_bind->value.length = length;
s_bind->value.buffer = malloc(length);
memcpy(s_bind->value.buffer, RSTRING(val)->ptr, length);
s_bind->value.type = A_STRING;
break;
case T_FIXNUM:
s_bind->value.buffer = malloc(sizeof(int));
*((int*)s_bind->value.buffer) = FIX2INT(val);
s_bind->value.type = A_VAL32;
break;
case T_BIGNUM:
s_bind->value.buffer = malloc(sizeof(LONG_LONG));
*((LONG_LONG*)s_bind->value.buffer) = rb_num2ll(val);
s_bind->value.type = A_VAL64;
break;
case T_FLOAT:
s_bind->value.buffer = malloc(sizeof(double));
*((double*)s_bind->value.buffer) = NUM2DBL(val);
s_bind->value.type = A_DOUBLE;
break;
case T_NIL:
*s_bind->value.is_null = 1;
s_bind->value.buffer = malloc(sizeof(int));
s_bind->value.type = A_VAL32;
break;
default:
rb_raise(rb_eTypeError, "Cannot convert type. Must be STRING, FIXNUM, BIGNUM, FLOAT, or NIL");
break;
}
}
else
{
switch (s_bind->value.type)
{
case A_STRING:
s_bind->value.buffer = malloc(s_bind->value.buffer_size);
break;
case A_DOUBLE:
s_bind->value.buffer = malloc(sizeof(float));
break;
case A_VAL64:
case A_UVAL64:
s_bind->value.buffer = malloc(sizeof(LONG_LONG));
break;
case A_VAL32:
case A_UVAL32:
s_bind->value.buffer = malloc(sizeof(int));
break;
case A_VAL16:
case A_UVAL16:
s_bind->value.buffer = malloc(sizeof(short));
break;
case A_VAL8:
case A_UVAL8:
s_bind->value.buffer = malloc(sizeof(char));
break;
default:
rb_raise(rb_eTypeError, "Type unknown");
break;
}
}
return (Qnil);
}
|