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

unsupported driver -> Scan pair: <nil> -> *string #40

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

unsupported driver -> Scan pair: <nil> -> *string #40

GoogleCodeExporter opened this issue Jun 15, 2015 · 12 comments

Comments

@GoogleCodeExporter
Copy link

when select columns from database, if some column's value is '', it will 
occurred error: unsupported driver -> Scan pair: <nil> -> *string,
so I changed the source at: column.go, line 134:
case api.SQL_C_WCHAR:
        if p == nil {
            //return nil, nil
            return "", nil
        }
        s := (*[1 << 20]uint16)(p)[:len(buf)/2]
        return utf16toutf8(s), nil

Original issue reported on code.google.com by Zuggie....@gmail.com on 11 Apr 2014 at 3:30

@GoogleCodeExporter
Copy link
Author

Please, provide small program to demonstrate the problem. Thank you.

Alex

Original comment by alex.bra...@gmail.com on 11 Apr 2014 at 7:35

  • Changed state: WaitingForReply

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

Error: sql: Scan error on column index 4: unsupported driver -> Scan pair: 
<nil> -> *string
Query: SELECT TOP 10 ROW_NUMBER() OVER(ORDER BY SSN_NO), SSN_NO, 
                 CURR_STATION, RESULT, ISNULL(FAILCODE, '') 
           FROM SFC_SSN(NOLOCK) 
          WHERE WONO=?
Condition: [NE03300016]

the column FAILCODE type is: NVARCHAR(30)

Original comment by Zuggie....@gmail.com on 11 Apr 2014 at 8:35

@GoogleCodeExporter
Copy link
Author

SQL is nice, but I still don't see what the problem is. Please provide small Go 
program I can run to see your problem. Show what you program displays and 
explain why its output is wrong. Hopefully I will be able to run your program 
here.

Thank you.

Alex

Original comment by alex.bra...@gmail.com on 11 Apr 2014 at 11:05

@GoogleCodeExporter
Copy link
Author

package main

import (
    _ "./odbc"
    "database/sql"
    "fmt"
    "reflect"
)

const (
    ConnectString = "driver={sql server};server=servername;database=database;uid=sa;pwd=password"
)

func FetchAllRowsPtr(query string, struc interface{}, cond ...interface{}) 
*[]interface{} {
    db, err := sql.Open("odbc", ConnectString)
    if err != nil {
        fmt.Printf("sql.Open Error: %v\n", err)
        panic(err)
    }
    defer db.Close()

    stmt, err := db.Prepare(query)
    if err != nil {
        fmt.Printf("db.Prepare Error: %v\n", err)
        panic(err)
    }
    defer stmt.Close()

    rows, err := stmt.Query(cond...)
    if err != nil {
        fmt.Printf("stmt.Query Error: %v\n", err)
        panic(err)
    }
    defer rows.Close()

    result := make([]interface{}, 0)
    s := reflect.ValueOf(struc).Elem()
    leng := s.NumField()
    onerow := make([]interface{}, leng)
    for i := 0; i < leng; i++ {
        onerow[i] = s.Field(i).Addr().Interface()
    }
    for rows.Next() {
        err = rows.Scan(onerow...)
        if err != nil {
            fmt.Printf("Error: %v\nQuery: %v\nCondition: %v\n", err, query, cond)
            panic(err)
        }
        result = append(result, s.Interface())
    }

    return &result
}

type WoDetail struct {
    Index    int
    Serial   string
    Curr     string
    Result   string
    Failcode string
}

func getdate(wono string) {
    wo_ls := FetchAllRowsPtr(
        `SELECT TOP 10 ROW_NUMBER() OVER(ORDER BY SSN_NO), SSN_NO, 
                 CURR_STATION, RESULT, ISNULL(FAILCODE, '') 
           FROM SFC_SSN(NOLOCK) 
          WHERE WONO=?`, new(WoDetail), wono)
    fmt.Printf("values: %v\n", wo_ls)
}

func main() {
    getdate('NE03300016')
}

// at the line 47, will occurred the error

Original comment by Zuggie....@gmail.com on 11 Apr 2014 at 2:31

@GoogleCodeExporter
Copy link
Author

Thank you for the code. I will try it.

Alex

Original comment by alex.bra...@gmail.com on 12 Apr 2014 at 2:26

@GoogleCodeExporter
Copy link
Author

I can see your problem now. Here https://codereview.appspot.com/87490043/ is 
the fix. Please, review. Thank you.

Alex

Original comment by alex.bra...@gmail.com on 14 Apr 2014 at 4:14

@GoogleCodeExporter
Copy link
Author

Original comment by alex.bra...@gmail.com on 14 Apr 2014 at 4:15

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

I can't link the address: https://codereview.appspot.com/87490043/
Did you write a short fix at here, thanks.

Original comment by Zuggie....@gmail.com on 14 Apr 2014 at 4:28

@GoogleCodeExporter
Copy link
Author

Sure. Please, see a.diff file attached.

Alex

Original comment by alex.bra...@gmail.com on 14 Apr 2014 at 4:32

Attachments:

@GoogleCodeExporter
Copy link
Author

Issue 41 has been merged into this issue.

Original comment by alex.bra...@gmail.com on 28 Apr 2014 at 11:33

@GoogleCodeExporter
Copy link
Author

This issue was closed by revision a8ac5d333051.

Original comment by alex.bra...@gmail.com on 6 May 2014 at 1:56

  • Changed state: Fixed

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