alexbrainman / odbc

odbc driver written in go
BSD 3-Clause "New" or "Revised" License
359 stars 141 forks source link

MSSQL datetime insert through code.google.com/p/odbc #36

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create table in MSSQL with datetime column (e.g. dt1)
2. Try insert into that table value of time.Time type
3. Get error:
SQLExecute: {22008} [Microsoft][SQL Server Native Client 11.0]Datetime field 
overflow. Fractional second precision exceeds the scale specified in the 
parameter binding.

Windows 7 version 6.1 running on x86; Cp1251; ru_RU (goworks)
go 1.2 windows/386

var ctime time.Time
ctime = time.Now()
res, err := DB.Exec(`INSERT INTO tmp_table (dt1) VALUES (?)`, ctime)
->> SQLExecute: {22008} [Microsoft][SQL Server Native Client 11.0]Datetime 
field overflow. Fractional second precision exceeds the scale specified in the 
parameter binding.

Original issue reported on code.google.com by mge...@gmail.com on 20 Mar 2014 at 10:08

GoogleCodeExporter commented 9 years ago
MS SQL cannot store time.Time without loss of data. You have to round your 
time.Time values to avoid data loss. For example, you can store 
time.Now().Round(time.Second) instead of time.Now().

See this thread 
https://groups.google.com/d/topic/golang-nuts/OBCcs1Tu0UE/discussion for 
details.

Alex

Original comment by alex.bra...@gmail.com on 21 Mar 2014 at 5:03