Class: Informix::InsertCursor
- Inherits:
-
CursorBase
- Object
- CursorBase
- Informix::InsertCursor
- Defined in:
- ext/informixc.c
Instance Method Summary collapse
-
#flush ⇒ Object
cursor.flush => cursor.
-
#put(*args) ⇒ Object
cursor.put(*params).
Methods inherited from CursorBase
Instance Method Details
#flush ⇒ Object
cursor.flush => cursor
Flushes the insert buffer, writing data to disk.
Returns __self__.
3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 |
# File 'ext/informixc.c', line 3638
static VALUE
rb_inscur_flush(VALUE self)
{
cursor_t *c;
/*
* EXEC SQL begin declare section;
*/
#line 2813 "informixc.ec"
#line 2814 "informixc.ec"
char *cid, *did;
/*
* EXEC SQL end declare section;
*/
#line 2815 "informixc.ec"
Data_Get_Struct(self, cursor_t, c);
if (!c->is_open)
rb_raise(rb_eProgrammingError, "Open the cursor object first");
did = c->database_id;
/*
* EXEC SQL set connection :did;
*/
#line 2822 "informixc.ec"
{
#line 2822 "informixc.ec"
sqli_connect_set(0, did, 0);
#line 2822 "informixc.ec"
}
if (SQLCODE < 0)
raise_ifx_extended();
cid = c->cursor_id;
/*
* EXEC SQL flush :cid;
*/
#line 2827 "informixc.ec"
{
#line 2827 "informixc.ec"
sqli_curs_flush(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, cid, 256));
#line 2827 "informixc.ec"
}
return self;
}
|
#put(*args) ⇒ Object
cursor.put(*params)
Binds params
as input parameters and executes the insert statement. The records are not written immediatly to disk, unless the insert buffer is full, the flush
method is called, the cursor is closed or the transaction is commited.
Examples:
A bulk insert using an insert cursor. Requires a transaction:
db.transaction do |db|
db.cursor('insert into stock values(?, ?, ?, ?, ?, ?)') |cur|
cur.open
# Loading a file separated by '|'
File.open(filename).each do |line|
fields = line.split('|')
cur.put(*fields)
end
end
end
3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 |
# File 'ext/informixc.c', line 3571
static VALUE
rb_inscur_put(int argc, VALUE *argv, VALUE self)
{
struct sqlda *input;
cursor_t *c;
/*
* EXEC SQL begin declare section;
*/
#line 2771 "informixc.ec"
#line 2772 "informixc.ec"
char *cid, *did;
/*
* EXEC SQL end declare section;
*/
#line 2773 "informixc.ec"
Data_Get_Struct(self, cursor_t, c);
if (!c->is_open)
rb_raise(rb_eProgrammingError, "Open the cursor object first");
did = c->database_id;
/*
* EXEC SQL set connection :did;
*/
#line 2780 "informixc.ec"
{
#line 2780 "informixc.ec"
sqli_connect_set(0, did, 0);
#line 2780 "informixc.ec"
}
if (SQLCODE < 0)
raise_ifx_extended();
input = &c->daInput;
cid = c->cursor_id;
bind_input_params(c, argv);
if (argc != input->sqld)
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
argc, input->sqld);
/*
* EXEC SQL put :cid using descriptor input;
*/
#line 2792 "informixc.ec"
{
#line 2792 "informixc.ec"
sqli_curs_put(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, cid, 256), input, (char *)0);
#line 2792 "informixc.ec"
}
clean_input_slots(c);
if (SQLCODE < 0)
raise_ifx_extended();
/* XXX 2-448, Guide to SQL: Sytax*/
return INT2FIX(sqlca.sqlerrd[2]);
}
|