Method: Informix::InsertCursor#put

Defined in:
ext/informixc.c

#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


3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
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
# File 'ext/informixc.c', line 3558

static VALUE
rb_inscur_put(int argc, VALUE *argv, VALUE self)
{
	struct sqlda *input;
	cursor_t *c;
/*
 * 	EXEC SQL begin declare section;
 */
#line 2758 "informixc.ec"
#line 2759 "informixc.ec"
  char *cid, *did;
/*
 * 	EXEC SQL end   declare section;
 */
#line 2760 "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 2767 "informixc.ec"
  {
#line 2767 "informixc.ec"
  sqli_connect_set(0, did, 0);
#line 2767 "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 2779 "informixc.ec"
  {
#line 2779 "informixc.ec"
  sqli_curs_put(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, cid, 256), input, (char *)0);
#line 2779 "informixc.ec"
  }
	clean_input_slots(c);
	if (SQLCODE < 0)
		raise_ifx_extended();

	/* XXX 2-448, Guide to SQL: Sytax*/
	return INT2FIX(sqlca.sqlerrd[2]);
}