File tree 3 files changed +44
-5
lines changed
3 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -32,16 +32,30 @@ Cursor.prototype.submit = function(connection) {
32
32
} , true )
33
33
34
34
con . flush ( )
35
+
36
+ con . once ( 'noData' , ifNoData )
37
+ con . once ( 'rowDescription' , function ( ) {
38
+ con . removeListener ( 'noData' , ifNoData ) ;
39
+ } ) ;
40
+
41
+ function ifNoData ( ) {
42
+ self . state = 'idle'
43
+ self . _shiftQueue ( ) ;
44
+ }
35
45
}
36
46
37
- Cursor . prototype . handleRowDescription = function ( msg ) {
38
- this . _result . addFields ( msg . fields )
39
- this . state = 'idle'
47
+ Cursor . prototype . _shiftQueue = function ( ) {
40
48
if ( this . _queue . length ) {
41
49
this . _getRows . apply ( this , this . _queue . shift ( ) )
42
50
}
43
51
}
44
52
53
+ Cursor . prototype . handleRowDescription = function ( msg ) {
54
+ this . _result . addFields ( msg . fields )
55
+ this . state = 'idle'
56
+ this . _shiftQueue ( ) ;
57
+ }
58
+
45
59
Cursor . prototype . handleDataRow = function ( msg ) {
46
60
var row = this . _result . parseRow ( msg . fields )
47
61
this . _rows . push ( row )
@@ -103,7 +117,7 @@ Cursor.prototype._getRows = function(rows, cb) {
103
117
}
104
118
105
119
Cursor . prototype . end = function ( cb ) {
106
- if ( this . statue != 'initialized' ) {
120
+ if ( this . state != 'initialized' ) {
107
121
this . connection . sync ( )
108
122
}
109
123
this . connection . end ( )
Original file line number Diff line number Diff line change 7
7
"test" : " test"
8
8
},
9
9
"scripts" : {
10
- "test" : " node test/"
10
+ "test" : " mocha test/"
11
11
},
12
12
"author" : " Brian M. Carlson" ,
13
13
"license" : " MIT" ,
Original file line number Diff line number Diff line change
1
+ var assert = require ( 'assert' )
2
+ var pg = require ( 'pg.js' ) ;
3
+ var Cursor = require ( '../' ) ;
4
+
5
+ describe ( 'queries with no data' , function ( ) {
6
+ beforeEach ( function ( done ) {
7
+ var client = this . client = new pg . Client ( )
8
+ client . connect ( done )
9
+ } )
10
+
11
+
12
+ afterEach ( function ( ) {
13
+ this . client . end ( )
14
+ } )
15
+
16
+ it ( 'handles queries that return no data' , function ( done ) {
17
+ var cursor = new Cursor ( 'CREATE TEMPORARY TABLE whatwhat (thing int)' )
18
+ this . client . query ( cursor )
19
+ cursor . read ( 100 , function ( err , rows ) {
20
+ assert . ifError ( err )
21
+ assert . equal ( rows . length , 0 )
22
+ done ( )
23
+ } )
24
+ } ) ;
25
+ } ) ;
You can’t perform that action at this time.
0 commit comments