darkwood001 / odbc

Automatically exported from code.google.com/p/odbc
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

empty 'SQLExecute' error #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
edit file.go with:

package main

import (
    _ "code.google.com/p/odbc"
    "database/sql"
    "runtime"
)

func mssqlConnect() (db *sql.DB, err error) {
    params := map[string]string{
        "driver":   "freetds",
        "server":   "host",
        "port":     "port",
        "database": "database",
        "uid":      "uid",
        "pwd":      "pwd",
    }
    if runtime.GOOS == "windows" {
        params["driver"] = "sql server"
    }

    var c string
    for n, v := range params {
        c += n + "=" + v + ";"
    }
    db, err = sql.Open("odbc", c)
    if err != nil {
        return nil, err
    }
    return db, nil
}

func main() {
    db, err := mssqlConnect()
    if err != nil {
        panic(err.Error())
    }
    defer db.Close()

    columnName := "DOCUM"

    _, errQuery := db.Query(`SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name = ?
ORDER BY schema_name, table_name;`, columnName)
    if errQuery != nil {
        panic(errQuery.Error())
    }
}

run:
go run file.go

What is the expected output? What do you see instead?
The program should exit without any output but I see the following instead. I 
only see "SQLExecute:" without any details.

panic: SQLExecute:

goroutine 1 [running]:
main.main()
        /home/bbigras/debug-odbc/test.go:50 +0x14b

goroutine 2 [syscall]:
exit status 2

What version of the product are you using? On what operating system?
go version go1.1.2 linux/386
freetds 0.82-6build1
tdsodbc 0.82-6build1
unixodbc 2.2.11-21
Ubuntu 10.04.4 LTS

Please provide any additional information below.
I only have this problem on Linux. It's fine on Windows 7 (64-bits).

Original issue reported on code.google.com by bigras.b...@gmail.com on 21 Aug 2013 at 8:41

GoogleCodeExporter commented 9 years ago
Note that it works if I remove the `columnName := "DOCUM"` line and use the 
following code for the query :

_, errQuery := db.Query(`SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name = 'DOCUM'
ORDER BY schema_name, table_name;`)
        if errQuery != nil {
                panic(errQuery.Error())
        }

Original comment by bigras.b...@gmail.com on 21 Aug 2013 at 8:43

GoogleCodeExporter commented 9 years ago
I have added this test

diff --git a/mssql_test.go b/mssql_test.go
--- a/mssql_test.go
+++ b/mssql_test.go
@@ -862,3 +862,37 @@

    exec(t, db, "drop table dbo.temp")
 }
+
+func TestMSSQLALEX(t *testing.T) {
+   db, sc, err := mssqlConnect()
+   if err != nil {
+       t.Fatal(err)
+   }
+   defer closeDB(t, db, sc, sc)
+
+   columnName := "id"
+   rows, err := db.Query(`SELECT t.name AS table_name,
+       SCHEMA_NAME(schema_id) AS schema_name,
+       c.name AS column_name
+       FROM sys.tables AS t
+       INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
+       WHERE c.name = ?
+       ORDER BY schema_name, table_name;`, columnName)
+   if err != nil {
+       t.Fatalf("db.Query failed: %v", err)
+   }
+   defer rows.Close()
+
+   for rows.Next() {
+       var table_name, schema_name, column_name string
+       err = rows.Scan(&table_name, &schema_name, &column_name)
+       if err != nil {
+           t.Fatal(err)
+       }
+       t.Logf("table_name=%v schema_name=%v column_name=%v", table_name, 
schema_name, column_name)
+   }
+   err = rows.Err()
+   if err != nil {
+       t.Fatal(err)
+   }
+}

that is similar to your sample. And that prints all columns named id in my 
database with no problem on both Windows XP 32 bit and Linux-386 (I use 
freetds-0.91 and unixODBC-2.3.1).

Maybe you should try and update your linux drivers. Not sure if I can help you 
more.

Alex

Original comment by alex.bra...@gmail.com on 23 Aug 2013 at 2:11

GoogleCodeExporter commented 9 years ago
I got rid of the problem by upgrading to freetds 0.91.

Original comment by bigras.b...@gmail.com on 23 Aug 2013 at 6:49

GoogleCodeExporter commented 9 years ago
Sounds good.

Alex

Original comment by alex.bra...@gmail.com on 25 Aug 2013 at 8:52