Microsoft ActiveX Object DataBase driver for go that using exp/sql

go-adodb

Microsoft ADODB driver conforming to the built-in database/sql interface

Installation

This package can be installed with the go get command:

go get github.com/mattn/go-adodb

Documentation

API documentation can be found here: http://godoc.org/github.com/mattn/go-adodb

Examples can be found under the ./_example directory

Note

If you met the issue that your apps crash, try to import blank import of runtime/cgo like below.

import (
    ...
    _ "runtime/cgo"
)

License

MIT: http://mattn.mit-license.org/2015

Author

Yasuhiro Matsumoto (a.k.a mattn)

Owner
mattn
Long-time Golang user&contributor, Google Dev Expert for Go, and author of many Go tools, Vim plugin author. Windows hacker C#/Java/C/C++
mattn
Comments
  • can't get first one line

    can't get first one line

    In my sql server has three lines data, but throw sql server only get two data. Can't get first one line

    package main
    
    import (
    "fmt"
    _ "github.com/mattn/go-adodb"
    "database/sql"
    )
    func main() {
    db, err := sql.Open("adodb", "Provider=SQLOLEDB;Initial Catalog=test;Data Source=SH-XIEMENGJUN\\SQLEXPRESS;user id=sa;password=123456")
    
    if err != nil {
        panic(err)
    }
    rows, err := db.Query("select uid, username from userinfo")
    if err != nil {
        fmt.Println(err)
        return
    }
    defer rows.Close()
    
    for rows.Next() {
        var id int
        var name string
        rows.Scan(&id, &name)
        println(id, name)
    }
    }
    
  • MSSQL 2000,2012 Datetime result not same in db datetime

    MSSQL 2000,2012 Datetime result not same in db datetime

    i found a bug, time result not same in go-adodb and real datetime in db, i'm using mssql 2000,2012 and go1.9.1 windows/386
    example query : SELECT GETDATE() AS tgl result : 2018-10-05 13:57:54.907

    code

    
        rows, err := DB.Query("SELECT  GETDATE() AS tgl")
    	if err != nil {
    		fmt.Printf("select query err: %s/n", err)
    	}
    	for rows.Next() {
    		var dt time.Time
    
    		rows.Scan(&dt)
    		 
    		println(b.String())
    		
    	}
    

    result in go-adodb : 2018-10-05 13:53:28 +0700 +07

    need result : 2018-10-05 13:57:54.907 +0700 +07

  • db.Query breaks the application over ab benchmark

    db.Query breaks the application over ab benchmark

    I have divided the mdb.go example in two apps:

    • mdb1 for the DB load http://play.golang.org/p/gvLXYfFCif
    • mdb2 for the querys http://play.golang.org/p/ePg2uTHy21

    When I test the mdb2 app manually with the browser, curl, etc it works fine, but when y put them on load, for example:

    ab -n 100 -c 10 -k http://app.url/

    ab exits with "...apr_socket_recv: Connection reset by peer (54)", and the app crashes with:

    Exception 0xc00000fd 0x0 0x3150263c
    PC=0x31e4d284fr French
    
    signal arrived during cgo execution
    
    syscall.Syscall9(0x4bcc6bd6, 0x9, 0x315922a0, 0x5, 0x6d65f0, ...de German
    )
    es Spanish
            /usr/local/go/src/pkg/runtime/zsyscall_windows_windows_386.c:123 +0x49
    github.com/mattn/go-ole.invoke(0x315922a0, 0x5, 0x1, 0x0, 0x0, ...)
            /Users/pmd/Dropbox/Code/go/src/github.com/mattn/go-ole/idispatch.go
    

    I have test it wit wrk with similar errors:

    wrk -t2 -c10 -d5s http://app.url

    Thanks.

  • Returns corrupt value when the data type is decimal or money in database(MS SQL Server 2005)

    Returns corrupt value when the data type is decimal or money in database(MS SQL Server 2005)

    Testing database: MS SQL Server 2005
    Table schema:
    create table Test(
        ID int,
        Amount decimal(9,2)
    )
    
    Prepare data:
    insert Test(ID, Amount)
    Values(1, 1.5)
    
    insert Test(ID, Amount)
    Values(1, 9.30)
    
    Go code
    package main
    
    import (
        "database/sql"
       "fmt"
        _ "github.com/mattn/go-adodb"
       )
    
    func main() {
        db, err := sql.Open("adodb", "connection string")
        if err != nil {
            log.Printf("Can't open database as error: %s", err)
        } else {
            fmt.Println("Connected database")
        }
    
        sql := "select ID, Amount from Test"
        rows, err := db.Query(sql)
        checkError(err)
    
        for rows.Next() {
            var id int
            var money float64
            err = rows.Scan(&id, &money)
            checkError(err)
            fmt.Println("ID: "id, " Amount: ", money)
        }
    }
    
    func checkError(err error) {
        if err != nil {
            log.Println(err)
        }
    }
    
    Testing result:
    ID:  1  Amount:  150
    ID:  1  Amount:  930
    

    If I alter data type decimal to money, will get error as below

     2013/01/17 15:49:50 sql: Scan error on column index 1: converting string "<nil>"
     to a float64: strconv.ParseFloat: parsing "<nil>": invalid syntax
    ID:  1  Amount:  0
    2013/01/17 15:49:50 sql: Scan error on column index 1: converting string "<nil>"
    to a float64: strconv.ParseFloat: parsing "<nil>": invalid syntax
    ID:  1  Amount:  0
    2013/01/17 15:49:50 sql: Scan error on column index 1: converting string "<nil>"
    to a float64: strconv.ParseFloat: parsing "<nil>": invalid syntax
    
  • DateTime Fields  Always return

    DateTime Fields Always return "2118-03-XX XX:XX:XX.XXXXXXXXXXXX UTC"

    The code is as following:

    ============================
    for rows.Next() {
            var date time.Time
            rows.Scan(&date)
            fmt.Println(date)
        }
    ============================
    

    The Result is as followiing:

    2118-03-04 04:28:28.545076635 +0000 UTC

    2118-03-04 04:28:28.381231586 +0000 UTC
    
