| Class | Informix::InsertCursor |
| In: |
ext/informixc.c
|
| Parent: | Informix::CursorBase |
The InsertCursor class adds insertion capabilities to the CursorBase class.
Flushes the insert buffer, writing data to disk.
Returns self.
/*
* call-seq:
* cursor.flush => cursor
*
* Flushes the insert buffer, writing data to disk.
*
* Returns __self__.
*/
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;
}
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
/*
* call-seq:
* 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
*/
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]);
}