@@ -289,8 +289,9 @@ function parse_response(code, buffer) {
289
289
290
290
function message ( ) {
291
291
var self = this ;
292
- this . messages = [ ] ;
293
- var pos = 0 ; // instance variable
292
+ this . messages = [ ] ; // public instance array.
293
+ var pos = 0 ;
294
+ this . _position = 0 ; // instance variable
294
295
this . setMessages = function ( msg ) {
295
296
if ( msg instanceof Array ) {
296
297
self . messages = msg ;
@@ -305,35 +306,35 @@ function message () {
305
306
}
306
307
this . next = function ( ) {
307
308
if ( exports . DEBUG > 3 ) {
308
- sys . debug ( "message pos: " + pos ) ;
309
- sys . debug ( "messages:" + sys . inspect ( self . messages ) ) ;
309
+ sys . debug ( "message pos: " + this . _position ) ;
310
+ sys . debug ( "messages:" + sys . inspect ( this . messages ) ) ;
310
311
}
311
- if ( self . messages [ pos ] !== null && self . messages [ pos ] !== undefined ) {
312
- pos = pos + 1 ;
312
+ if ( this . messages [ this . _position ] !== null && this . messages [ this . _position ] !== undefined ) {
313
+ this . _position = this . _position + 1 ;
313
314
if ( exports . DEBUG > 3 ) {
314
- sys . debug ( "Returning: " + self . messages [ pos - 1 ] ) ;
315
+ sys . debug ( "Returning: " + this . messages [ this . _position - 1 ] ) ;
315
316
}
316
- return self . messages [ pos - 1 ] ;
317
+ return this . messages [ this . _position - 1 ] ;
317
318
}
318
319
if ( exports . DEBUG > 3 ) {
319
- sys . debug ( "pos " + pos + " exceeds internal message buffer." ) ;
320
+ sys . debug ( "pos " + this . _position + " exceeds internal message buffer." ) ;
320
321
sys . debug ( "Returning null" ) ;
321
322
}
322
323
return null ;
323
324
}
324
325
this . empty = function ( ) {
325
326
if ( exports . DEBUG > 3 ) {
326
- sys . debug ( "message pos " + pos + " exceeds length " + self . messages . length + ": " + ( pos >= self . messages . length ) ) ;
327
+ sys . debug ( "message pos " + this . _position + " exceeds length " + this . messages . length + ": " + ( this . _position >= this . messages . length ) ) ;
327
328
}
328
- if ( pos >= self . messages . length ) {
329
+ if ( this . _position >= this . messages . length ) {
329
330
return true ;
330
331
}
331
332
return false ;
332
333
}
333
334
}
334
335
335
336
message . prototype = new process . EventEmitter ;
336
-
337
+ // message.prototype.constructor = message;
337
338
338
339
function Query ( sql , callback ) {
339
340
message . call ( this ) ;
@@ -376,7 +377,7 @@ function Query(sql, callback) {
376
377
} ) ;
377
378
}
378
379
379
- Query . prototype = new message ( ) ;
380
+ Query . prototype = new message ;
380
381
Query . prototype . constructor = Query ;
381
382
382
383
function Prepared ( sql , conn /*, use_named */ ) {
@@ -386,10 +387,11 @@ function Prepared(sql, conn /*, use_named */) {
386
387
// var prepared_name = md5(sql); // Use the md5 hash. This is easily selectable later.
387
388
388
389
var self = this ;
389
- // message.call(this);
390
+ message . call ( this ) ;
390
391
self . row_description = null ;
391
392
self . parameters = null ;
392
393
self . noData = false ;
394
+ self . sql = sql ;
393
395
394
396
var parseComplete = null ;
395
397
var readyToExec = false ;
@@ -402,7 +404,7 @@ function Prepared(sql, conn /*, use_named */) {
402
404
type : "Parse" ,
403
405
// Prepared name, the query,
404
406
// and a zero-length array to declare no types.
405
- args : [ '' , sql , [ ] ] ,
407
+ args : [ '' , self . sql , [ ] ] ,
406
408
} ,
407
409
{
408
410
type : "Describe" ,
@@ -483,11 +485,7 @@ function Prepared(sql, conn /*, use_named */) {
483
485
484
486
self . next = function ( ) {
485
487
// Override.
486
- var msg = this . __proto__ . next ( ) ;
487
- // if ( exports.DEBUG > 0) {
488
- // sys.debug("Message is: " + msg);
489
- // sys.debug("proto is: " + self.__proto__);
490
- // }
488
+ var msg = this . __proto__ . next . call ( this ) ;
491
489
if ( exports . DEBUG > 3 ) {
492
490
sys . debug ( "currexec " + currExec ) ;
493
491
sys . debug ( "msg" + msg ) ;
@@ -508,24 +506,14 @@ function Prepared(sql, conn /*, use_named */) {
508
506
}
509
507
currExec . args . forEach ( function ( i ) {
510
508
if ( exports . DEBUG > 2 ) {
511
- sys . debug ( "Arg is : " + i . type ) ;
509
+ sys . debug ( "Adding Arg : " + i . type ) ;
512
510
}
513
- self . addMessage ( i ) ;
511
+ self . addMessage . call ( self , i ) ;
514
512
} ) ;
515
- // for (arg in currExec.args.slice(1)) {
516
- //
517
- // if (currExec.args.hasOwnProperty(arg)) {
518
- //
519
- // }
520
- // }
521
- // self.addMessage({
522
- // type: "Flush",
523
- // args: [],
524
- // }); // Flush the current query out.
525
513
if ( exports . DEBUG > 2 ) {
526
514
sys . debug ( "Calling next from prototype." ) ;
527
515
}
528
- return self . __proto__ . next ( ) ;
516
+ return self . __proto__ . next . call ( this ) ;
529
517
}
530
518
}
531
519
if ( exports . DEBUG > 0 ) {
@@ -1042,8 +1030,9 @@ function Connection(args) {
1042
1030
// do the implicit sync/commit here?
1043
1031
callback . apply ( callback , arguments ) ;
1044
1032
}
1045
- if ( exports . DEBUG > 0 ) {
1033
+ if ( exports . DEBUG > 3 ) {
1046
1034
sys . debug ( "Transaction is: " + tx ) ;
1035
+ sys . debug ( "Query is: " + query ) ;
1047
1036
}
1048
1037
tx . prepare . call ( tx , query , cb ) ;
1049
1038
events . emit ( "queryAdded" ) ;
@@ -1118,16 +1107,19 @@ function Connection(args) {
1118
1107
Ergo, we set up a DB listener with the same name, and fire our emitter
1119
1108
when it's triggered.
1120
1109
1121
- Easy.
1110
+ Easy, and very nifty .
1122
1111
*/
1123
1112
conn . addListener ( 'newListener' , function ( e , listener ) {
1124
1113
if ( e === 'String' ) {
1125
1114
// It's a string.
1126
- if ( ! ( e in [ 'newListener' ] ) )
1127
- conn . notify ( e , listener ) ;
1115
+ if ( ! ( e in [ 'newListener' ] ) ) {
1116
+ conn . notify ( e , listener ) ;
1117
+ }
1128
1118
}
1129
-
1130
1119
} ) ;
1120
+ conn . notify = function ( name ) {
1121
+
1122
+ }
1131
1123
}
1132
1124
Connection . prototype = new process . EventEmitter ( ) ;
1133
1125
@@ -1220,12 +1212,15 @@ function Transaction (connection /*, params */) {
1220
1212
// Sets up a prepared query, and drops it onto the queue.
1221
1213
if ( sql . match ( / \? / ) ) {
1222
1214
var i = 1 ;
1223
- sql = sql . replace ( / \? / g, function ( ) { return "$" + i ++ ; } ) ;
1215
+ var fsql = sql . replace ( / \? / g, function ( ) { return "$" + i ++ ; } ) ;
1224
1216
}
1225
- var p = new Prepared ( sql , thisp ) ;
1217
+ var p = new Prepared ( fsql , thisp ) ;
1226
1218
thisp . push ( p ) ;
1227
1219
events . emit ( "queryAdded" ) ;
1228
1220
wrap ( callback ) ( p , thisp ) ;
1221
+ if ( exports . DEBUG == 4 ) {
1222
+ sys . debug ( "Prepared messages: " + sys . inspect ( messages ) ) ;
1223
+ }
1229
1224
// conn.emit.call(conn, "queryAdded");
1230
1225
}
1231
1226
@@ -1244,7 +1239,7 @@ function Transaction (connection /*, params */) {
1244
1239
1245
1240
this . begin = function ( ) {
1246
1241
// Begins the transaction. We now lock the transaction to the wire.
1247
- thisp . append ( thisp . query ( "BEGIN;" ) ) ; // Don't need to watch for callbacks.
1242
+ thisp . push ( thisp . query ( "BEGIN;" ) ) ; // Don't need to watch for callbacks.
1248
1243
}
1249
1244
this . rollback = function ( ) {
1250
1245
// Rolls back the request, and does the connection release.
@@ -1278,6 +1273,9 @@ function Transaction (connection /*, params */) {
1278
1273
this . next = function ( ) {
1279
1274
if ( messages . length > 0 ) {
1280
1275
if ( messages [ 0 ] !== null && messages [ 0 ] !== undefined ) {
1276
+ if ( exports . DEBUG == 4 ) {
1277
+ sys . debug ( "TX Returning: " + sys . inspect ( messages [ 0 ] ) ) ;
1278
+ }
1281
1279
return messages . shift ( ) ; // Front of the array, there.
1282
1280
}
1283
1281
}
@@ -1295,59 +1293,4 @@ function connectionManager (dsn /*, connections=1 */) {
1295
1293
// var conn = new Connection(dsn);
1296
1294
}
1297
1295
1298
- exports . connect = Connection ;
1299
-
1300
-
1301
-
1302
- /* Allows a currently-executing query to selectively modify the current
1303
- query queue, IF it is currently executing.
1304
-
1305
- Otherwise, it splices the query object in after its position in the queue.
1306
- */
1307
- // conn.yield_to = function (first, query) {
1308
- // if (exports.DEBUG > 0) {
1309
- // sys.debug("got yield_to");
1310
- // }
1311
- // if (first === current_query) {
1312
- // query_queue.unshift(query);
1313
- // events.emit("queryAdded"); // Don't immediately switch to the next message.
1314
- // }
1315
- // else if (first in query_queue) {
1316
- // // Splice it in after the query
1317
- // query_queue.splice( query_queue.indexOf(first), 0, query );
1318
- // events.emit("queryAdded");
1319
- // }
1320
- // }
1321
- // // Transactions shouldn't release themselves, I don't think.
1322
- // //
1323
- // conn.release = function (query) {
1324
- // if (exports.DEBUG > 0) {
1325
- // sys.debug("got release");
1326
- // }
1327
- // if (query === current_query) {
1328
- // readyState = true;
1329
- // events.emit("ReadyForQuery"); // Cycle along.
1330
- // }
1331
- // }
1332
-
1333
-
1334
- // var parameters, callback;
1335
- //
1336
- // // Grab the variable length parameters and the row_callback is there is one.
1337
- // parameters = Array.prototype.slice.call(arguments, 1);
1338
- //
1339
- // if (typeof parameters[parameters.length - 1] === 'function') {
1340
- // callback = parameters.pop();
1341
- // }
1342
- // var q;
1343
- // if (parameters.length == 1 && parameters[0] instanceof Array) {
1344
- // // We have a parameterized query
1345
- // q = new Prepared(query, function (sth) {
1346
- // sth.execute(parameters[0], callback);
1347
- // });
1348
- // }
1349
- // else {
1350
- // q = new Query(query, callback);
1351
- //
1352
- // }
1353
- // query_queue.push(q);
1296
+ exports . connect = Connection ;
0 commit comments