Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datetime field overflow with sql server 2008 #28

Closed
GoogleCodeExporter opened this issue Jun 15, 2015 · 7 comments
Closed

Datetime field overflow with sql server 2008 #28

GoogleCodeExporter opened this issue Jun 15, 2015 · 7 comments

Comments

@GoogleCodeExporter
Copy link


SQLExecute: {22008} [Microsoft][SQL Server Native Client 11.0]Datetime 
字段溢出。秒的小数精度超出了在参数绑定中指定的小数位��
�。

PATCH:
--- a/param.go  Fri Nov 15 09:34:59 2013 +1100
+++ b/param.go  Tue Dec 10 15:34:00 2013 +0800
@@ -102,7 +102,7 @@
                        Hour:     api.SQLUSMALLINT(d.Hour()),
                        Minute:   api.SQLUSMALLINT(d.Minute()),
                        Second:   api.SQLUSMALLINT(d.Second()),
-                       Fraction: api.SQLUINTEGER(d.Nanosecond()),
+                       Fraction: 0,
                }
                p.Data = &b
                buf = unsafe.Pointer(&b)
@@ -113,7 +113,9 @@
                if decimal <= 0 {
                        // represented as yyyy-mm-dd hh:mm:ss.fff format in ms sql server
                        decimal = 3
+                       b.Fraction = api.SQLUINTEGER(d.Nanosecond() / 
int(time.Millisecond))
                }
                size = 20 + api.SQLULEN(decimal)
        case []byte:


Original issue reported on code.google.com by runner....@gmail.com on 10 Dec 2013 at 7:38

@GoogleCodeExporter
Copy link
Author

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

@GoogleCodeExporter
Copy link
Author

Original comment by alex.bra...@gmail.com on 11 Dec 2013 at 12:46

  • Changed state: WaitingForReply

@GoogleCodeExporter
Copy link
Author

//  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

@GoogleCodeExporter
Copy link
Author

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

  • Changed state: WontFix

@GoogleCodeExporter
Copy link
Author

I think you should let it automatically adjust precision in driver.

Original comment by runner....@gmail.com on 7 Jan 2014 at 5:29

@GoogleCodeExporter
Copy link
Author

I think differently. Sorry.

Alex

Original comment by alex.bra...@gmail.com on 7 Jan 2014 at 5:43

@GoogleCodeExporter
Copy link
Author

Issue 45 has been merged into this issue.

Original comment by alex.bra...@gmail.com on 25 Jun 2014 at 4:12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant