Class: Informix::InsertCursor

Inherits:
CursorBase show all
Defined in:
ext/informixc.c

Instance Method Summary collapse

Methods inherited from CursorBase

#close, #free, #id, #open

Instance Method Details

#flushObject

cursor.flush => cursor

Flushes the insert buffer, writing data to disk.

Returns __self__.



3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
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
# File 'ext/informixc.c', line 3626

static VALUE
rb_inscur_flush(VALUE self)
{
	cursor_t *c;
/*
 * 	EXEC SQL begin declare section;
 */
#line 2801 "informixc.ec"
#line 2802 "informixc.ec"
  char *cid, *did;
/*
 * 	EXEC SQL end   declare section;
 */
#line 2803 "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 2810 "informixc.ec"
  {
#line 2810 "informixc.ec"
  sqli_connect_set(0, did, 0);
#line 2810 "informixc.ec"
  }
	if (SQLCODE < 0)
		raise_ifx_extended();

	cid = c->cursor_id;
/*
 * 	EXEC SQL flush :cid;
 */
#line 2815 "informixc.ec"
  {
#line 2815 "informixc.ec"
  sqli_curs_flush(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, cid, 256));
#line 2815 "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


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
3616
# File 'ext/informixc.c', line 3559

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

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