File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ role DBDish::StatementHandle does DBDish::ErrorHandling {
59
59
}
60
60
61
61
method fetchrow_hashref { $ . fetchrow-hash }
62
+ method fetchrow_typedhash { die " Your selected backend does not support/implement typed values" }
62
63
63
64
method fetchall-hash {
64
65
my @ names := self . column_names;
Original file line number Diff line number Diff line change @@ -136,6 +136,7 @@ constant %oid-to-type-name = (
136
136
137
137
). hash;
138
138
139
+
139
140
constant CONNECTION_OK = 0 ;
140
141
constant CONNECTION_BAD = 1 ;
141
142
@@ -327,6 +328,26 @@ class DBDish::Pg::StatementHandle does DBDish::StatementHandle {
327
328
return $ results_ref ;
328
329
}
329
330
331
+ # Try to map pg type to perl type
332
+ method fetchrow_typedhash {
333
+ my Str @ values = self . fetchrow_array;
334
+ return Any if ! @ values . defined ;
335
+ my @ names = self . column_names;
336
+ my @ types = self . column_oids;
337
+ my % hash ;
338
+ my % p = ' f' => False , ' t' => True ;
339
+ for 0 .. (@ values . elems-1) -> $ i {
340
+ given (% oid-to-type-name {@ types [$ i ]}) {
341
+ % hash {@ names [$ i ]} = @ values [$ i ] when ' Str' ;
342
+ % hash {@ names [$ i ]} = @ values [$ i ]. Num when ' Num' ;
343
+ % hash {@ names [$ i ]} = @ values [$ i ]. Int when ' Int' ;
344
+ % hash {@ names [$ i ]} = % p {@ values [$ i ]} when ' Bool' ;
345
+ % hash {@ names [$ i ]} = @ values [$ i ]. Real when ' Real' ;
346
+ }
347
+ }
348
+ return % hash ;
349
+ }
350
+
330
351
method finish () {
331
352
if defined ($ ! result ) {
332
353
PQclear($ ! result );
You can’t perform that action at this time.
0 commit comments