| Class | Informix::ScrollCursor |
| In: |
lib/informix/scrollcursor.rb
ext/informixc.c |
| Parent: | SequentialCursor |
The ScrollCursor class adds Array-like capabilities to the SequentialCursor class
Provides the Array-like functionality for scroll cursors when using the cursor[index] syntax
/*
* Provides the Array-like functionality for scroll cursors when using the
* cursor[index] syntax
*/
static VALUE
rb_scrollcur_entry(VALUE self, VALUE index, VALUE type, VALUE bang)
{
cursor_t *c;
struct sqlda *output;
VALUE record;
short c_bang;
/*
* EXEC SQL begin declare section;
*/
#line 2844 "informixc.ec"
#line 2845 "informixc.ec"
char *cid, *did;
long pos;
/*
* EXEC SQL end declare section;
*/
#line 2847 "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 2854 "informixc.ec"
{
#line 2854 "informixc.ec"
sqli_connect_set(0, did, 0);
#line 2854 "informixc.ec"
}
if (SQLCODE < 0)
return Qnil;
output = c->daOutput;
cid = c->cursor_id;
if (NIL_P(index))
/*
* EXEC SQL fetch current :cid using descriptor output;
*/
#line 2862 "informixc.ec"
{
#line 2862 "informixc.ec"
static _FetchSpec _FS0 = { 0, 5, 0 };
sqli_curs_fetch(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, cid, 256), (ifx_sqlda_t *)0, output, (char *)0, &_FS0);
#line 2862 "informixc.ec"
}
else if ((pos = NUM2LONG(index) + 1) > 0)
/*
* EXEC SQL fetch absolute :pos :cid using descriptor output;
*/
#line 2864 "informixc.ec"
{
#line 2864 "informixc.ec"
static ifx_sqlvar_t _sqibind[] =
{
{ 103, sizeof(pos), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
#line 2864 "informixc.ec"
};
static ifx_sqlda_t _SD0 = { 1, _sqibind, {0}, 1, 0 };
static _FetchSpec _FS1 = { 0, 6, 0 };
#line 2864 "informixc.ec"
_sqibind[0].sqldata = (char *) &pos;
sqli_curs_fetch(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, cid, 256), &_SD0, output, (char *)0, &_FS1);
#line 2864 "informixc.ec"
}
else {
/*
* EXEC SQL fetch last :cid;
*/
#line 2866 "informixc.ec"
{
#line 2866 "informixc.ec"
static _FetchSpec _FS0 = { 0, 4, 0 };
sqli_curs_fetch(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, cid, 256), (ifx_sqlda_t *)0, (ifx_sqlda_t *)0, (char *)0, &_FS0);
#line 2866 "informixc.ec"
}
/*
* EXEC SQL fetch relative :pos :cid using descriptor output;
*/
#line 2867 "informixc.ec"
{
#line 2867 "informixc.ec"
static ifx_sqlvar_t _sqibind[] =
{
{ 103, sizeof(pos), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
#line 2867 "informixc.ec"
};
static ifx_sqlda_t _SD0 = { 1, _sqibind, {0}, 1, 0 };
static _FetchSpec _FS1 = { 0, 7, 0 };
#line 2867 "informixc.ec"
_sqibind[0].sqldata = (char *) &pos;
sqli_curs_fetch(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, cid, 256), &_SD0, output, (char *)0, &_FS1);
#line 2867 "informixc.ec"
}
}
if (SQLCODE == SQLNOTFOUND)
return Qnil;
if (SQLCODE < 0)
raise_ifx_extended();
c_bang = RTEST(bang);
RECORD(c, type, c_bang, record);
return make_result(c, record);
}
Returns the next offset th record. Negative indices count backward from the current position. Returns nil if the offset is out of range.
Stores the record fetched always in the same Array object.
cursor.next!(offset = 1) => array or nil
# File lib/informix/scrollcursor.rb, line 154
154: def next!(offset = 1)
155: rel(offset, Array, true)
156: end
Returns the previous offset th record. Negative indices count forward from the current position. Returns nil if the offset is out of range.
cursor.prev(offset = 1) => array or nil
# File lib/informix/scrollcursor.rb, line 103
103: def prev(offset = 1)
104: rel(-offset, Array, false)
105: end
Returns the previous offset th record. Negative indices count forward from the current position. Returns nil if the offset is out of range.
Stores the record fetched always in the same Array object.
cursor.prev!(offset = 1) => array or nil
# File lib/informix/scrollcursor.rb, line 114
114: def prev!(offset = 1)
115: rel(-offset, Array, true)
116: end
Returns the previous offset th record. Negative indices count forward from the current position. Returns nil if the offset is out of range.
cursor.prev_hash(offset = 1) => hash or nil
# File lib/informix/scrollcursor.rb, line 123
123: def prev_hash(offset = 1)
124: rel(-offset, Hash, false)
125: end
Returns the previous offset th record. Negative indices count forward from the current position. Returns nil if the offset is out of range.
Stores the record fetched always in the same Hash object.
cursor.prev_hash!(offset = 1) => hash or nil
# File lib/informix/scrollcursor.rb, line 134
134: def prev_hash!(offset = 1)
135: rel(-offset, Hash, true)
136: end
Base function for prev* and next* methods
/*
* Base function for prev* and next* methods
*/
static VALUE
rb_scrollcur_rel(VALUE self, VALUE offset, VALUE type, VALUE bang)
{
short c_bang;
cursor_t *c;
struct sqlda *output;
VALUE record;
/*
* EXEC SQL begin declare section;
*/
#line 2891 "informixc.ec"
#line 2892 "informixc.ec"
char *cid, *did;
long pos;
/*
* EXEC SQL end declare section;
*/
#line 2894 "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 2901 "informixc.ec"
{
#line 2901 "informixc.ec"
sqli_connect_set(0, did, 0);
#line 2901 "informixc.ec"
}
if (SQLCODE < 0)
return Qnil;
pos = NUM2LONG(offset);
output = c->daOutput;
cid = c->cursor_id;
/*
* EXEC SQL fetch relative :pos :cid using descriptor output;
*/
#line 2909 "informixc.ec"
{
#line 2909 "informixc.ec"
static ifx_sqlvar_t _sqibind[] =
{
{ 103, sizeof(pos), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
#line 2909 "informixc.ec"
};
static ifx_sqlda_t _SD0 = { 1, _sqibind, {0}, 1, 0 };
static _FetchSpec _FS1 = { 0, 7, 0 };
#line 2909 "informixc.ec"
_sqibind[0].sqldata = (char *) &pos;
sqli_curs_fetch(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, cid, 256), &_SD0, output, (char *)0, &_FS1);
#line 2909 "informixc.ec"
}
if (SQLCODE == SQLNOTFOUND)
return Qnil;
if (SQLCODE < 0)
raise_ifx_extended();
c_bang = RTEST(bang);
RECORD(c, type, c_bang, record);
return make_result(c, record);
}
Returns the record at index, or returns a subarray starting at start and continuing for length records. Negative indices count backward from the end of the cursor (-1 is the last element). Returns nil if the (starting) index is out of range.
Warning: if the (starting) index is negative and out of range, the position in the cursor is set to the last record. Otherwise the current position in the cursor is preserved.
cursor[index] => array or nil cursor[start, length] => array or nil cursor.slice(index) => array or nil cursor.slice(start, length) => array or nil
# File lib/informix/scrollcursor.rb, line 47
47: def slice(*args)
48: slice0(args, Array)
49: end
Returns the record at index. Negative indices count backward from the end of the cursor (-1 is the last element). Returns nil if the index is out of range.
Stores the record fetched always in the same Array object.
Warning: if the index is negative and out of range, the position in the cursor is set to the last record. Otherwise the current position in the cursor is preserved.
cursor.slice!(index) => array or nil
# File lib/informix/scrollcursor.rb, line 64
64: def slice!(index)
65: entry(index, Array, true)
66: end
Returns the record at index, or returns a subarray starting at start and continuing for length records. Negative indices count backward from the end of the cursor (-1 is the last element). Returns nil if the (starting) index is out of range.
Warning: if the (starting) index is negative and out of range, the position in the cursor is set to the last record. Otherwise the current position in the cursor is preserved.
cursor.slice_hash(index) => hash or nil cursor.slice_hash(start, length) => array or nil
# File lib/informix/scrollcursor.rb, line 79
79: def slice_hash(*args)
80: slice0(args, Hash)
81: end
Returns the record at index. Negative indices count backward from the end of the cursor (-1 is the last element). Returns nil if the index is out of range.
Stores the record fetched always in the same Hash object.
Warning: if the index is negative and out of range, the position in the cursor is set to the last record. Otherwise the current position in the cursor is preserved.
cursor.slice_hash!(index) => hash or nil
# File lib/informix/scrollcursor.rb, line 94
94: def slice_hash!(index)
95: entry(index, Hash, true)
96: end