Open ooodjc opened 3 weeks ago
Could you please show me your code?
`package main
import ( "database/sql" "fmt" "log" "os"
_ "github.com/mattn/go-adodb"
)
func main() { url := "Provider=SQLOLEDB;Initial Catalog=issyytv3;Data Source=192.168.0.116,1433;user id=sa;password=" issyytv3, err := sql.Open("adodb", url)
if err != nil {
log.Fatal(err)
return
}
defer issyytv3.Close()
args := os.Args
value := "%" + args[1] + "%"
sql := `SELECT item_no, item_name, item_clsno, price, sale_price, vip_price FROM t_bd_item_info WHERE item_no like ? or item_name like ?`
rows, err := issyytv3.Query(sql, value, value)
if err != nil {
fmt.Println(err)
return
}
defer rows.Close()
for rows.Next() {
var itemNo, itemName, itemClsno string
var price, salePrice, vipPrice float64
err := rows.Scan(&itemNo, &itemName, &itemClsno, &price, &salePrice, &vipPrice)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(itemNo, itemName, itemClsno, price, salePrice, vipPrice)
}
} `
When querying data from a SQL Server 2000 database, when querying through db.Query(sql, id, name), there will be 16 extra spaces in the first parameter, resulting in failure to query the specified data.
//This is shown in the SQL Server Profiler. declare @P1 int set @P1=1 exec sp_prepexec @P1 output, N'@P1 char(20),@P2 varchar(40)', N'SELECT item_no, item_name, item_clsno, price, sale_price, vip_price FROM t_bd_item_info WHERE item_no like @P1 or item_name like @P2', '%090870% ', '%090870%' select @P1