@@ -38,7 +38,7 @@ var formatter = {
38
38
. push_cstring ( query )
39
39
. push_int16 ( var_types . length ) ;
40
40
var_types . each ( function ( var_type ) {
41
- stream . push_int32 ( var_type ) ;
41
+ builder . push_int32 ( var_type ) ;
42
42
} ) ;
43
43
return builder ;
44
44
} ,
@@ -70,8 +70,8 @@ var formatter = {
70
70
71
71
// Parse response streams from the server
72
72
function parse_response ( code , stream ) {
73
- var input = new bits . Decoder ( stream ) ;
74
- var type , args ;
73
+ var input , type , args , num_fields , data , size , i ;
74
+ input = new bits . Decoder ( stream ) ;
75
75
args = [ ] ;
76
76
switch ( code ) {
77
77
case 'R' :
@@ -126,10 +126,10 @@ function parse_response(code, stream) {
126
126
break ;
127
127
case 'T' :
128
128
type = "RowDescription" ;
129
- var num_fields = stream . shift_int16 ( ) ;
130
- var row = [ ] ;
131
- for ( var i = 0 ; i < num_fields ; i += 1 ) {
132
- row . push ( {
129
+ num_fields = stream . shift_int16 ( ) ;
130
+ data = [ ] ;
131
+ for ( i = 0 ; i < num_fields ; i += 1 ) {
132
+ data . push ( {
133
133
field : stream . shift_cstring ( ) ,
134
134
table_id : stream . shift_int32 ( ) ,
135
135
column_id : stream . shift_int16 ( ) ,
@@ -139,14 +139,14 @@ function parse_response(code, stream) {
139
139
format_code : stream . shift_int16 ( )
140
140
} ) ;
141
141
}
142
- args = [ row ] ;
142
+ args = [ data ] ;
143
143
break ;
144
144
case 'D' :
145
145
type = "DataRow" ;
146
- var data = [ ] ;
147
- var num_cols = stream . shift_int16 ( ) ;
148
- for ( i = 0 ; i < num_cols ; i += 1 ) {
149
- var size = stream . shift_int32 ( ) ;
146
+ data = [ ] ;
147
+ num_fields = stream . shift_int16 ( ) ;
148
+ for ( i = 0 ; i < num_fields ; i += 1 ) {
149
+ size = stream . shift_int32 ( ) ;
150
150
if ( size === - 1 ) {
151
151
data . push ( null ) ;
152
152
} else {
@@ -168,20 +168,18 @@ function parse_response(code, stream) {
168
168
169
169
170
170
exports . Connection = function ( database , username , password , port ) {
171
+ var connection , events , query_queue , row_description , query_callback , results , readyState , closeState ;
171
172
172
173
// Default to port 5432
173
174
if ( port === undefined ) {
174
175
port = 5432 ;
175
176
}
176
177
177
- var connection = tcp . createConnection ( port ) ;
178
- var events = new process . EventEmitter ( ) ;
179
- var query_queue = [ ] ;
180
- var row_description ;
181
- var query_callback ;
182
- var results ;
183
- var readyState = false ;
184
- var closeState = false ;
178
+ connection = tcp . createConnection ( port ) ;
179
+ events = new process . EventEmitter ( ) ;
180
+ query_queue = [ ] ;
181
+ readyState = false ;
182
+ closeState = false ;
185
183
186
184
// Sends a message to the postgres server
187
185
function sendMessage ( type , args ) {
@@ -201,19 +199,20 @@ exports.Connection = function (database, username, password, port) {
201
199
sendMessage ( 'StartupMessage' , [ { user : username , database : database } ] ) ;
202
200
} ) ;
203
201
connection . addListener ( "receive" , function ( data ) {
204
- var input = new bits . Decoder ( data ) ;
202
+ var input , code , len , stream , command ;
203
+ input = new bits . Decoder ( data ) ;
205
204
if ( exports . DEBUG > 2 ) {
206
205
sys . debug ( "<-" + JSON . stringify ( data ) ) ;
207
206
}
208
207
209
208
while ( input . data . length > 0 ) {
210
- var code = input . shift_code ( ) ;
211
- var len = input . shift_int32 ( ) ;
212
- var stream = new bits . Decoder ( input . shift_raw_string ( len - 4 ) ) ;
209
+ code = input . shift_code ( ) ;
210
+ len = input . shift_int32 ( ) ;
211
+ stream = new bits . Decoder ( input . shift_raw_string ( len - 4 ) ) ;
213
212
if ( exports . DEBUG > 1 ) {
214
213
sys . debug ( "stream: " + code + " " + JSON . stringify ( stream ) ) ;
215
214
}
216
- var command = parse_response ( code , stream ) ;
215
+ command = parse_response ( code , stream ) ;
217
216
if ( command . type ) {
218
217
if ( exports . DEBUG > 0 ) {
219
218
sys . debug ( "Received " + command . type + ": " + JSON . stringify ( command . args ) ) ;
@@ -265,10 +264,12 @@ exports.Connection = function (database, username, password, port) {
265
264
results = [ ] ;
266
265
} ) ;
267
266
events . addListener ( "DataRow" , function ( data ) {
268
- var row = { } ;
269
- for ( var i = 0 , l = data . length ; i < l ; i += 1 ) {
270
- var description = row_description [ i ] ;
271
- var value = data [ i ] ;
267
+ var row , i , l , description , value ;
268
+ row = { } ;
269
+ l = data . length ;
270
+ for ( i = 0 ; i < l ; i += 1 ) {
271
+ description = row_description [ i ] ;
272
+ value = data [ i ] ;
272
273
if ( value !== null ) {
273
274
// TODO: investigate to see if these numbers are stable across databases or
274
275
// if we need to dynamically pull them from the pg_types table
0 commit comments