Class Informix::SequentialCursor
In: lib/informix/seqcursor.rb
ext/informixc.c
Parent: CursorBase

The SequentialCursor class adds fetching capabilities and iterators to the CursorBase class.

Methods

Included Modules

Enumerable

Public Instance methods

Iterates over the remaining records, passing each record to the block as an array.

Returns self.

  cursor.each {|record| block } => cursor

[Source]

     # File lib/informix/seqcursor.rb, line 115
115:     def each(&block)
116:       each0(Array, false, &block)
117:     end

Iterates over the remaining records, passing each record to the block as an array. No new Array objects are created for each record. The same Array object is reused in each call.

Returns self.

  cursor.each! {|record| block } => cursor

[Source]

     # File lib/informix/seqcursor.rb, line 126
126:     def each!(&block)
127:       each0(Array, true, &block)
128:     end

Base function for each* methods, except each*_by

[Source]

/*
 * Base function for each* methods, except each*_by
 */
static VALUE
each(VALUE self, VALUE type, VALUE bang)
{
        cursor_t *c;
/*
 *      EXEC SQL begin declare section;
 */
#line 2693 "informixc.ec"
#line 2694 "informixc.ec"
  char *cid, *did;
/*
 *      EXEC SQL end   declare section;
 */
#line 2695 "informixc.ec"

        short c_bang;
        struct sqlda *output;
        VALUE record;

        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 2705 "informixc.ec"
  {
#line 2705 "informixc.ec"
  sqli_connect_set(0, did, 0);
#line 2705 "informixc.ec"
  }
        if (SQLCODE < 0)
                raise_ifx_extended();

        output = c->daOutput;
        cid = c->cursor_id;

        for(;;) {
/*
 *              EXEC SQL fetch :cid using descriptor output;
 */
#line 2713 "informixc.ec"
  {
#line 2713 "informixc.ec"
  static _FetchSpec _FS0 = { 0, 1, 0 };
  sqli_curs_fetch(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, cid, 256), (ifx_sqlda_t *)0, output, (char *)0, &_FS0);
#line 2713 "informixc.ec"
  }
                if (SQLCODE < 0)
                        raise_ifx_extended();

                if (SQLCODE == SQLNOTFOUND)
                        return self;
                c_bang = RTEST(bang);
                RECORD(c, type, c_bang, record);
                rb_yield(make_result(c, record));
        }
}

Iterates over the remaining records, passing at most n records to the block as arrays.

Returns self.

  cursor.each_by(n) {|records| block } => cursor

[Source]

     # File lib/informix/seqcursor.rb, line 155
155:     def each_by(n, &block)
156:       each_by0(n, Array, &block)
157:     end

Base function for each*_by methods

[Source]

/*
 * Base function for each*_by methods
 */
static VALUE
each_by(VALUE self, VALUE n, VALUE type)
{
        VALUE records;

        for(;;) {
                records = fetch_many(self, n, type);
                if (RARRAY(records)->len == 0)
                        return self;
                rb_yield(records);
        }
}

Iterates over the remaining records, passing each record to the block as a hash.

  cursor.each_hash {|record| block } => cursor

[Source]

     # File lib/informix/seqcursor.rb, line 134
134:     def each_hash(&block)
135:       each0(Hash, false, &block)
136:     end

Iterates over the remaining records, passing each record to the block as a hash. No new Hash objects are created for each record. The same Hash object is reused in each call.

Returns self.

  cursor.each_hash! {|record| block } => cursor

[Source]

     # File lib/informix/seqcursor.rb, line 145
145:     def each_hash!(&block)
146:       each0(Hash, true, &block)
147:     end

Iterates over the remaining records, passing at most n records to the block as hashes.

Returns self.

  cursor.each_hash_by(n) {|records| block } => cursor

[Source]

     # File lib/informix/seqcursor.rb, line 165
165:     def each_hash_by(n, &block)
166:       each_by0(n, Hash, &block)
167:     end

Fetches the next record.

Returns the record fetched as an array, or nil if there are no records left.

  cursor.fetch  => array or nil

[Source]

    # File lib/informix/seqcursor.rb, line 42
42:     def fetch
43:       fetch0(Array, false)
44:     end

Fetches the next record, storing it in the same Array object every time it is called.

Returns the record fetched as an array, or nil if there are no records left.

  cursor.fetch!  => array or nil

[Source]

    # File lib/informix/seqcursor.rb, line 53
53:     def fetch!
54:       fetch0(Array, true)
55:     end

Base function for fetch* methods, except *_many

[Source]

/*
 * Base function for fetch* methods, except *_many
 */
