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>.
1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 |
# File 'ext/sqlanywhere.c', line 1622
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.
1600 1601 1602 1603 1604 1605 1606 1607 |
# File 'ext/sqlanywhere.c', line 1600
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.
1403 1404 1405 1406 1407 1408 1409 |
# File 'ext/sqlanywhere.c', line 1403
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>.
1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 |
# File 'ext/sqlanywhere.c', line 1575
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>.
1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 |
# File 'ext/sqlanywhere.c', line 1548
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>.
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 |
# File 'ext/sqlanywhere.c', line 1445
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_LEN(val);
*s_bind->value.length = length;
s_bind->value.buffer = malloc(length);
memcpy(s_bind->value.buffer, RSTRING_PTR(val), length);
s_bind->value.type = A_STRING;
break;
case T_FIXNUM:
if(sizeof(void*) == 4){ //32-bit
s_bind->value.buffer = malloc(sizeof(int));
*((int*)s_bind->value.buffer) = FIX2INT(val);
s_bind->value.type = A_VAL32;
}else{ //64-bit
s_bind->value.buffer = malloc(sizeof(long));
*((long*)s_bind->value.buffer) = FIX2LONG(val);
s_bind->value.type = A_VAL64;
}
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);
}
|