File tree 3 files changed +30
-0
lines changed
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) {
63
63
var format = field . format ;
64
64
this . _fieldNames [ i ] = field . name ;
65
65
this . _fieldConverters [ i ] = Types . getTypeParser ( field . dataTypeID , format ) ;
66
+ this . _result . addField ( field ) ;
66
67
}
67
68
} ;
68
69
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ var Result = function() {
6
6
this . rowCount = null ;
7
7
this . oid = null ;
8
8
this . rows = [ ] ;
9
+ this . fields = [ ] ;
9
10
} ;
10
11
11
12
var matchRegexp = / ( [ A - Z a - z ] + ) ? ( \d + ) ? ( \d + ) ? / ;
@@ -37,4 +38,9 @@ Result.prototype.addRow = function(row) {
37
38
this . rows . push ( row ) ;
38
39
} ;
39
40
41
+ //Add a field definition to the result
42
+ Result . prototype . addField = function ( field ) {
43
+ this . fields . push ( field ) ;
44
+ } ;
45
+
40
46
module . 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