minus5 / gofreetds

Go Sql Server database driver.
MIT License
113 stars 48 forks source link

Incorrect SQL Syntax - Unclosed quotation mark after the character string #51

Open huaguoping opened 7 years ago

huaguoping commented 7 years ago

Hi, everyone. I encountered a strange problem.When I run the same code on test platform using the same conf, it work well. Once I run the same code on production platform, I got the following error:

General SQL Server error: Check messages from the SQL Server

Msg 170, Level 15
General SQL Server error: Check messages from the SQL Server

Msg 105, Level 15, State 1
Server 'SERVER', Line 24
        Unclosed quotation mark before the character string '<E5><90>?'.

Msg 170, Level 15, State 1
Server 'SERVER', Line 24
        Line 24: Incorrect syntax near '<E5><90>?'.

My code is :

_, err := db.Exec(`
        INSERT INTO Table (
            field1
            , field2
            , field3
            , field4
            , field5
            , field6
            , field7
            , field8
            , field9) 
            VALUES (
                ?
                ,?
                ,?
                ,?
                ,?
                ,?
                ,?
                ,?
                ,?)`, info.TopMarketId, Info.MarketId, Info.GoodsId, Info.GoodsAttribute, Info.TrackDate, Info.Value, Info.TimeCreated, Info.TimeLastUpdated, Info.Type)
    if err != nil {
        log.Println("DB Exec failed: ", err.Error())
        return err
    }

Anyone can help?Thank you very much : )

ianic commented 7 years ago

In case like this I will fire up SQL Server Profiler and catch the exact command which is sent to the mssql. The other way is to switch on freetds logging and find there the command:

export TDSDUMP=/tmp/freetds.log
./my_app
...
less /tmp/freetds.log

Once you find what is exactly sent to the mssql it should be obvious where we failed.