Class: Advantage::a_ads_bind_param
- Inherits:
-
Object
- Object
- Advantage::a_ads_bind_param
- Defined in:
- ext/advantage/advantage.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 ads_describe_bind_param( ).
<b>Returns</b>:
- <tt>nil</tt>.
1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 |
# File 'ext/advantage/advantage.c', line 1711
static VALUE
static_Bind_finish(VALUE bind)
{
a_ads_bind_param *s_bind;
Data_Get_Struct(bind, a_ads_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 ads_describe_bind_param( ).
<b>Returns</b>:
- <tt>VALUE name</tt>: The direction of the bound parameter.
1689 1690 1691 1692 1693 1694 1695 1696 |
# File 'ext/advantage/advantage.c', line 1689
static VALUE
static_Bind_get_direction(VALUE bind)
{
a_ads_bind_param *s_bind;
Data_Get_Struct(bind, a_ads_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 ads_describe_bind_param( ).
<b>Returns</b>:
- <tt>VALUE name</tt>: The bound variable's name.
1458 1459 1460 1461 1462 1463 1464 |
# File 'ext/advantage/advantage.c', line 1458
static VALUE
static_Bind_get_name(VALUE bind)
{
a_ads_bind_param *s_bind;
Data_Get_Struct(bind, a_ads_bind_param, s_bind);
return (rb_str_new2((char *)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 ads_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>.
1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 |
# File 'ext/advantage/advantage.c', line 1664
static VALUE
static_Bind_set_buffer_size(VALUE bind, VALUE size)
{
a_ads_bind_param *s_bind;
Data_Get_Struct(bind, a_ads_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 ads_describe_bind_param( ).
- <tt>VALUE direction</tt> -- The direction of the binding variable.
<b>Returns</b>:
- <tt>nil</tt>.
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 |
# File 'ext/advantage/advantage.c', line 1637
static VALUE
static_Bind_set_direction(VALUE bind, VALUE direction)
{
a_ads_bind_param *s_bind;
Data_Get_Struct(bind, a_ads_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 ads_describe_bind_param( ).
- <tt>VALUE val</tt> -- The value to bind into the bound variable.
<b>Returns</b>:
- <tt>nil</tt>.
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 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 |
# File 'ext/advantage/advantage.c', line 1500
static VALUE
static_Bind_set_value(VALUE bind, VALUE val)
{
a_ads_bind_param *s_bind;
int length;
Data_Get_Struct(bind, a_ads_bind_param, s_bind);
// FIXME: use Ruby's allocation routines?
s_bind->value.is_null = malloc(sizeof(UNSIGNED32));
*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.length = malloc(sizeof(size_t));
s_bind->value.buffer = malloc(sizeof(int));
*((int *)s_bind->value.buffer) = FIX2INT(val);
s_bind->value.type = A_VAL32;
length = 1;
*s_bind->value.length = length;
}
else //64-bit
{
s_bind->value.length = malloc(sizeof(size_t));
s_bind->value.buffer = malloc(sizeof(long));
*((long *)s_bind->value.buffer) = FIX2LONG(val);
s_bind->value.type = A_VAL64;
length = 1;
*s_bind->value.length = length;
}
break;
case T_BIGNUM:
s_bind->value.length = malloc(sizeof(size_t));
s_bind->value.buffer = malloc(sizeof(LONG_LONG));
*((LONG_LONG *)s_bind->value.buffer) = rb_num2ll(val);
s_bind->value.type = A_VAL64;
length = 1;
*s_bind->value.length = length;
break;
case T_FLOAT:
s_bind->value.length = malloc(sizeof(size_t));
s_bind->value.buffer = malloc(sizeof(double));
*((double *)s_bind->value.buffer) = NUM2DBL(val);
s_bind->value.type = A_DOUBLE;
length = 1;
*s_bind->value.length = length;
break;
case T_FALSE:
s_bind->value.length = malloc(sizeof(size_t));
s_bind->value.buffer = malloc(sizeof(short));
*((int *)s_bind->value.buffer) = ADS_FALSE;
s_bind->value.type = A_UVAL16;
length = 1;
*s_bind->value.length = length;
break;
case T_TRUE:
s_bind->value.length = malloc(sizeof(size_t));
s_bind->value.buffer = malloc(sizeof(short));
*((int *)s_bind->value.buffer) = ADS_TRUE;
s_bind->value.type = A_UVAL16;
length = 1;
*s_bind->value.length = length;
break;
case T_NIL:
s_bind->value.length = malloc(sizeof(size_t));
*s_bind->value.is_null = 1;
s_bind->value.buffer = malloc(sizeof(int));
s_bind->value.type = A_VAL32;
length = 1;
*s_bind->value.length = length;
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);
}
|