Closed GoogleCodeExporter closed 9 years ago
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
[deleted comment]
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
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
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
Thank you for the code. I will try it.
Alex
Original comment by alex.bra...@gmail.com
on 12 Apr 2014 at 2:26
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
Original comment by alex.bra...@gmail.com
on 14 Apr 2014 at 4:15
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
Sure. Please, see a.diff file attached.
Alex
Original comment by alex.bra...@gmail.com
on 14 Apr 2014 at 4:32
Attachments:
Issue 41 has been merged into this issue.
Original comment by alex.bra...@gmail.com
on 28 Apr 2014 at 11:33
This issue was closed by revision a8ac5d333051.
Original comment by alex.bra...@gmail.com
on 6 May 2014 at 1:56
Original issue reported on code.google.com by
Zuggie....@gmail.com
on 11 Apr 2014 at 3:30