6565#define SPG_YIELD_MKV_HASH_GROUPS 11
6666#define SPG_YIELD_KMV_HASH_GROUPS 12
6767#define SPG_YIELD_MKMV_HASH_GROUPS 13
68+ #define SPG_YIELD_COLUMN_ARRAY 14
69+ #define SPG_YIELD_COLUMNS_ARRAY 15
6870
6971/* External functions defined by ruby-pg */
7072PGconn * pg_get_pgconn (VALUE );
@@ -91,6 +93,7 @@ static VALUE spg_vmasks6;
9193static VALUE spg_sym_utc ;
9294static VALUE spg_sym_local ;
9395static VALUE spg_sym_map ;
96+ static VALUE spg_sym_map_array ;
9497static VALUE spg_sym_first ;
9598static VALUE spg_sym_array ;
9699static VALUE spg_sym_hash ;
@@ -1405,6 +1408,12 @@ static VALUE spg_yield_hash_rows_internal(VALUE self, PGresult *res, int enc_ind
14051408 } else if (rb_type (pg_value ) == T_ARRAY ) {
14061409 type = SPG_YIELD_COLUMNS ;
14071410 }
1411+ } else if (pg_type == spg_sym_map_array ) {
1412+ if (SYMBOL_P (pg_value )) {
1413+ type = SPG_YIELD_COLUMN_ARRAY ;
1414+ } else if (rb_type (pg_value ) == T_ARRAY ) {
1415+ type = SPG_YIELD_COLUMNS_ARRAY ;
1416+ }
14081417 } else if (pg_type == spg_sym_first ) {
14091418 type = SPG_YIELD_FIRST ;
14101419 } else if (pg_type == spg_sym_array ) {
@@ -1463,6 +1472,35 @@ static VALUE spg_yield_hash_rows_internal(VALUE self, PGresult *res, int enc_ind
14631472 rb_yield (spg__col_values (self , h , colsyms , nfields , res , i , colconvert , enc_index ));
14641473 }
14651474 break ;
1475+ case SPG_YIELD_COLUMN_ARRAY :
1476+ /* Array containing single column */
1477+ {
1478+ VALUE ary = rb_ary_new2 (ntuples );
1479+ j = spg__field_id (pg_value , colsyms , nfields );
1480+ if (j == -1 ) {
1481+ for (i = 0 ; i < ntuples ; i ++ ) {
1482+ rb_ary_store (ary , i , Qnil );
1483+ }
1484+ }
1485+ else {
1486+ for (i = 0 ; i < ntuples ; i ++ ) {
1487+ rb_ary_store (ary , i , spg__col_value (self , res , i , j , colconvert , enc_index ));
1488+ }
1489+ }
1490+ rb_yield (ary );
1491+ }
1492+ break ;
1493+ case SPG_YIELD_COLUMNS_ARRAY :
1494+ /* Array containing arrays of columns */
1495+ {
1496+ VALUE ary = rb_ary_new2 (ntuples );
1497+ h = spg__field_ids (pg_value , colsyms , nfields );
1498+ for (i = 0 ; i < ntuples ; i ++ ) {
1499+ rb_ary_store (ary , i , spg__col_values (self , h , colsyms , nfields , res , i , colconvert , enc_index ));
1500+ }
1501+ rb_yield (ary );
1502+ }
1503+ break ;
14661504 case SPG_YIELD_FIRST :
14671505 /* First column */
14681506 for (i = 0 ; i < ntuples ; i ++ ) {
@@ -1918,6 +1956,7 @@ void Init_sequel_pg(void) {
19181956 spg_sym_utc = ID2SYM (rb_intern ("utc" ));
19191957 spg_sym_local = ID2SYM (rb_intern ("local" ));
19201958 spg_sym_map = ID2SYM (rb_intern ("map" ));
1959+ spg_sym_map_array = ID2SYM (rb_intern ("map_array" ));
19211960 spg_sym_first = ID2SYM (rb_intern ("first" ));
19221961 spg_sym_array = ID2SYM (rb_intern ("array" ));
19231962 spg_sym_hash = ID2SYM (rb_intern ("hash" ));
0 commit comments