2118-03-04 04:28:27.996275258 +0000 UTC
    
2118-03-04 04:28:27.826067295 +0000 UTC
    
2118-03-04 04:28:27.340895064 +0000 UTC
    
2118-03-04 04:28:27.242269889 +0000 UTC

    2118-03-04 04:28:27.041838082 +0000 UTC

    2118-03-04 04:28:26.865267204 +0000 UTC
    
2118-03-04 04:28:26.209887009 +0000 UTC
    
2118-03-04 04:28:25.976049901 +0000 UTC
    

    But in fact ,the Datas in My Database(MSQL2000 or MSSQL2008) are :

    2011-02-14 21:25:46.000
    2011-02-14 21:24:03.000
    2011-02-14 21:20:01.000
    2011-02-14 21:18:14.000
    2011-02-14 21:13:09.000
    2011-02-14 21:12:07.000
    2011-02-14 21:10:01.000
    2011-02-14 21:08:10.000
    2011-02-14 21:01:18.000
    2011-02-14 20:58:51.000
    

    Would Please tell me WHY? or What should I do to correct the errors? Thank You.

  • WinCC OLE  DB Provider error executing query

    WinCC OLE DB Provider error executing query

    So i have been trying to implement this module to access a database which using WinCC OLE DB Provider(Page 22 to 25). I can connect to the database using open method and i also successfully ping the database, but when i execute the query it returns error.

    here's the query.

    TAG:R,'SystemArchive\\1511_AT_1379A/MS.PV_Out#Value','2022-02-08 07:35:00.000', '2022-02-08 07:40:00.000'
    

    and here's the error log from the program i made.

    Test Connection String : Provider=WinCCOLEDBProvider.1;Persist Security Info=False;User ID="";Data Source=10.1.1.1\WINCC;Catalog=CC_OS_1__21_12_14_16_25_11R;Mode=Read;Location="";Mode=Read;Extended Properties=""

    Sql Driver : [adodb]

    Ping Successful!

    Test Query : TAG:R,'SystemArchive\1511_AT_1379A/MS.PV_Out#Value','2022-02-08 07:35:00.000', '2022-02-08 07:40:00.000' Error Preparing Statement Exception occurred. (Provider cannot derive parameter information and SetParameterInfo has not been called.)

    panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x1 addr=0x38 pc=0x864d82]

    goroutine 1 [running]: database/sql.(*Stmt).QueryContext(0x0, {0x8de310, 0xc00009e010}, {0x0, 0x0, 0x0}) C:/Program Files/Go/src/database/sql/sql.go:2726 +0x82 database/sql.(*Stmt).Query(...) C:/Program Files/Go/src/database/sql/sql.go:2784 main.main() D:/tugas/Pagawean/MusaGreen/Repo/adodb-wincc-oledb/main.go:63 +0x45f

    The point i take here is the provider cannot derive parameter information and the set parameter info has not been called. I have been trying to search across webs but i still havent managed to figure what the error exactly means and what the provider actually wants. Most cases i found is about the provider version x86 vs x64, which people prefer to use x86 and there is another one saying the error occured because of the provider bug so it needs to set the cursor within "ADODB.Connection" object. I have tried the second one by forking this repo and modify the Open() method by adding this line

    _, err = oleutil.PutProperty(db, "CursorLocation", 3)
    if err != nil {
    	return nil, err
    }
    val, err := oleutil.GetProperty(db, "Parameters")
    if err != nil {
    	return nil, err
    }
    dbrc := val.ToIDispatch()
    val.Clear()
    

    then i return the dbrc on return &AdodbConn{db: dbrc}, nil.

    Still no luck this far, is there anyone can point something out? is there anything i miss here? kind regard thank you :)

  • go get / build fails

    go get / build fails

    C:\Users\Alex>go get -u github.com/mattn/go-adodb

    github.com/mattn/go-adodb

    C:\devel\go\thirdparty\src\github.com\mattn\go-adodb\adodb.go:347: sa.PvData und efined (type *ole.SAFEARRAY has no field or method PvData) C:\devel\go\thirdparty\src\github.com\mattn\go-adodb\adodb.go:347: sa.RgsaBound undefined (type *ole.SAFEARRAY has no field or method RgsaBound) C:\devel\go\thirdparty\src\github.com\mattn\go-adodb\adodb.go:377: sa.PvData und efined (type *ole.SAFEARRAY has no field or method PvData) C:\devel\go\thirdparty\src\github.com\mattn\go-adodb\adodb.go:377: sa.RgsaBound undefined (type *ole.SAFEARRAY has no field or method RgsaBound)

  • How to get VT_VARIANT values from result?

    How to get VT_VARIANT values from result?

    Hi, first of all thanks for all the work you've put into making both this and go-ole.

    I need to get data out of a custom proprietary time series database for which an OLEDB driver is supplied. I managed to get things up and running for timestamp and integer parameters, but the driver returns certain values as VT_VARIANT to allow mutiple datatype to be returned in the same column.

    For example: image

    Here the value column is of type variant. The resulting object in the interface is of type *ole.VARIANT, but the VT is always empty:

    	rows, err := db.Query(queryData)
    	if err != nil {
    		fmt.Println("select", err)
    		return
    	}
    	defer rows.Close()
    
    	fmt.Println(rows.Columns())
    	ct, _ := rows.ColumnTypes()
    	fmt.Println(ct[0].Name(), ct[0].DatabaseTypeName(), ct[0].ScanType())
    
    	for rows.Next() {
    		var timestamp time.Time
    		var value interface{}
    		err = rows.Scan(&timestamp, &value)
    		if err != nil {
    			fmt.Println("scan", err)
    			return
    		}
    		fmt.Println(timestamp, value)
    	}
    
    2018-04-27 13:37:28 +0200 CEST &{VT_EMPTY 0 0 0 131693095766368559 [0 0 0 0 0 0 0 0]}
    2018-04-27 13:42:04 +0200 CEST &{VT_EMPTY 0 0 0 131693100061366196 [0 0 0 0 0 0 0 0]}
    2018-04-27 13:44:35 +0200 CEST &{VT_EMPTY 0 0 0 131693100061341924 [0 0 0 0 0 0 0 0]}
    2018-04-27 13:45:07 +0200 CEST &{VT_EMPTY 0 0 0 131693100061317651 [0 0 0 0 0 0 0 0]}
    2018-04-27 13:45:39 +0200 CEST &{VT_EMPTY 0 0 0 131693104356260674 [0 0 0 0 0 0 0 0]}
    2018-04-27 14:09:17 +0200 CEST &{VT_EMPTY 0 0 0 131693117241186835 [0 0 0 0 0 0 0 0]}
    2018-04-27 14:10:18 +0200 CEST &{VT_EMPTY 0 0 0 131693117241211108 [0 0 0 0 0 0 0 0]}
    2018-04-27 14:12:51 +0200 CEST &{VT_EMPTY 0 0 0 131693117241186835 [0 0 0 0 0 0 0 0]}
    2018-04-27 14:14:48 +0200 CEST &{VT_EMPTY 0 0 0 131693121536178404 [0 0 0 0 0 0 0 0]}
    2018-04-27 14:23:38 +0200 CEST &{VT_EMPTY 0 0 0 131693125831121427 [0 0 0 0 0 0 0 0]}
    2018-04-27 14:24:12 +0200 CEST &{VT_EMPTY 0 0 0 131693125831097154 [0 0 0 0 0 0 0 0]}
    2018-04-27 14:24:58 +0200 CEST &{VT_EMPTY 0 0 0 131693125831066814 [0 0 0 0 0 0 0 0]}
    2018-04-27 14:30:48 +0200 CEST &{VT_EMPTY 0 0 0 131693130126058382 [0 0 0 0 0 0 0 0]}
    

    How should I handle this type of column?

    Any ideas are much appreciated, spent almost a full day I trying different things 😞 Thanks in advance!!!

  • List of tables and fields

    List of tables and fields

    Hi,

    I'm looking for a way to extract tables and fields of a MSAccess database without making query. I wonder if go-adodb can help me for that or if i should look at go-ole ? (i'm not very confortable with windows api) Maybe there is an example for this ?

    Thanks

  • GUID  datetime  INSERT

    GUID datetime INSERT

    id is GUID uniqueidentifier [receivetime], [completetime] is datetime

    INSERT INTO [topic]([id],[receivetime], [completetime]) VALUES ('03fc4c83-dae6-4273-aae9-fb50c30248ab','2015-01-27 19:56:42.798', '2015-01-27 19:56:45.792') successful!!!!

    s, err := models.Db.Prepare(“INSERT INTO [topic]([id],[receivetime], [completetime]) VALUES (?,?,?)”)

    s.Exec(id,receivetime,completetime)

    failure???

  • multithread error and suggest (SQL Server 2k)

    multithread error and suggest (SQL Server 2k)

    Hello,Mattn. When I using go-adodb connecting the SQL Server 2000 with several connections,errors occured as"CoInitialize has not been called".

    So I have to modify the code adodb.go:

    1. remove ole.CoInitialize(0) from init()
    2. add ole.CoInitialize(0) to func (d *AdodbDriver) Open(dsn string) (driver.Conn, error)
    3. add ole.CoUninitialize() to func (c *AdodbConn) Close() error

    At last,sorry for my poor English ,and hope to be helpful!!

  • Error while creating MDB file with provided example

    Error while creating MDB file with provided example

    I just tried with the sample code provided in mdb.go but getting empty error message. Any help? Below is the code to test.

    package main

    import ( "database/sql" "fmt" "os" _ "runtime/cgo" "time"

    "github.com/go-ole/go-ole"
    "github.com/go-ole/go-ole/oleutil"
    _ "github.com/mattn/go-adodb"
    

    )

    var provider string

    func createMdb(f string) error { unk, err := oleutil.CreateObject("ADOX.Catalog") if err != nil { fmt.Println(err) return err } defer unk.Release() cat, err := unk.QueryInterface(ole.IID_IDispatch) if err != nil { fmt.Println("2") return err } defer cat.Release() provider = "Microsoft.Jet.OLEDB.4.0" r, err := oleutil.CallMethod(cat, "Create", "Provider="+provider+";Data Source="+f+";") if err != nil { provider = "Microsoft.ACE.OLEDB.12.0" r, err = oleutil.CallMethod(cat, "Create", "Provider="+provider+";Data Source="+f+";") if err != nil { fmt.Println("3") return err } } r.Clear() return nil }

    func main() { ole.CoInitialize(0) defer ole.CoUninitialize()

    f := "./example.mdb"
    
    os.Remove(f)
    
    err := createMdb(f)
    if err != nil {
    	fmt.Println("create mdb", err)
    	return
    }
    

    }

  • I cannot get any rows, when I query a proc

    I cannot get any rows, when I query a proc

    create proc xxx1 as insert table_1 select 1 select * from table_1

    golang

    rows, err := db.query('exec xxx1');
    
    rows.Columns();  // empty
    rows.Next();    //  false
    
  • do not support RowsNextResultSet

    do not support RowsNextResultSet

    // RowsNextResultSet extends the Rows interface by providing a way to signal // the driver to advance to the next result set. type RowsNextResultSet interface { Rows

    // HasNextResultSet is called at the end of the current result set and
    // reports whether there is another result set after the current one.
    HasNextResultSet() bool
    
    // NextResultSet advances the driver to the next result set even
    // if there are remaining rows in the current result set.
    //
    // NextResultSet should return io.EOF when there are no more result sets.
    NextResultSet() error
    

    }

  • Memory error when using OLE object column

    Memory error when using OLE object column

    I get a panic when trying to read an OLE object from a DB.

    The program fails the first time it calls rows.Next()

    I have attached a database to work with the following code:

    crash.zip

    package main
    
    import (
    	"database/sql"
    	"fmt"
    
    	"github.com/go-ole/go-ole"
    	_ "github.com/mattn/go-adodb"
    )
    
    func main() {
    	ole.CoInitialize(0)
    	defer ole.CoUninitialize()
    
    	db, err := sql.Open("adodb", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=crash.mdb;")
    	if err != nil {
    		fmt.Println("open", err)
    		return
    	}
    	defer db.Close()
    
    	rows, err := db.Query("select * from Table1")
    	if err != nil {
    		fmt.Println("select", err)
    		return
    	}
    	defer rows.Close()
    
    	for rows.Next() {
    		// Will never get here
    	}
    }
    ```
    
    
    
  • Update golang.org/x/net commit hash to 4628272

    Update golang.org/x/net commit hash to 4628272

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | golang.org/x/net | require | digest | 6afb519 -> 4628272 |


    Renovate configuration

    :date: Schedule: At any time (no schedule defined).

    :vertical_traffic_light: Automerge: Disabled by config. Please merge this manually once you are satisfied.

    :recycle: Rebasing: Whenever PR becomes conflicted, or if you tick the rebase/retry checkbox below.

    :no_bell: Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by WhiteSource Renovate. View repository job log here.

Microsoft SQL server driver written in go language

A pure Go MSSQL driver for Go's database/sql package Install Requires Go 1.8 or above. Install with go get github.com/denisenkom/go-mssqldb . Connecti

Dec 26, 2022
Oracle driver for Go using database/sql

go-oci8 Description Golang Oracle database driver conforming to the Go database/sql interface Installation Install Oracle full client or Instant Clien

Dec 30, 2022
sqlite3 driver for go using database/sql

go-sqlite3 Latest stable version is v1.14 or later not v2. NOTE: The increase to v2 was an accident. There were no major changes or features. Descript

Jan 8, 2023
Go driver for PostgreSQL over SSH. This driver can connect to postgres on a server via SSH using the local ssh-agent, password, or private-key.

pqssh Go driver for PostgreSQL over SSH. This driver can connect to postgres on a server via SSH using the local ssh-agent, password, or private-key.

Nov 6, 2022
Go Sql Server database driver.

gofreetds Go FreeTDS wrapper. Native Sql Server database driver. Features: can be used as database/sql driver handles calling stored procedures handle

Dec 16, 2022
Pure Go Postgres driver for database/sql

pq - A pure Go postgres driver for Go's database/sql package Install go get github.com/lib/pq Features SSL Handles bad connections for database/sql S

Jan 2, 2023
Attach hooks to any database/sql driver

sqlhooks Attach hooks to any database/sql driver. The purpose of sqlhooks is to provide a way to instrument your sql statements, making really easy to

Dec 14, 2022
Qmgo - The Go driver for MongoDB. It‘s based on official mongo-go-driver but easier to use like Mgo.

Qmgo English | 简体中文 Qmgo is a Go driver for MongoDB . It is based on MongoDB official driver, but easier to use like mgo (such as the chain call). Qmg

Dec 28, 2022
Mirror of Apache Calcite - Avatica Go SQL Driver

Apache Avatica/Phoenix SQL Driver Apache Calcite's Avatica Go is a Go database/sql driver for the Avatica server. Avatica is a sub-project of Apache C

Nov 3, 2022
Firebird RDBMS sql driver for Go (golang)

firebirdsql (Go firebird sql driver) Firebird RDBMS http://firebirdsql.org SQL driver for Go Requirements Firebird 2.5 or higher Golang 1.13 or higher

Dec 20, 2022
Go-odm, a Golang Object Document Mapping for MongoDB.
Go-odm, a Golang Object Document Mapping for MongoDB.

A project of SENROK Open Source Go ODM Go-odm, a Golang Object Document Mapping for MongoDB. Table of contents Features Installation Get started Docum

Nov 4, 2022
GO DRiver for ORacle DB

Go DRiver for ORacle godror is a package which is a database/sql/driver.Driver for connecting to Oracle DB, using Anthony Tuininga's excellent OCI wra

Jan 5, 2023
PostgreSQL driver and toolkit for Go

pgx - PostgreSQL Driver and Toolkit pgx is a pure Go driver and toolkit for PostgreSQL. pgx aims to be low-level, fast, and performant, while also ena

Jan 4, 2023
Lightweight Golang driver for ArangoDB

Arangolite Arangolite is a lightweight ArangoDB driver for Go. It focuses on pure AQL querying. See AranGO for a more ORM-like experience. IMPORTANT:

Sep 26, 2022
Go language driver for RethinkDB
Go language driver for RethinkDB

RethinkDB-go - RethinkDB Driver for Go Go driver for RethinkDB Current version: v6.2.1 (RethinkDB v2.4) Please note that this version of the driver on

Dec 24, 2022
goriak - Go language driver for Riak KV
goriak - Go language driver for Riak KV

goriak Current version: v3.2.1. Riak KV version: 2.0 or higher, the latest version of Riak KV is always recommended. What is goriak? goriak is a wrapp

Nov 22, 2022
Mongo Go Models (mgm) is a fast and simple MongoDB ODM for Go (based on official Mongo Go Driver)
Mongo Go Models (mgm) is a fast and simple MongoDB ODM for Go (based on official Mongo Go Driver)

Mongo Go Models Important Note: We changed package name from github.com/Kamva/mgm/v3(uppercase Kamva) to github.com/kamva/mgm/v3(lowercase kamva) in v

Jan 2, 2023
The MongoDB driver for Go

The MongoDB driver for Go This fork has had a few improvements by ourselves as well as several PR's merged from the original mgo repo that are current

Jan 8, 2023
The Go driver for MongoDB
The Go driver for MongoDB

MongoDB Go Driver The MongoDB supported driver for Go. Requirements Installation Usage Bugs / Feature Reporting Testing / Development Continuous Integ

Dec 31, 2022