Interesting, I was able to get Blackholyman's method to work fine as well using Gio's method with the ComVar functions.
I was also able to edit AHK DBA as well
By Creating: "ComVar.ahk"
Code: Select all
/*
Functions to handle COM objects ByRef
source: https://autohotkey.com/docs/commands/ComObjActive.htm#ByRefEx
*/
ComVar(Type=0xC)
{
static base := { __Get: "ComVarGet", __Set: "ComVarSet", __Delete: "ComVarDel" }
; Create an array of 1 VARIANT. This method allows built-in code to take
; care of all conversions between VARIANT and AutoHotkey internal types.
arr := ComObjArray(Type, 1)
; Lock the array and retrieve a pointer to the VARIANT.
DllCall("oleaut32\SafeArrayAccessData", "ptr", ComObjValue(arr), "ptr*", arr_data)
; Store the array and an object which can be used to pass the VARIANT ByRef.
return { ref: ComObject(0x4000|Type, arr_data), _: arr, base: base }
}
ComVarGet(cv, p*) { ; Called when script accesses an unknown field.
if p.MaxIndex() = "" ; No name/parameters, i.e. cv[]
return cv._[0]
}
ComVarSet(cv, v, p*) { ; Called when script sets an unknown field.
if p.MaxIndex() = "" ; No name/parameters, i.e. cv[]:=v
return cv._[0] := v
}
ComVarDel(cv) { ; Called when the object is being freed.
; This must be done to allow the internal array to be freed.
DllCall("oleaut32\SafeArrayUnaccessData", "ptr", ComObjValue(cv._))
}
Modifying "DBA.ahk" to include the following lines:
Code: Select all
; functions to properly return values from COM objects
#Include <ComVar>
and finally, editing "DatabaseADO.ahk" Query function to:
Code: Select all
/*
Querys the DB and returns a ResultTable or true/false
*/
Query(sql){
ret := false
if(this.IsValid())
{
;Execute( commandtext,ra,options)
;affectedRows := 0
/*
Note: ByRef is not directly supported in functions called by COM clients, or when calling COM methods.
Instead, the script receives or must pass a wrapper object containing the VarType and address of the value.
https://autohotkey.com/docs/Functions.htm#ByRef
https://autohotkey.com/docs/commands/ComObjActive.htm#ByRefEx
https://autohotkey.com/boards/viewtopic.php?p=67482#p67482
*/
affectedRows := ComVar() ; create wrapper object
affectedRows[] := "Warning: Could not retrieve number of affected rows!" ; default, overwritten if call returns values.
rs := this._connection.Execute(sql, affectedRows.ref)
if(IsObject(rs) && rs.State != gDBA_ADO.ObjectStateEnum.adStateClosed)
{
ret := this.FetchADORecordSet(rs)
rs.Close()
}else{
;ret := affectedRows
ret := affectedRows[] ; [] used to dereference value.
}
}
return ret
}
That seems to work perfectly now.