mattn / go-adodb

Microsoft ActiveX Object DataBase driver for go that using exp/sql
http://mattn.kaoriya.net/
MIT License
142 stars 36 forks source link

Querying Windows search DB fails with "Current provider does not support commands with parameters." #45

Open dpajkovic opened 5 years ago

dpajkovic commented 5 years ago

Hello, I'm trying to port some of my PowerShell code to Go, and I'm stumbling here when porting the interface to the search index on Windows. With PowerShell it's simply case of connecting System.Data.OleDb.OleDbCommand to provider "provider=search.collatordso;extended properties=’application=windows’;" and then running a simple SQL command like "SELECT Top 5 System.ItemPathDisplay FROM SYSTEMINDEX" (can get more complex with WHERE clauses).

I made a simple script:

package main

import (
    "database/sql"
    "fmt"
    "log"
    _ "github.com/mattn/go-adodb"
)

var provider = `provider=search.collatordso;extended properties="application=windows";`

func main() {
    fmt.Println(sql.Drivers())
    db, err := sql.Open("adodb", provider)
    if err != nil {
        log.Fatalln("open", err)
    }
    defer db.Close()

    fmt.Println("Pong:", db.Ping())
    fmt.Println("Stats:", db.Stats())

    rows, err := db.Query("SELECT Top 5 System.ItemPathDisplay FROM SYSTEMINDEX")
    if err != nil {
        log.Fatalln("select", err)
    }
    defer rows.Close()
}

and when I run it I get:

[adodb]
Pong: <nil>
Stats: {0 1 0 1 0 0s 1 0}
2019/06/03 17:09:48 select Exception occurred. (Current provider does not support commands with parameters.)
exit status 1

Please help with any suggestions, I'm at my wits' end.

mattn commented 5 years ago

If the query is replaced to SELECT System.ItemPathDisplay FROM SYSTEMINDEX, does it works?

dpajkovic commented 5 years ago

No, unfortunately the error is still the same.

mattn commented 5 years ago

Could you please try last change? https://github.com/mattn/go-adodb/commit/010be82f64e9661e64a4c0f2469d40255e19933c

botastic commented 4 years ago

I had the same issue, because I was using the latest version (Tag 0.0.1) without. The latest commit 5e535a3 does work though.

Would it be possible to add a new release version, in order be able to use the version in the go.mod file rather than the commit hash?