Closed GoogleCodeExporter closed 9 years ago
Please, provide a small example program to demonstrate the problem. Thank you.
Alex
Original comment by alex.bra...@gmail.com
on 11 Dec 2013 at 12:41
Original comment by alex.bra...@gmail.com
on 11 Dec 2013 at 12:46
// go test "-msdriver=sql server native client 11.0" -mssrv=192.168.1.2
-msdb=tpt_data_386_test -msuser=tpt -m spass=extreme -v -run=MS
func TestMSSQLDatetimeParam(t *testing.T) {
db, sc, err := mssqlConnect()
if err != nil {
t.Fatal(err)
}
defer closeDB(t, db, sc, sc)
if !is2008OrLater(db) {
t.Skip("skipping test; needs MS SQL Server 2008 or later")
}
db.Exec("drop table dbo.temp")
exec(t, db, "create table dbo.temp (dt datetime)")
expect := time.Date(2007, 5, 8, 12, 35, 29, 1234567e2, time.Local)
_, err = db.Exec("insert into dbo.temp (dt) values (?)", expect)
if err != nil {
t.Fatal(err)
}
var got time.Time
err = db.QueryRow("select top 1 dt from dbo.temp").Scan(&got)
if err != nil {
t.Fatal(err)
}
if expect != got {
t.Fatalf("expect %v, but got %v", expect, got)
}
exec(t, db, "drop table dbo.temp")
}
Original comment by runner....@gmail.com
on 7 Jan 2014 at 3:31
Your datatime overflows.
MS SQL Server only supports 3 digits after decimal point in seconds. See for
example http://msdn.microsoft.com/en-us/library/ms187819.aspx.
If you need precision better then that, use new datetime2 type. If you don't
need the precision, just round your time.Time values before posting them into
your database server.
Alex
Original comment by alex.bra...@gmail.com
on 7 Jan 2014 at 4:18
I think you should let it automatically adjust precision in driver.
Original comment by runner....@gmail.com
on 7 Jan 2014 at 5:29
I think differently. Sorry.
Alex
Original comment by alex.bra...@gmail.com
on 7 Jan 2014 at 5:43
Issue 45 has been merged into this issue.
Original comment by alex.bra...@gmail.com
on 25 Jun 2014 at 4:12
Original issue reported on code.google.com by
runner....@gmail.com
on 10 Dec 2013 at 7:38