forked from alexbrainman/odbc
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathifx_test.go
More file actions
59 lines (51 loc) · 1.81 KB
/
ifx_test.go
File metadata and controls
59 lines (51 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package odbc
import (
"database/sql"
"flag"
"fmt"
"testing"
"time"
)
var (
ifxsrv = flag.String("ifxsrv", "server", "ifx server name")
ifxdb = flag.String("ifxdb", "dbname", "ifx database name")
ifxuser = flag.String("ifxuser", "", "ifx user name")
ifxpass = flag.String("ifxpass", "", "ifx password")
)
func ifxConnect() (db *sql.DB, stmtCount int, err error) {
conn := fmt.Sprintf("driver=IBM INFORMIX ODBC DRIVER;server=%s;database=%s;user=%s;password=%s",
*ifxsrv, *ifxdb, *ifxuser, *ifxpass)
db, err = sql.Open("odbc", conn)
if err != nil {
return nil, 0, err
}
stats := db.Driver().(*Driver).Stats
return db, stats.StmtCount, nil
}
func TestIFXTime(t *testing.T) {
db, sc, err := ifxConnect()
if err != nil {
t.Fatal(err)
}
defer closeDB(t, db, sc, sc)
db.Exec("drop table temp")
exec(t, db, "create table temp(id serial primary key, time datetime year to second)")
now := time.Now()
// SQL_TIME_STRUCT only supports hours, minutes and seconds
now = time.Date(1, time.January, 1, now.Hour(), now.Minute(), now.Second(), 0, time.Local)
_, err = db.Exec("insert into temp (time) values(?)", now)
if err != nil {
t.Fatal(err)
}
var ret time.Time
if err := db.QueryRow("select time from temp where id = ?", 1).Scan(&ret); err != nil {
t.Fatal(err)
}
if ret != now {
t.Fatalf("unexpected return value: want=%v, is=%v", now, ret)
}
exec(t, db, "drop table temp")
}