Class: Fb::Cursor
- Inherits:
-
Data
- Object
- Data
- Fb::Cursor
- Defined in:
- ext/fb/fb_ext.c
Instance Method Summary collapse
-
#close(sql, *args) ⇒ nil
Closes the cursor.
-
#drop ⇒ nil
Drops the cursor.
-
#each(*args) ⇒ Object
Iterates the rows from the open cursor, passing each one to a block in either an Array or a Hash, where the column names or aliases from the query form the keys.
-
#fetch(*args) ⇒ Object
Reads and returns a single row from the open cursor in either an Array or a Hash, where the column names or aliases from the query form the keys.
-
#fetchall(*args) ⇒ Object
Returns the remainder of the rows from the open cursor, with each row represented by either an Array or a Hash, where the column names or aliases from the query form the keys.
-
#fields(*args) ⇒ Object
Return an array of Field Structs or a hash indexed by field name.
Instance Method Details
#close(sql, *args) ⇒ nil
Closes the cursor. If a transaction was automatically started for this cursor, the transaction is commited.
2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 |
# File 'ext/fb/fb_ext.c', line 2275
static VALUE cursor_close(VALUE self)
{
struct FbCursor *fb_cursor;
struct FbConnection *fb_connection;
Data_Get_Struct(self, struct FbCursor, fb_cursor);
Data_Get_Struct(fb_cursor->connection, struct FbConnection, fb_connection);
fb_cursor_check(fb_cursor);
/* Close the cursor */
if (fb_cursor->stmt) {
isc_dsql_free_statement(fb_connection->isc_status, &fb_cursor->stmt, DSQL_close);
fb_error_check_warn(fb_connection->isc_status);
isc_dsql_free_statement(fb_connection->isc_status, &fb_cursor->stmt, DSQL_drop);
fb_error_check(fb_connection->isc_status);
fb_cursor->open = Qfalse;
if (fb_connection->transact == fb_cursor->auto_transact) {
isc_commit_transaction(fb_connection->isc_status, &fb_connection->transact);
fb_cursor->auto_transact = fb_connection->transact;
fb_error_check(fb_connection->isc_status);
}
}
fb_cursor->fields_ary = Qnil;
fb_cursor->fields_hash = Qnil;
return Qnil;
}
|
#drop ⇒ nil
Drops the cursor.
TODO: How is this different from close()?
2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 |
# File 'ext/fb/fb_ext.c', line 2309
static VALUE cursor_drop(VALUE self)
{
struct FbCursor *fb_cursor;
struct FbConnection *fb_connection;
int i;
Data_Get_Struct(self, struct FbCursor, fb_cursor);
fb_cursor_drop(fb_cursor);
fb_cursor->fields_ary = Qnil;
fb_cursor->fields_hash = Qnil;
/* reset the reference from connection */
Data_Get_Struct(fb_cursor->connection, struct FbConnection, fb_connection);
for (i = 0; i < RARRAY_LEN(fb_connection->cursor); i++) {
if (RARRAY_PTR(fb_connection->cursor)[i] == self) {
RARRAY_PTR(fb_connection->cursor)[i] = Qnil;
}
}
return Qnil;
}
|
#each {|Array| ... } ⇒ nil #each(: array) {|Array| ... } ⇒ nil #each(: hash) {|Hash| ... } ⇒ nil
Iterates the rows from the open cursor, passing each one to a block in either an Array or a Hash, where the column names or aliases from the query form the keys. If the downcase_names attribute of the associated connection evaluates to true, the keys are lower case, except where the column name was mixed case to begin with.
2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 |
# File 'ext/fb/fb_ext.c', line 2247
static VALUE cursor_each(int argc, VALUE* argv, VALUE self)
{
VALUE row;
struct FbCursor *fb_cursor;
int hash_rows = hash_format(argc, argv);
Data_Get_Struct(self, struct FbCursor, fb_cursor);
fb_cursor_fetch_prep(fb_cursor);
for (;;) {
row = fb_cursor_fetch(fb_cursor);
if (NIL_P(row)) break;
if (hash_rows) {
rb_yield(fb_hash_from_ary(fb_cursor->fields_ary, row));
} else {
rb_yield(row);
}
}
return Qnil;
}
|
#fetch ⇒ Array #fetch(: array) ⇒ Array #fetch(: hash) ⇒ Hash
Reads and returns a single row from the open cursor in either an Array or a Hash, where the column names or aliases from the query form the keys. If the downcase_names attribute of the associated connection evaluates to true, the keys are lower case, except where the column name was mixed case to begin with.
2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 |
# File 'ext/fb/fb_ext.c', line 2188
static VALUE cursor_fetch(int argc, VALUE* argv, VALUE self)
{
VALUE ary;
struct FbCursor *fb_cursor;
int hash_row = hash_format(argc, argv);
Data_Get_Struct(self, struct FbCursor, fb_cursor);
fb_cursor_fetch_prep(fb_cursor);
ary = fb_cursor_fetch(fb_cursor);
if (NIL_P(ary)) return Qnil;
return hash_row ? fb_hash_from_ary(fb_cursor->fields_ary, ary) : ary;
}
|
#fetchall ⇒ Array of Arrays #fetchall(: array) ⇒ Array of Arrays #fetchall(: hash) ⇒ Array of Hashes
Returns the remainder of the rows from the open cursor, with each row represented by either an Array or a Hash, where the column names or aliases from the query form the keys. If the downcase_names attribute of the associated connection evaluates to true, the keys are lower case, except where the column name was mixed case to begin with.
2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 |
# File 'ext/fb/fb_ext.c', line 2213
static VALUE cursor_fetchall(int argc, VALUE* argv, VALUE self)
{
VALUE ary, row;
struct FbCursor *fb_cursor;
int hash_rows = hash_format(argc, argv);
Data_Get_Struct(self, struct FbCursor, fb_cursor);
fb_cursor_fetch_prep(fb_cursor);
ary = rb_ary_new();
for (;;) {
row = fb_cursor_fetch(fb_cursor);
if (NIL_P(row)) break;
if (hash_rows) {
rb_ary_push(ary, fb_hash_from_ary(fb_cursor->fields_ary, row));
} else {
rb_ary_push(ary, row);
}
}
return ary;
}
|
#fields ⇒ Array #fields(: array) ⇒ Array #fields(: hash) ⇒ Hash
Return an array of Field Structs or a hash indexed by field name. If the downcase_names attribute of the associated connection evaluates to true, the keys are lower case, except where the column name was mixed case to begin with.
2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 |
# File 'ext/fb/fb_ext.c', line 2340
static VALUE cursor_fields(int argc, VALUE* argv, VALUE self)
{
struct FbCursor *fb_cursor;
Data_Get_Struct(self, struct FbCursor, fb_cursor);
if (argc == 0 || argv[0] == ID2SYM(rb_intern("array"))) {
return fb_cursor->fields_ary;
} else if (argv[0] == ID2SYM(rb_intern("hash"))) {
return fb_cursor->fields_hash;
} else {
rb_raise(rb_eFbError, "Unknown format");
}
}
|