Class Informix::ScrollCursor
In: lib/informix/scrollcursor.rb
ext/informixc.c
Parent: SequentialCursor

The ScrollCursor class adds Array-like capabilities to the SequentialCursor class

Methods

[]   current   current!   current_hash   current_hash!   entry   first   first!   first_hash   first_hash!   last   last!   last_hash   last_hash!   next   next!   next_hash   next_hash!   prev   prev!   prev_hash   prev_hash!   rel   slice   slice!   slice_hash   slice_hash!  

Public Instance methods

[](*args)

Alias for slice

Returns the current record of the cursor. If the cursor is empty, returns nil.

  cursor.current  => array or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 252
252:     def current
253:       entry(nil, Array, false)
254:     end

Returns the current record of the cursor. If the cursor is empty, returns nil.

Stores the record fetched always in the same Array object.

  cursor.current!  => array or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 262
262:     def current!
263:       entry(nil, Array, true)
264:     end

Returns the current record of the cursor. If the cursor is empty, returns nil.

  cursor.current_hash  => hash or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 270
270:     def current_hash
271:       entry(nil, Hash, false)
272:     end

Returns the current record of the cursor. If the cursor is empty, returns nil.

Stores the record fetched always in the same Hash object.

  cursor.current_hash!  => hash or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 280
280:     def current_hash!
281:       entry(nil, Hash, true)
282:     end

Provides the Array-like functionality for scroll cursors when using the cursor[index] syntax

[Source]

/*
 * 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 first record of the cursor. If the cursor is empty, returns nil.

  cursor.first  => array or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 180
180:     def first
181:       entry(0, Array, false)
182:     end

Returns the first record of the cursor. If the cursor is empty, returns nil.

Stores the record fetched always in the same Array object.

  cursor.first!  => array or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 190
190:     def first!
191:       entry(0, Array, true)
192:     end

Returns the first record of the cursor. If the cursor is empty, returns nil.

  cursor.first_hash  => hash or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 198
198:     def first_hash
199:       entry(0, Hash, false)
200:     end

Returns the first record of the cursor. If the cursor is empty, returns nil.

Stores the record fetched always in the same Hash object.

  cursor.first_hash!  => hash or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 208
208:     def first_hash!
209:       entry(0, Hash, true)
210:     end

Returns the last record of the cursor. If the cursor is empty, returns nil.

  cursor.last  => array or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 216
216:     def last
217:       entry(-1, Array, false)
218:     end

Returns the last record of the cursor. If the cursor is empty, returns nil.

Stores the record fetched always in the same Array object.

  cursor.last!  => array or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 226
226:     def last!
227:       entry(-1, Array, true)
228:     end

Returns the last record of the cursor. If the cursor is empty, returns nil.

  cursor.last_hash  => hash or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 234
234:     def last_hash
235:       entry(-1, Hash, false)
236:     end

Returns the last record of the cursor. If the cursor is empty, returns nil.

Stores the record fetched always in the same Hash object.

  cursor.last_hash!  => hash or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 244
244:     def last_hash!
245:       entry(-1, Hash, true)
246:     end

Returns the next offset th record. Negative indices count backward from the current position. Returns nil if the offset is out of range.

  cursor.next(offset = 1)  => array or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 143
143:     def next(offset = 1)
144:       rel(offset, Array, false)
145:     end

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

[Source]

     # File lib/informix/scrollcursor.rb, line 154
154:     def next!(offset = 1)
155:       rel(offset, Array, true)
156:     end

Returns the next offset th record. Negative indices count backward from the current position. Returns nil if the offset is out of range.

  cursor.next_hash(offset = 1)  => hash or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 163
163:     def next_hash(offset = 1)
164:       rel(offset, Hash, false)
165:     end

Returns the next offset th record. Negative indices count backward from the current position. Returns nil if the offset is out of range.

  cursor.next_hash!(offset = 1)  => hash or nil

[Source]

     # File lib/informix/scrollcursor.rb, line 172
172:     def next_hash!(offset = 1)
173:       rel(offset, Hash, true)
174:     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

[Source]

     # 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

[Source]

     # 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

[Source]

     # 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

[Source]

     # 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

[Source]

/*
 * 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

[Source]

    # 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

[Source]

    # 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

[Source]

    # 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

[Source]

    # File lib/informix/scrollcursor.rb, line 94
94:     def slice_hash!(index)
95:       entry(index, Hash, true)
96:     end

[Validate]