FAQ
I am running into an issue with both go-odbc and mgodbc

Error occured reading row: sql: Scan error on column index 0: converting
string "1.005998e+06" to a int64: strconv.ParseInt: parsing "1.005998+06

I am hitting a SqlServer 2008 db and the column type I am trying to pull is
bigint. I can scan the rows fine when the value returned is below 1000000


db, err := sql.Open("mgodbc", dsn)
defer db.Close()

stmt, err := db.Prepare("SELECT TOP 100 Id FROM Catalog")
defer stmt.Close()

rows, err := stmt.Query()
defer rows.Close()

for rows.Next() {
var id int64
err = rows.Scan(&id)

log.Printf("Id: %d\n", id)
}


I was first using int instead of int64 but did not make a difference.

What am I doing wrong?

--

Search Discussions

  • Luke Mauldin at Nov 14, 2012 at 6:29 pm
    Have you tried using https://github.com/LukeMauldin/lodbc/
    On Wednesday, November 14, 2012 12:14:36 PM UTC-6, Derek Tracy wrote:

    I am running into an issue with both go-odbc and mgodbc

    Error occured reading row: sql: Scan error on column index 0: converting
    string "1.005998e+06" to a int64: strconv.ParseInt: parsing "1.005998+06

    I am hitting a SqlServer 2008 db and the column type I am trying to pull
    is bigint. I can scan the rows fine when the value returned is below
    1000000


    db, err := sql.Open("mgodbc", dsn)
    defer db.Close()

    stmt, err := db.Prepare("SELECT TOP 100 Id FROM Catalog")
    defer stmt.Close()

    rows, err := stmt.Query()
    defer rows.Close()

    for rows.Next() {
    var id int64
    err = rows.Scan(&id)

    log.Printf("Id: %d\n", id)
    }


    I was first using int instead of int64 but did not make a difference.

    What am I doing wrong?
    --
  • Bsr at Nov 14, 2012 at 6:39 pm
    Luke, is it only for Windows. I am not sure the compatibility of SYSCALL.
    On Wednesday, November 14, 2012 1:29:11 PM UTC-5, Luke Mauldin wrote:

    Have you tried using https://github.com/LukeMauldin/lodbc/
    On Wednesday, November 14, 2012 12:14:36 PM UTC-6, Derek Tracy wrote:

    I am running into an issue with both go-odbc and mgodbc

    Error occured reading row: sql: Scan error on column index 0: converting
    string "1.005998e+06" to a int64: strconv.ParseInt: parsing "1.005998+06

    I am hitting a SqlServer 2008 db and the column type I am trying to pull
    is bigint. I can scan the rows fine when the value returned is below
    1000000


    db, err := sql.Open("mgodbc", dsn)
    defer db.Close()

    stmt, err := db.Prepare("SELECT TOP 100 Id FROM Catalog")
    defer stmt.Close()

    rows, err := stmt.Query()
    defer rows.Close()

    for rows.Next() {
    var id int64
    err = rows.Scan(&id)

    log.Printf("Id: %d\n", id)
    }


    I was first using int instead of int64 but did not make a difference.

    What am I doing wrong?
    --
  • Derek Tracy at Nov 14, 2012 at 7:29 pm
    Forgot to reply-to-all


    ---------- Forwarded message ----------
    From: Derek Tracy <tracyde@gmail.com>
    Date: Wed, Nov 14, 2012 at 1:36 PM
    Subject: Re: [go-nuts] Re: odbc ParseInt errors
    To: Luke Mauldin <lukemauldin@gmail.com>


    I am running this Go program on a Linux box, so I don't think lodbc would
    work since it uses SYSCALL

    ---------------------------------
    Derek Tracy
    tracyde@gmail.com
    ---------------------------------



    On Wed, Nov 14, 2012 at 1:29 PM, Luke Mauldin wrote:

    Have you tried using https://github.com/LukeMauldin/lodbc/

    On Wednesday, November 14, 2012 12:14:36 PM UTC-6, Derek Tracy wrote:

    I am running into an issue with both go-odbc and mgodbc

    Error occured reading row: sql: Scan error on column index 0: converting
    string "1.005998e+06" to a int64: strconv.ParseInt: parsing "1.005998+06

    I am hitting a SqlServer 2008 db and the column type I am trying to pull
    is bigint. I can scan the rows fine when the value returned is below
    1000000


    db, err := sql.Open("mgodbc", dsn)
    defer db.Close()

    stmt, err := db.Prepare("SELECT TOP 100 Id FROM Catalog")
    defer stmt.Close()

    rows, err := stmt.Query()
    defer rows.Close()

    for rows.Next() {
    var id int64
    err = rows.Scan(&id)

    log.Printf("Id: %d\n", id)
    }


    I was first using int instead of int64 but did not make a difference.

    What am I doing wrong?
    --

    --
  • Derek Tracy at Nov 14, 2012 at 7:32 pm
    I did find a work around.

    If I cast the bigint to varchar(max) in the select the odbc driver
    correctly converts that to an int64

    "SELECT TOP 100 CAST(Id VARCHAR(MAX)) FROM Catalog"

    Still would like to figure out why the bigint is being put into scientific
    notation in the first place

    On Wed, Nov 14, 2012 at 2:29 PM, Derek Tracy wrote:

    Forgot to reply-to-all



    ---------- Forwarded message ----------
    From: Derek Tracy <tracyde@gmail.com>
    Date: Wed, Nov 14, 2012 at 1:36 PM
    Subject: Re: [go-nuts] Re: odbc ParseInt errors
    To: Luke Mauldin <lukemauldin@gmail.com>


    I am running this Go program on a Linux box, so I don't think lodbc would
    work since it uses SYSCALL
    ---------------------------------
    Derek Tracy
    tracyde@gmail.com
    ---------------------------------



    On Wed, Nov 14, 2012 at 1:29 PM, Luke Mauldin wrote:

    Have you tried using https://github.com/LukeMauldin/lodbc/

    On Wednesday, November 14, 2012 12:14:36 PM UTC-6, Derek Tracy wrote:

    I am running into an issue with both go-odbc and mgodbc

    Error occured reading row: sql: Scan error on column index 0:
    converting string "1.005998e+06" to a int64: strconv.ParseInt: parsing
    "1.005998+06
    I am hitting a SqlServer 2008 db and the column type I am trying to
    pull is bigint. I can scan the rows fine when the value returned is below
    1000000

    db, err := sql.Open("mgodbc", dsn)
    defer db.Close()

    stmt, err := db.Prepare("SELECT TOP 100 Id FROM Catalog")
    defer stmt.Close()

    rows, err := stmt.Query()
    defer rows.Close()

    for rows.Next() {
    var id int64
    err = rows.Scan(&id)

    log.Printf("Id: %d\n", id)
    }


    I was first using int instead of int64 but did not make a difference.

    What am I doing wrong?
    --
    --
  • Brainman at Nov 15, 2012 at 12:36 am

    On Thursday, 15 November 2012 05:14:36 UTC+11, Derek Tracy wrote:

    What am I doing wrong?
    I think, the database/sql driver doesn't handle type conversions properly.
    I do not know about mgodbc, I only looked at go-odbc, and it does not
    handle odbc C.SQL_NUMERIC type, and that is what sql server returns for
    "bigint" fields. Perhaps, if you report your issue to the driver author,
    they will help.

    Alternatively, you could try my driver http://code.google.com/p/odbc. It
    might work for you.

    Alex

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 14, '12 at 6:14p
activeNov 15, '12 at 12:36a
posts6
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase