mattn / go-adodb

Microsoft ActiveX Object DataBase driver for go that using exp/sql
http://mattn.kaoriya.net/
MIT License
142 stars 36 forks source link

MSSQL 2000,2012 Datetime result not same in db datetime #38

Closed derit closed 6 years ago

derit commented 6 years ago

i found a bug, time result not same in go-adodb and real datetime in db, i'm using mssql 2000,2012 and go1.9.1 windows/386
example query : SELECT GETDATE() AS tgl result : 2018-10-05 13:57:54.907

code


    rows, err := DB.Query("SELECT  GETDATE() AS tgl")
    if err != nil {
        fmt.Printf("select query err: %s/n", err)
    }
    for rows.Next() {
        var dt time.Time

        rows.Scan(&dt)

        println(b.String())

    }

result in go-adodb : 2018-10-05 13:53:28 +0700 +07

need result : 2018-10-05 13:57:54.907 +0700 +07

mattn commented 6 years ago

Probably, it should be fixed with similar patch.

https://github.com/mattn/go-adodb/commit/329577bf18e68c091cfb6b29a43eeac2410c53be

derit commented 6 years ago

this is urgent, because a difference data in db

mattn commented 6 years ago

Yes, I understand. But currently I do not have an environment to prepare MSSQL server. Please take me some time. If you try patch and will get fixes, please let me know.

derit commented 6 years ago

okay, i wish the problem solved soon

mattn commented 6 years ago

I tried this but don't reproduce this.

package main

import (
    "database/sql"
    "log"
    "time"

    _ "github.com/mattn/go-adodb"
)

func main() {
    db, err := sql.Open("adodb", `Driver={SQL Server};Server=XXXXX\SQLEXPRESS;Database=example`)
    if err != nil {
        log.Fatal(err)
    }
    rows, err := db.Query("SELECT GETDATE() AS tgl")
    if err != nil {
        log.Fatalf("select query err: %s/n", err)
    }
    for rows.Next() {
        var dt time.Time
        println(time.Now().Format("2006/01/02 15:04:05.000"))
        rows.Scan(&dt)
        println(dt.Format("2006/01/02 15:04:05.000"))
    }
}
2018/10/06 14:34:17.769
2018/10/06 14:34:17.000
derit commented 6 years ago

yes you get difference between date real date in system 2018/10/06 14:34:17.769 after query 2018/10/06 14:34:17.000 milliseconds is difference

mattn commented 6 years ago

This is delay for rows.Scan(). I think this is a reasonable value. Your case seems to bee differ for four minutes.

2018-10-05 13:53:28 +0700 +07 2018-10-05 13:57:54.907 +0700 +07

mattn commented 6 years ago

Perhaps your SQL server have time legs.

mattn commented 6 years ago

Also you can try this PR. This fix nanoseconds differ. But won't fix your four minutes differ.

https://github.com/mattn/go-adodb/pull/39

derit commented 6 years ago

thanks, problem solved