@@ -29,10 +29,14 @@ var Query = function (config, values, callback) {
29
29
// use unique portal name each time
30
30
this . portal = config . portal || ''
31
31
this . callback = config . callback
32
+ this . _rowMode = config . rowMode
32
33
if ( process . domain && config . callback ) {
33
34
this . callback = process . domain . bind ( config . callback )
34
35
}
35
- this . _result = new Result ( config . rowMode , config . types )
36
+ this . _result = new Result ( this . _rowMode , this . types )
37
+
38
+ // potential for multiple results
39
+ this . _results = this . _result
36
40
this . isPreparedStatement = false
37
41
this . _canceledDueToError = false
38
42
this . _promise = null
@@ -54,10 +58,24 @@ Query.prototype.requiresPreparation = function () {
54
58
return this . values . length > 0
55
59
}
56
60
61
+ Query . prototype . _checkForMultirow = function ( ) {
62
+ // if we already have a result with a command property
63
+ // then we've already executed one query in a multi-statement simple query
64
+ // turn our results into an array of results
65
+ if ( this . _result . command ) {
66
+ if ( ! Array . isArray ( this . _results ) ) {
67
+ this . _results = [ this . _result ]
68
+ }
69
+ this . _result = new Result ( this . _rowMode , this . types )
70
+ this . _results . push ( this . _result )
71
+ }
72
+ }
73
+
57
74
// associates row metadata from the supplied
58
75
// message with this query object
59
76
// metadata used when parsing row results
60
77
Query . prototype . handleRowDescription = function ( msg ) {
78
+ this . _checkForMultirow ( )
61
79
this . _result . addFields ( msg . fields )
62
80
this . _accumulateRows = this . callback || ! this . listeners ( 'row' ) . length
63
81
}
@@ -83,6 +101,7 @@ Query.prototype.handleDataRow = function (msg) {
83
101
}
84
102
85
103
Query . prototype . handleCommandComplete = function ( msg , con ) {
104
+ this . _checkForMultirow ( )
86
105
this . _result . addCommandComplete ( msg )
87
106
// need to sync after each command complete of a prepared statement
88
107
if ( this . isPreparedStatement ) {
@@ -104,9 +123,9 @@ Query.prototype.handleReadyForQuery = function (con) {
104
123
return this . handleError ( this . _canceledDueToError , con )
105
124
}
106
125
if ( this . callback ) {
107
- this . callback ( null , this . _result )
126
+ this . callback ( null , this . _results )
108
127
}
109
- this . emit ( 'end' , this . _result )
128
+ this . emit ( 'end' , this . _results )
110
129
}
111
130
112
131
Query . prototype . handleError = function ( err , connection ) {
0 commit comments