static VALUE
fetch(VALUE self, VALUE type, VALUE bang)
{
/*
 *      EXEC SQL begin declare section;
 */
#line 2600 "informixc.ec"
#line 2601 "informixc.ec"
  char *cid, *did;
/*
 *      EXEC SQL end   declare section;
 */
#line 2602 "informixc.ec"

        short c_bang;
        cursor_t *c;
        struct sqlda *output;
        VALUE record;

        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 2613 "informixc.ec"
  {
#line 2613 "informixc.ec"
  sqli_connect_set(0, did, 0);
#line 2613 "informixc.ec"
  }
        if (SQLCODE < 0)
                raise_ifx_extended();

        output = c->daOutput;
        cid = c->cursor_id;

/*
 *      EXEC SQL fetch :cid using descriptor output;
 */
#line 2620 "informixc.ec"
  {
#line 2620 "informixc.ec"
  static _FetchSpec _FS0 = { 0, 1, 0 };
  sqli_curs_fetch(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, cid, 256), (ifx_sqlda_t *)0, output, (char *)0, &_FS0);
#line 2620 "informixc.ec"
  }
        if (SQLCODE < 0)
                raise_ifx_extended();

        if (SQLCODE == SQLNOTFOUND)
                return Qnil;

        c_bang = RTEST(bang);
        RECORD(c, type, c_bang, record);
        return make_result(c, record);
}

Returns all the records left as an array of arrays

  cursor.fetch_all  => array

[Source]

     # File lib/informix/seqcursor.rb, line 98
 98:     def fetch_all
 99:       fetch_many0(nil, Array)
100:     end

Fetches the next record.

Returns the record fetched as a hash, or nil if there are no records left.

  cursor.fetch_hash  => hash or nil

[Source]

    # File lib/informix/seqcursor.rb, line 63
63:     def fetch_hash
64:       fetch0(Hash, false)
65:     end

Fetches the next record, storing it in the same Hash object every time it is called.

Returns the record fetched as a hash, or nil if there are no records left.

  cursor.fetch_hash!  => hash or nil

[Source]

    # File lib/informix/seqcursor.rb, line 74
74:     def fetch_hash!
75:       fetch0(Hash, true)
76:     end

Returns all the records left as an array of hashes

  cursor.fetch_hash_all  => array

[Source]

     # File lib/informix/seqcursor.rb, line 105
105:     def fetch_hash_all
106:       fetch_many0(nil, Hash)
107:     end

Reads at most n records. Returns the records read as an array of hashes.

  cursor.fetch_hash_many(n)  => array

[Source]

    # File lib/informix/seqcursor.rb, line 91
91:     def fetch_hash_many(n)
92:       fetch_many0(n, Hash)
93:     end

Reads at most n records.

Returns the records read as an array of arrays

  cursor.fetch_many(n)  => array

[Source]

    # File lib/informix/seqcursor.rb, line 83
83:     def fetch_many(n)
84:       fetch_many0(n, Array)
85:     end

Base function for fetch*_many, fetch*_all and each_by methods

[Source]

/*
 * Base function for fetch*_many, fetch*_all and each_by methods
 */
static VALUE
fetch_many(VALUE self, VALUE n, VALUE type)
{
/*
 *      EXEC SQL begin declare section;
 */
#line 2638 "informixc.ec"
#line 2639 "informixc.ec"
  char *cid, *did;
/*
 *      EXEC SQL end   declare section;
 */
#line 2640 "informixc.ec"

        cursor_t *c;
        struct sqlda *output;
        VALUE record, records;
        register long i, max;
        register int all = n == Qnil;

        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 2652 "informixc.ec"
  {
#line 2652 "informixc.ec"
  sqli_connect_set(0, did, 0);
#line 2652 "informixc.ec"
  }
        if (SQLCODE < 0)
                raise_ifx_extended();

        output = c->daOutput;
        cid = c->cursor_id;

        if (!all) {
                max = FIX2LONG(n);
                records = rb_ary_new2(max);
        }
        else {
                records = rb_ary_new();
        }

        for(i = 0; all || i < max; i++) {
/*
 *              EXEC SQL fetch :cid using descriptor output;
 */
#line 2668 "informixc.ec"
  {
#line 2668 "informixc.ec"
  static _FetchSpec _FS0 = { 0, 1, 0 };
  sqli_curs_fetch(ESQLINTVERSION, sqli_curs_locate(ESQLINTVERSION, cid, 256), (ifx_sqlda_t *)0, output, (char *)0, &_FS0);
#line 2668 "informixc.ec"
  }
                if (SQLCODE < 0)
                        raise_ifx_extended();

                if (SQLCODE == SQLNOTFOUND)
                        break;

                if (type == rb_cArray)
                        record = rb_ary_new2(c->daOutput->sqld);
                else
                        record = rb_hash_new();
                rb_ary_store(records, i, make_result(c, record));
        }

        return records;
}

[Validate]