Code Monkey home page Code Monkey logo

Comments (12)

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
Please, provide small program to demonstrate the problem. Thank you.

Alex

Original comment by [email protected] on 11 Apr 2014 at 7:35

  • Changed state: WaitingForReply

from odbc.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
[deleted comment]

from odbc.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
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 [email protected] on 11 Apr 2014 at 8:35

from odbc.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
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 [email protected] on 11 Apr 2014 at 11:05

from odbc.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
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 [email protected] on 11 Apr 2014 at 2:31

from odbc.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
Thank you for the code. I will try it.

Alex

Original comment by [email protected] on 12 Apr 2014 at 2:26

from odbc.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
I can see your problem now. Here https://codereview.appspot.com/87490043/ is 
the fix. Please, review. Thank you.

Alex

Original comment by [email protected] on 14 Apr 2014 at 4:14

from odbc.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024

Original comment by [email protected] on 14 Apr 2014 at 4:15

  • Changed state: Started

from odbc.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
I can't link the address: https://codereview.appspot.com/87490043/
Did you write a short fix at here, thanks.

Original comment by [email protected] on 14 Apr 2014 at 4:28

from odbc.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
Sure. Please, see a.diff file attached.

Alex

Original comment by [email protected] on 14 Apr 2014 at 4:32

Attachments:

from odbc.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
Issue 41 has been merged into this issue.

Original comment by [email protected] on 28 Apr 2014 at 11:33

from odbc.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
This issue was closed by revision a8ac5d333051.

Original comment by [email protected] on 6 May 2014 at 1:56

  • Changed state: Fixed

from odbc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.