@@ -10,7 +10,13 @@ before(function (done) {
1010 var openCount = 0 ;
1111 db . on ( 'open' , opened ) ;
1212 db2 . on ( 'open' , opened ) ;
13- function opened ( ) { ++ openCount === 2 && done ( ) ; }
13+ function opened ( ) {
14+ if ( ++ openCount === 2 ) {
15+ db . prepare ( 'CREATE TABLE entries (a INTEGER, b REAL, c TEXT)' ) . run ( ) ;
16+ db2 . prepare ( 'CREATE TABLE entries (a INTEGER, b REAL, c TEXT)' ) . run ( ) ;
17+ done ( ) ;
18+ }
19+ }
1420} ) ;
1521
1622describe ( 'Int64' , function ( ) {
@@ -75,10 +81,88 @@ describe('Int64', function () {
7581 expect ( int . equals ( + String ( int ) ) ) . to . be . false ;
7682 expect ( int . equals ( + int ) ) . to . be . false ;
7783 } ) ;
78- it ( 'should bind to statements and transactions' ) ;
79- it ( 'should get returned by operations after setting .safeIntegers()' ) ;
80- it ( 'should react to changing settings inside an .each() callback' ) ;
81- it ( 'should be safe from other databases inside an .each() callback' ) ;
82- it ( 'should be able to change the default setting on the database' ) ;
83- it ( 'should return fully accurate round-trip results' ) ;
84+ it ( 'should bind to statements and transactions' , function ( ) {
85+ var int = new Int64 ( 4243423 , 234234234 ) ;
86+ db . prepare ( 'INSERT INTO entries VALUES (?, ?, ?)' ) . run ( int , int , int ) ;
87+ db . transaction ( [ 'INSERT INTO entries VALUES (?, ?, ?)' ] ) . run ( int , int , int ) ;
88+ db . prepare ( 'INSERT INTO entries VALUES (?, ?, ?)' ) . bind ( int , int , int ) . run ( ) ;
89+ db . transaction ( [ 'INSERT INTO entries VALUES (?, ?, ?)' ] ) . bind ( int , int , int ) . run ( ) ;
90+
91+ db2 . prepare ( 'INSERT INTO entries VALUES (?, ?, ?)' ) . run ( int , int , int ) ;
92+ db2 . transaction ( [ 'INSERT INTO entries VALUES (?, ?, ?)' ] ) . run ( int , int , int ) ;
93+ db2 . prepare ( 'INSERT INTO entries VALUES (?, ?, ?)' ) . bind ( int , int , int ) . run ( ) ;
94+ db2 . transaction ( [ 'INSERT INTO entries VALUES (?, ?, ?)' ] ) . bind ( int , int , int ) . run ( ) ;
95+ } ) ;
96+ it ( 'should get returned by operations after setting .safeIntegers()' , function ( ) {
97+ var int = new Int64 ( 4243423 , 234234234 ) ;
98+ var stmt = db . prepare ( 'SELECT a FROM entries' ) . pluck ( ) ;
99+ expect ( stmt . get ( ) ) . to . equal ( 1006028374637854700 ) ;
100+ expect ( stmt . safeIntegers ( ) . get ( ) ) . to . deep . equal ( int ) ;
101+ expect ( stmt . get ( ) ) . to . deep . equal ( int ) ;
102+ expect ( stmt . safeIntegers ( false ) . get ( ) ) . to . equal ( 1006028374637854700 ) ;
103+ expect ( stmt . get ( ) ) . to . equal ( 1006028374637854700 ) ;
104+ expect ( stmt . safeIntegers ( true ) . get ( ) ) . to . deep . equal ( int ) ;
105+ expect ( stmt . get ( ) ) . to . deep . equal ( int ) ;
106+
107+ stmt = db . prepare ( 'SELECT b FROM entries' ) . pluck ( ) ;
108+ expect ( stmt . get ( ) ) . to . equal ( 1006028374637854700 ) ;
109+ expect ( stmt . safeIntegers ( ) . get ( ) ) . to . equal ( 1006028374637854700 ) ;
110+
111+ stmt = db . prepare ( 'SELECT c FROM entries' ) . pluck ( ) ;
112+ expect ( stmt . get ( ) ) . to . equal ( '1006028374637854687' ) ;
113+ expect ( stmt . safeIntegers ( ) . get ( ) ) . to . equal ( '1006028374637854687' ) ;
114+ } ) ;
115+ it ( 'should react to changing settings inside an .each() callback' , function ( ) {
116+ var int = new Int64 ( 4243423 , 234234234 ) ;
117+ var stmt = db . prepare ( 'SELECT * FROM entries' ) ;
118+ var count = 0 ;
119+ stmt . each ( function ( row ) {
120+ expect ( row . b ) . to . equal ( 1006028374637854700 ) ;
121+ expect ( row . c ) . to . equal ( '1006028374637854687' ) ;
122+ if ( ++ count % 2 ) {
123+ expect ( row . a ) . to . equal ( 1006028374637854700 ) ;
124+ } else {
125+ expect ( row . a ) . to . deep . equal ( int ) ;
126+ }
127+ stmt . safeIntegers ( count % 2 ? true : false ) ;
128+ } ) ;
129+ expect ( count ) . to . equal ( 4 ) ;
130+ } ) ;
131+ it ( 'should be safe from other databases inside an .each() callback' , function ( ) {
132+ var int = new Int64 ( 4243423 , 234234234 ) ;
133+ var stmt = db . prepare ( 'SELECT a FROM entries' ) . safeIntegers ( ) ;
134+ var stmt2 = db2 . prepare ( 'SELECT a FROM entries' ) ;
135+ var count = 0 ;
136+ stmt . each ( function ( row ) {
137+ ++ count ;
138+ expect ( row . a ) . to . deep . equal ( int ) ;
139+
140+ var subcount = 0 ;
141+ stmt2 . safeIntegers ( false ) . each ( function ( row ) {
142+ ++ subcount ;
143+ expect ( row . a ) . to . equal ( 1006028374637854700 ) ;
144+ } ) ;
145+ expect ( subcount ) . to . equal ( 4 ) ;
146+
147+ } ) ;
148+ expect ( count ) . to . equal ( 4 ) ;
149+ } ) ;
150+ it ( 'should be able to change the default setting on the database' , function ( ) {
151+ db . defaultSafeIntegers ( true ) ;
152+ var int = new Int64 ( 4243423 , 234234234 ) ;
153+
154+ var stmt = db . prepare ( 'SELECT a FROM entries' ) . pluck ( ) ;
155+ expect ( stmt . get ( ) ) . to . deep . equal ( int ) ;
156+ expect ( stmt . safeIntegers ( false ) . get ( ) ) . to . equal ( 1006028374637854700 ) ;
157+
158+ db . defaultSafeIntegers ( false ) ;
159+
160+ var stmt2 = db . prepare ( 'SELECT a FROM entries' ) . pluck ( ) ;
161+ expect ( stmt2 . get ( ) ) . to . equal ( 1006028374637854700 ) ;
162+ expect ( stmt2 . safeIntegers ( ) . get ( ) ) . to . deep . equal ( int ) ;
163+
164+ db . defaultSafeIntegers ( true ) ;
165+ expect ( stmt . get ( ) ) . to . equal ( 1006028374637854700 ) ;
166+ expect ( stmt2 . get ( ) ) . to . deep . equal ( int ) ;
167+ } ) ;
84168} ) ;
0 commit comments