This repository was archived by the owner on Sep 8, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed
Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ Query.prototype.handleRowDescription = function(msg) {
6363 var format = field . format ;
6464 this . _fieldNames [ i ] = field . name ;
6565 this . _fieldConverters [ i ] = Types . getTypeParser ( field . dataTypeID , format ) ;
66+ this . _result . addField ( field ) ;
6667 }
6768} ;
6869
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ var Result = function() {
66 this . rowCount = null ;
77 this . oid = null ;
88 this . rows = [ ] ;
9+ this . fields = [ ] ;
910} ;
1011
1112var matchRegexp = / ( [ A - Z a - z ] + ) ? ( \d + ) ? ( \d + ) ? / ;
@@ -37,4 +38,9 @@ Result.prototype.addRow = function(row) {
3738 this . rows . push ( row ) ;
3839} ;
3940
41+ //Add a field definition to the result
42+ Result . prototype . addField = function ( field ) {
43+ this . fields . push ( field ) ;
44+ } ;
45+
4046module . exports = Result ;
Original file line number Diff line number Diff line change 1+ var helper = require ( __dirname + '/test-helper' ) ;
2+ var pg = helper . pg ;
3+ var config = helper . config ;
4+
5+ test ( 'can access results when no rows are returned' , function ( ) {
6+ if ( config . native ) return false ;
7+ var checkResult = function ( result ) {
8+ assert ( result . fields , 'should have fields definition' ) ;
9+ assert . equal ( result . fields . length , 1 ) ;
10+ assert . equal ( result . fields [ 0 ] . name , 'val' ) ;
11+ assert . equal ( result . fields [ 0 ] . dataTypeID , 25 ) ;
12+ pg . end ( ) ;
13+ } ;
14+
15+ pg . connect ( config , assert . success ( function ( client , done ) {
16+ var query = client . query ( 'select $1::text as val limit 0' , [ 'hi' ] , assert . success ( function ( result ) {
17+ checkResult ( result ) ;
18+ done ( ) ;
19+ } ) ) ;
20+
21+ assert . emits ( query , 'end' , checkResult ) ;
22+ } ) ) ;
23+ } ) ;
You can’t perform that action at this time.
0 commit comments