@@ -98,16 +98,16 @@ type Schema struct {
98
98
drop string
99
99
}
100
100
101
- func (s Schema ) Postgres () (string , string ) {
102
- return s .create , s .drop
101
+ func (s Schema ) Postgres () (string , string , string ) {
102
+ return s .create , s .drop , `now()`
103
103
}
104
104
105
- func (s Schema ) MySQL () (string , string ) {
106
- return strings .Replace (s .create , `"` , "`" , - 1 ), s .drop
105
+ func (s Schema ) MySQL () (string , string , string ) {
106
+ return strings .Replace (s .create , `"` , "`" , - 1 ), s .drop , `now()`
107
107
}
108
108
109
- func (s Schema ) Sqlite3 () (string , string ) {
110
- return strings .Replace (s .create , `now()` , `CURRENT_TIMESTAMP` , - 1 ), s .drop
109
+ func (s Schema ) Sqlite3 () (string , string , string ) {
110
+ return strings .Replace (s .create , `now()` , `CURRENT_TIMESTAMP` , - 1 ), s .drop , `CURRENT_TIMESTAMP`
111
111
}
112
112
113
113
var defaultSchema = Schema {
@@ -218,27 +218,27 @@ func MultiExec(e Execer, query string) {
218
218
}
219
219
}
220
220
221
- func RunWithSchema (schema Schema , t * testing.T , test func (db * DB , t * testing.T )) {
222
- runner := func (db * DB , t * testing.T , create , drop string ) {
221
+ func RunWithSchema (schema Schema , t * testing.T , test func (db * DB , t * testing.T , now string )) {
222
+ runner := func (db * DB , t * testing.T , create , drop , now string ) {
223
223
defer func () {
224
224
MultiExec (db , drop )
225
225
}()
226
226
227
227
MultiExec (db , create )
228
- test (db , t )
228
+ test (db , t , now )
229
229
}
230
230
231
231
if TestPostgres {
232
- create , drop := schema .Postgres ()
233
- runner (pgdb , t , create , drop )
232
+ create , drop , now := schema .Postgres ()
233
+ runner (pgdb , t , create , drop , now )
234
234
}
235
235
if TestSqlite {
236
- create , drop := schema .Sqlite3 ()
237
- runner (sldb , t , create , drop )
236
+ create , drop , now := schema .Sqlite3 ()
237
+ runner (sldb , t , create , drop , now )
238
238
}
239
239
if TestMysql {
240
- create , drop := schema .MySQL ()
241
- runner (mysqldb , t , create , drop )
240
+ create , drop , now := schema .MySQL ()
241
+ runner (mysqldb , t , create , drop , now )
242
242
}
243
243
}
244
244
@@ -263,7 +263,7 @@ func loadDefaultFixture(db *DB, t *testing.T) {
263
263
// Test a new backwards compatible feature, that missing scan destinations
264
264
// will silently scan into sql.RawText rather than failing/panicing
265
265
func TestMissingNames (t * testing.T ) {
266
- RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T ) {
266
+ RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T , now string ) {
267
267
loadDefaultFixture (db , t )
268
268
type PersonPlus struct {
269
269
FirstName string `db:"first_name"`
@@ -383,7 +383,7 @@ func TestEmbeddedStructs(t *testing.T) {
383
383
type Loop2 struct { Loop1 }
384
384
type Loop3 struct { Loop2 }
385
385
386
- RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T ) {
386
+ RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T , now string ) {
387
387
loadDefaultFixture (db , t )
388
388
peopleAndPlaces := []PersonPlace {}
389
389
err := db .Select (
@@ -476,7 +476,7 @@ func TestJoinQuery(t *testing.T) {
476
476
}
477
477
type Boss Employee
478
478
479
- RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T ) {
479
+ RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T , now string ) {
480
480
loadDefaultFixture (db , t )
481
481
482
482
var employees []struct {
@@ -512,7 +512,7 @@ func TestJoinQueryNamedPointerStructs(t *testing.T) {
512
512
}
513
513
type Boss Employee
514
514
515
- RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T ) {
515
+ RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T , now string ) {
516
516
loadDefaultFixture (db , t )
517
517
518
518
var employees []struct {
@@ -544,7 +544,7 @@ func TestJoinQueryNamedPointerStructs(t *testing.T) {
544
544
}
545
545
546
546
func TestSelectSliceMapTime (t * testing.T ) {
547
- RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T ) {
547
+ RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T , now string ) {
548
548
loadDefaultFixture (db , t )
549
549
rows , err := db .Queryx ("SELECT * FROM person" )
550
550
if err != nil {
@@ -573,7 +573,7 @@ func TestSelectSliceMapTime(t *testing.T) {
573
573
}
574
574
575
575
func TestNilReceiver (t * testing.T ) {
576
- RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T ) {
576
+ RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T , now string ) {
577
577
loadDefaultFixture (db , t )
578
578
var p * Person
579
579
err := db .Get (p , "SELECT * FROM person LIMIT 1" )
@@ -619,7 +619,7 @@ func TestNamedQuery(t *testing.T) {
619
619
` ,
620
620
}
621
621
622
- RunWithSchema (schema , t , func (db * DB , t * testing.T ) {
622
+ RunWithSchema (schema , t , func (db * DB , t * testing.T , now string ) {
623
623
type Person struct {
624
624
FirstName sql.NullString `db:"first_name"`
625
625
LastName sql.NullString `db:"last_name"`
@@ -829,7 +829,7 @@ func TestNilInserts(t *testing.T) {
829
829
drop : "drop table tt;" ,
830
830
}
831
831
832
- RunWithSchema (schema , t , func (db * DB , t * testing.T ) {
832
+ RunWithSchema (schema , t , func (db * DB , t * testing.T , now string ) {
833
833
type TT struct {
834
834
ID int
835
835
Value * string
@@ -874,7 +874,7 @@ func TestScanError(t *testing.T) {
874
874
drop : `drop table kv;` ,
875
875
}
876
876
877
- RunWithSchema (schema , t , func (db * DB , t * testing.T ) {
877
+ RunWithSchema (schema , t , func (db * DB , t * testing.T , now string ) {
878
878
type WrongTypes struct {
879
879
K int
880
880
V string
@@ -902,7 +902,7 @@ func TestScanError(t *testing.T) {
902
902
// loading and reloading the schema..
903
903
904
904
func TestUsage (t * testing.T ) {
905
- RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T ) {
905
+ RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T , now string ) {
906
906
loadDefaultFixture (db , t )
907
907
slicemembers := []SliceMember {}
908
908
err := db .Select (& slicemembers , "SELECT * FROM place ORDER BY telcode ASC" )
@@ -1421,7 +1421,7 @@ func TestEmbeddedMaps(t *testing.T) {
1421
1421
drop : `drop table message;` ,
1422
1422
}
1423
1423
1424
- RunWithSchema (schema , t , func (db * DB , t * testing.T ) {
1424
+ RunWithSchema (schema , t , func (db * DB , t * testing.T , now string ) {
1425
1425
messages := []Message {
1426
1426
{"Hello, World" , PropertyMap {"one" : "1" , "two" : "2" }},
1427
1427
{"Thanks, Joy" , PropertyMap {"pull" : "request" }},
@@ -1465,7 +1465,7 @@ func TestIssue197(t *testing.T) {
1465
1465
type Var struct { Raw json.RawMessage }
1466
1466
type Var2 struct { Raw []byte }
1467
1467
type Var3 struct { Raw mybyte }
1468
- RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T ) {
1468
+ RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T , now string ) {
1469
1469
var err error
1470
1470
var v , q Var
1471
1471
if err = db .Get (& v , `SELECT '{"a": "b"}' AS raw` ); err != nil {
@@ -1565,7 +1565,7 @@ func TestIn(t *testing.T) {
1565
1565
t .Error ("Expected an error, but got nil." )
1566
1566
}
1567
1567
}
1568
- RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T ) {
1568
+ RunWithSchema (defaultSchema , t , func (db * DB , t * testing.T , now string ) {
1569
1569
loadDefaultFixture (db , t )
1570
1570
//tx.MustExec(tx.Rebind("INSERT INTO place (country, city, telcode) VALUES (?, ?, ?)"), "United States", "New York", "1")
1571
1571
//tx.MustExec(tx.Rebind("INSERT INTO place (country, telcode) VALUES (?, ?)"), "Hong Kong", "852")
@@ -1689,7 +1689,7 @@ func TestEmbeddedLiterals(t *testing.T) {
1689
1689
drop : `drop table x;` ,
1690
1690
}
1691
1691
1692
- RunWithSchema (schema , t , func (db * DB , t * testing.T ) {
1692
+ RunWithSchema (schema , t , func (db * DB , t * testing.T , now string ) {
1693
1693
type t1 struct {
1694
1694
K * string
1695
1695
}
0 commit comments