Open ymofen opened 2 years ago
What is your:
sql.open("adodb", "Provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=dss_test;User ID=sa;Password=xxxx")
What server? sqlserver?
sqlserver is mssql2014 or mssql2018 r2
/ sql proc /
ALTER procedure [dbo].[dss_list_proc]
@instr varchar(64)='001',
@instr2 varchar(64)='002'
as
begin
/ unexception
if object_id('tempdb..#temp') is not null drop table #temp
select 1 as A into #temp
select from #temp
*/
/* will be ok */
select 1 as A
end
golang code func TestADODB(t *testing.T) {
str := "Provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=dss_test;User ID=sa;Password=sa@2014"
db, err := sql.Open("adodb", str)
if err != nil{
fmt.Println(err)
return;
}
vsql := "exec dss_list_proc '001', '002'";
rows, e1 := db.Query(vsql)
if e1 != nil{
fmt.Println(e1);
return;
}
if rows.Next(){
fmt.Println("OK")
}
}
I code direct with go-ole, got the same results....
func TestADORecordSet(t *testing.T) {
ole.CoInitialize(0)
defer ole.CoUninitialize()
unknown, err := oleutil.CreateObject("ADODB.Connection")
if err != nil {
fmt.Println(err);
return;
}
db, err := unknown.QueryInterface(ole.IID_IDispatch)
unknown.Release()
if err != nil {
fmt.Println(err);
return;
}
rc, err := oleutil.CallMethod(db, "Open", "Provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=dss_test;User ID=sa;Password=sa@2014")
if err != nil {
fmt.Println(err);
return;
}
rc.Clear()
{
unknown, err := oleutil.CreateObject("ADODB.recordset")
if err != nil {
fmt.Println(err);
return;
}
rs, err := unknown.QueryInterface(ole.IID_IDispatch)
lvsql := "exec dss_list_proc '001', '002'"
_, err1 := oleutil.CallMethod(rs, "Open", lvsql, db);
if err1 != nil {
fmt.Println(err1);
return;
}else{
unknown, err := oleutil.GetProperty(rs, "Fields")
if err != nil {
fmt.Println(err);
return;
}
fields := unknown.ToIDispatch()
defer fields.Release()
rv, err := oleutil.GetProperty(fields, "Count")
if err != nil {
fmt.Println(err);
return;
}
nc := int(rv.Val)
rv.Clear()
cols := make([]string, nc)
for i := 0; i < nc; i++ {
var varval ole.VARIANT
varval.VT = ole.VT_I4
varval.Val = int64(i)
val, err := oleutil.CallMethod(fields, "Item", &varval)
if err != nil {
fmt.Println(err);
return;
}
item := val.ToIDispatch()
val.Clear()
name, err := oleutil.GetProperty(item, "Name")
if err != nil {
item.Release()
fmt.Println(err);
return;
}
cols[i] = name.ToString()
name.Clear()
item.Release()
}
fmt.Println(cols)
}
}
}
create proc xxx1 as insert table_1 select 1 select * from table_1
golang