@@ -20,76 +20,76 @@ test("simple, unnamed prepared statement", function(){
2020test ( "named prepared statement" , function ( ) {
2121
2222 var client = helper . client ( ) ;
23- var queryName = "user by age and like name" ;
24- var query = client . query ( {
25- text : 'select name from person where age <= $1 and name LIKE $2' ,
26- values : [ 20 , 'Bri%' ] ,
27- name : queryName
28- } ) ;
23+ client . on ( 'drain' , client . end . bind ( client ) ) ;
2924
25+ var queryName = "user by age and like name" ;
3026 var parseCount = 0 ;
31- client . connection . on ( 'parseComplete' , function ( ) {
32- parseCount ++ ;
33- } ) ;
34-
35- assert . raises ( query , 'row' , function ( row ) {
36- assert . equal ( row . fields [ 0 ] , 'Brian' ) ;
37- } ) ;
3827
39- assert . raises ( query , 'end' , function ( ) {
40- test ( "query was parsed" , function ( ) {
41- assert . equal ( parseCount , 1 ) ;
28+ test ( "first named prepared statement" , function ( ) {
29+ var query = client . query ( {
30+ text : 'select name from person where age <= $1 and name LIKE $2' ,
31+ values : [ 20 , 'Bri%' ] ,
32+ name : queryName
4233 } ) ;
4334
44- test ( "with same name & text" , function ( ) {
45- var cachedQuery = client . query ( {
46- text : 'select name from person where age <= $1 and name LIKE $2' ,
47- name : queryName ,
48- values : [ 10 , 'A%' ]
35+ test ( "is parsed" , function ( ) {
36+ client . connection . on ( 'parseComplete' , function ( ) {
37+ parseCount ++ ;
4938 } ) ;
39+ } ) ;
5040
51- assert . raises ( cachedQuery , 'row' , function ( row ) {
52- assert . equal ( row . fields [ 0 ] , 'Aaron ' ) ;
53- } ) ;
41+ assert . raises ( query , 'row' , function ( row ) {
42+ assert . equal ( row . fields [ 0 ] , 'Brian ' ) ;
43+ } ) ;
5444
55- assert . raises ( cachedQuery , 'end' , function ( ) {
56- test ( "query was only parsed one time" , function ( ) {
57- assert . equal ( parseCount , 1 , "Should not have reparsed query" ) ;
58- } ) ;
45+ assert . raises ( query , 'end' , function ( ) {
46+ test ( "query was parsed" , function ( ) {
47+ assert . equal ( parseCount , 1 ) ;
5948 } ) ;
6049 } ) ;
50+ } ) ;
6151
62- test ( "with same name, but the query text not even there batman!" , function ( ) {
63- var q = client . query ( {
64- name : queryName ,
65- values : [ 30 , '%n%' ]
66- } ) ;
52+ test ( "second named prepared statement with same name & text" , function ( ) {
53+ var cachedQuery = client . query ( {
54+ text : 'select name from person where age <= $1 and name LIKE $2' ,
55+ name : queryName ,
56+ values : [ 10 , 'A%' ]
57+ } ) ;
58+
59+ assert . raises ( cachedQuery , 'row' , function ( row ) {
60+ assert . equal ( row . fields [ 0 ] , 'Aaron' ) ;
61+ } ) ;
6762
68- test ( "gets first row" , function ( ) {
63+ assert . raises ( cachedQuery , 'end' , function ( ) {
64+ test ( "query was only parsed one time" , function ( ) {
65+ assert . equal ( parseCount , 1 , "Should not have reparsed query" ) ;
66+ } ) ;
67+ } ) ;
68+ } ) ;
6969
70- assert . raises ( q , 'row' , function ( row ) {
71- assert . equal ( row . fields [ 0 ] , "Aaron" ) ;
70+ test ( "with same name, but the query text not even there batman!" , function ( ) {
71+ var q = client . query ( {
72+ name : queryName ,
73+ values : [ 30 , '%n%' ]
74+ } ) ;
7275
73- test ( "gets second row" , function ( ) {
76+ test ( "gets first row" , function ( ) {
77+ assert . raises ( q , 'row' , function ( row ) {
78+ assert . equal ( row . fields [ 0 ] , "Aaron" ) ;
7479
75- assert . raises ( q , ' row' , function ( row ) {
76- assert . equal ( row . fields [ 0 ] , "Brian" ) ;
77- } ) ;
80+ test ( "gets second row" , function ( ) {
81+ assert . raises ( q , ' row' , function ( row ) {
82+ assert . equal ( row . fields [ 0 ] , "Brian" ) ;
7883 } ) ;
79-
8084 } ) ;
81- } ) ;
8285
83- test ( "only parsed query once total" , function ( ) {
84- assert . equal ( parseCount , 1 ) ;
85- q . on ( 'end' , function ( ) {
86- client . end ( ) ;
87- } ) ;
8886 } ) ;
87+ } ) ;
8988
89+ assert . raises ( q , 'end' , function ( ) {
90+ assert . equal ( parseCount , 1 ) ;
9091 } ) ;
9192 } ) ;
92-
9393} ) ;
9494
9595test ( "prepared statements on different clients" , function ( ) {
0 commit comments