|
71 | 71 | #define SPG_YIELD_MKMV_HASH_GROUPS 13 |
72 | 72 | #define SPG_YIELD_COLUMN_ARRAY 14 |
73 | 73 | #define SPG_YIELD_COLUMNS_ARRAY 15 |
| 74 | +#define SPG_YIELD_FIRST_ARRAY 16 |
| 75 | +#define SPG_YIELD_ARRAY_ARRAY 17 |
74 | 76 |
|
75 | 77 | /* External functions defined by ruby-pg */ |
76 | 78 | PGconn* pg_get_pgconn(VALUE); |
@@ -99,7 +101,9 @@ static VALUE spg_sym_local; |
99 | 101 | static VALUE spg_sym_map; |
100 | 102 | static VALUE spg_sym_map_array; |
101 | 103 | static VALUE spg_sym_first; |
| 104 | +static VALUE spg_sym_first_array; |
102 | 105 | static VALUE spg_sym_array; |
| 106 | +static VALUE spg_sym_array_array; |
103 | 107 | static VALUE spg_sym_hash; |
104 | 108 | static VALUE spg_sym_hash_groups; |
105 | 109 | static VALUE spg_sym_model; |
@@ -1422,6 +1426,10 @@ static VALUE spg_yield_hash_rows_internal(VALUE self, PGresult *res, int enc_ind |
1422 | 1426 | type = SPG_YIELD_FIRST; |
1423 | 1427 | } else if (pg_type == spg_sym_array) { |
1424 | 1428 | type = SPG_YIELD_ARRAY; |
| 1429 | + } else if (pg_type == spg_sym_first_array) { |
| 1430 | + type = SPG_YIELD_FIRST_ARRAY; |
| 1431 | + } else if (pg_type == spg_sym_array_array) { |
| 1432 | + type = SPG_YIELD_ARRAY_ARRAY; |
1425 | 1433 | } else if ((pg_type == spg_sym_hash || pg_type == spg_sym_hash_groups) && rb_type(pg_value) == T_ARRAY) { |
1426 | 1434 | VALUE pg_value_key, pg_value_value; |
1427 | 1435 | pg_value_key = rb_ary_entry(pg_value, 0); |
@@ -1521,6 +1529,28 @@ static VALUE spg_yield_hash_rows_internal(VALUE self, PGresult *res, int enc_ind |
1521 | 1529 | rb_yield(h); |
1522 | 1530 | } |
1523 | 1531 | break; |
| 1532 | + case SPG_YIELD_FIRST_ARRAY: |
| 1533 | + /* Array of first column */ |
| 1534 | + h = rb_ary_new2(ntuples); |
| 1535 | + for(i=0; i<ntuples; i++) { |
| 1536 | + rb_ary_store(h, i, spg__col_value(self, res, i, 0, colconvert, enc_index)); |
| 1537 | + } |
| 1538 | + rb_yield(h); |
| 1539 | + break; |
| 1540 | + case SPG_YIELD_ARRAY_ARRAY: |
| 1541 | + /* Array of arrays of all columns */ |
| 1542 | + { |
| 1543 | + VALUE ary = rb_ary_new2(ntuples); |
| 1544 | + for(i=0; i<ntuples; i++) { |
| 1545 | + h = rb_ary_new2(nfields); |
| 1546 | + for(j=0; j<nfields; j++) { |
| 1547 | + rb_ary_store(h, j, spg__col_value(self, res, i, j, colconvert, enc_index)); |
| 1548 | + } |
| 1549 | + rb_ary_store(ary, i, h); |
| 1550 | + } |
| 1551 | + rb_yield(ary); |
| 1552 | + } |
| 1553 | + break; |
1524 | 1554 | case SPG_YIELD_KV_HASH: |
1525 | 1555 | case SPG_YIELD_KV_HASH_GROUPS: |
1526 | 1556 | /* Hash with single key and single value */ |
@@ -1967,6 +1997,8 @@ void Init_sequel_pg(void) { |
1967 | 1997 | spg_sym_map_array = ID2SYM(rb_intern("map_array")); |
1968 | 1998 | spg_sym_first = ID2SYM(rb_intern("first")); |
1969 | 1999 | spg_sym_array = ID2SYM(rb_intern("array")); |
| 2000 | + spg_sym_first_array = ID2SYM(rb_intern("first_array")); |
| 2001 | + spg_sym_array_array = ID2SYM(rb_intern("array_array")); |
1970 | 2002 | spg_sym_hash = ID2SYM(rb_intern("hash")); |
1971 | 2003 | spg_sym_hash_groups = ID2SYM(rb_intern("hash_groups")); |
1972 | 2004 | spg_sym_model = ID2SYM(rb_intern("model")); |
|
0 commit comments