var sqlite3 = require('..');
var assert = require('assert');

describe('data types', function() {
    var db;
    before(function(done) {
        db = new sqlite3.Database(':memory:');
        db.run("CREATE TABLE txt_table (txt TEXT)");
        db.run("CREATE TABLE int_table (int INTEGER)");
        db.run("CREATE TABLE flt_table (flt FLOAT)");
        db.wait(done);
    });

    beforeEach(function(done) {
        db.exec('DELETE FROM txt_table; DELETE FROM int_table; DELETE FROM flt_table;', done);
    });

    it('should serialize Date()', function(done) {
        var date = new Date();
        db.run("INSERT INTO int_table VALUES(?)", date);
        db.get("SELECT int FROM int_table", function(err, row) {
            if (err) throw err;
            assert.equal(row.int, +date);
            done();
        });
    });

    it('should serialize RegExp()', function(done) {
        var regexp = /^f\noo/;
        db.run("INSERT INTO txt_table VALUES(?)", regexp);
        db.get("SELECT txt FROM txt_table", function(err, row) {
            if (err) throw err;
            assert.equal(row.txt, String(regexp));
            done();
        });
    });

    [
        4294967296.249,
        Math.PI,
        3924729304762836.5,
        new Date().valueOf(),
        912667.394828365,
        2.3948728634826374e+83,
        9.293476892934982e+300,
        Infinity,
        -9.293476892934982e+300,
        -2.3948728634826374e+83,
        -Infinity
    ].forEach(function(flt) {
        it('should serialize float ' + flt, function(done) {
            db.run("INSERT INTO flt_table VALUES(?)", flt);
            db.get("SELECT flt FROM flt_table", function(err, row) {
                if (err) throw err;
                assert.equal(row.flt, flt);
                done();
            });
        });
    });

    [
        4294967299,
        3924729304762836,
        new Date().valueOf(),
        2.3948728634826374e+83,
        9.293476892934982e+300,
        Infinity,
        -9.293476892934982e+300,
        -2.3948728634826374e+83,
        -Infinity
    ].forEach(function(integer) {
        it('should serialize integer ' + integer, function(done) {
            db.run("INSERT INTO int_table VALUES(?)", integer);
            db.get("SELECT int AS integer FROM int_table", function(err, row) {
                if (err) throw err;
                assert.equal(row.integer, integer);
                done();
            });
        });
    });
});

@@ -641,27 +641,79 @@
 ES(?)%22, date
-);%0A
+, function (err) %7B%0A            if (err) throw err;%0A    
         db.g
@@ -769,32 +769,36 @@
 ) %7B%0A            
+    
 if (err) throw e
@@ -793,32 +793,36 @@
 err) throw err;%0A
+    
             asse
@@ -855,32 +855,36 @@
             
+    
 done();%0A
         %7D);%0A
@@ -863,32 +863,48 @@
         done();%0A
+            %7D);%0A
         %7D);%0A    
@@ -1048,19 +1048,71 @@
 , regexp
-);%0A
+, function (err) %7B%0A            if (err) throw err;%0A    
         
@@ -1172,32 +1172,36 @@
 ) %7B%0A            
+    
 if (err) throw e
@@ -1196,32 +1196,36 @@
 err) throw err;%0A
+    
             asse
@@ -1267,32 +1267,36 @@
             
+    
 done();%0A
         %7D);%0A
@@ -1275,32 +1275,48 @@
         done();%0A
+            %7D);%0A
         %7D);%0A    
@@ -1761,27 +1761,82 @@
 UES(?)%22, flt
-);%0A
+, function (err) %7B%0A                if (err) throw err;%0A   
             
@@ -1827,32 +1827,33 @@
 %0A               
+ 
 db.get(%22SELECT f
@@ -1901,32 +1901,36 @@
                 
+    
 if (err) throw e
@@ -1941,32 +1941,36 @@
                 
+ 
+   
 assert.equal(row
@@ -1993,32 +1993,36 @@
             
+  
+  
 done();%0A
             
@@ -2001,32 +2001,52 @@
         done();%0A
+                %7D);%0A
             %7D);%0A
@@ -2468,35 +2468,91 @@
 UES(?)%22, integer
-);%0A
+, function (err) %7B%0A                if (err) throw err;%0A    
             db.g
@@ -2623,32 +2623,36 @@
                 
+    
 if (err) throw e
@@ -2647,32 +2647,36 @@
 err) throw err;%0A
+    
                 
@@ -2723,32 +2723,36 @@
             
+  
+  
 done();%0A
             
@@ -2731,32 +2731,52 @@
         done();%0A
+                %7D);%0A
             %7D);%0A

Make sure the INSERT completes before trying the SELECT