OracleUDF
来源:互联网 发布:网页编程教程 编辑:程序博客网 时间:2024/06/05 03:45
Dim $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
;===============================================================================
; Function: _OpenOracle
; Description: 返回一个Oracle的链接.
; Syntax: _OpenOracle($server="",$UserID="",$Password="")
; Parameter(s): $server:一个Oracle的链接
; $UserID:用户名称
; $Password:密码
; Return Value(s): 成功 : 返回一个供_Oracle函数使用的链接名称
; 失败:返回-1并设置 @error on errors:
;UDF作者:35888894
;===============================================================================
Func _OpenOracle($server="",$UserID="",$Password="");连接名,用户名,密码
$connection = "DRIVER={Microsoft ODBC for Oracle};SERVER=" & $server & ";User Id=" & $UserID & ";Password=" & $Password & ";"
If $server<>"" And $UserID<>"" And $Password<>"" Then
Return $connection
Else
Return -1
EndIf
EndFunc
;===============================================================================
; Function: _Oracle
; Description: 执行SQL语句并返回一个值或者一个数组
; Syntax: _Oracle($connection,$adoSql,$LW_Return=False)
; Parameter(s): $connection:_OpenOracle函数返回的一个Oracle链接
; $adoSql:要执行的SQL语句
; $LW_Return:当此值为false的时候是执行非Select语句,返回值为1,当此值为非false的时候
; 返回值是一个二维数组
; Return Value(s): 成功 : 当 $LW_Return为非False的时候返回一个二维数组,在数组[0][0]中保存查找表字段的个数
; 数组[0][x]中依次保存每个字段 数组[1][0]中保存查找出的数据的条数
; 数组[x][x]中依次保存查询的结果
; 失败:返回-1并设置 @error on errors:
;UDF作者:35888894
;===============================================================================
Func _Oracle($connection,$adoSql,$LW_Return=False);链接名称,SQL语句,是否有返回值
Local $LW_RES[2][2],$LW_ls=0
$adoSql=StringReplace($adoSql,";","")
$adoCon = ObjCreate( "ADODB.Connection" )
With $adoCon
.connectionString = ($connection)
.Open
EndWith
$adoRs = ObjCreate ("ADODB.Recordset")
$adoRs.CursorType = 2
$adoRs.LockType = 3
$adoRs.Open($adoSql, $adoCon)
If $LW_Return=False Then Return 1
With $adoRs
$LW_RES[0][0]=.Fields.Count
If $LW_ls=0 And .Fields.Count+1>2 Then
ReDim $LW_RES[2][.Fields.Count+1]
$LW_ls=1
EndIf
For $i = 0 To .Fields.Count - 1
$LW_RES[0][$i+1]=.Fields( $i ).Name
Next
If .RecordCount Then
$count=1
While Not .EOF
$count=$count+1
ReDim $LW_RES[$count][$LW_RES[0][0]+1]
For $i = 0 To .Fields.Count - 1
$LW_RES[$count-1][$i+1]=.Fields( $i ).Value
Next
.MoveNext
WEnd
$LW_RES[1][0]=$count-1
EndIf
EndWith
Return $LW_RES
EndFunc
Func MyErrFunc()
$HexNumber=hex($oMyError.number,8)
Msgbox(0,"Oracle Report","We intercepted a COM Error !" & @CRLF & @CRLF & _
"err.description is: " & @TAB & $oMyError.description & @CRLF & _
"err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
"err.number is: " & @TAB & $HexNumber & @CRLF & _
"err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
"err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
"err.source is: " & @TAB & $oMyError.source & @CRLF & _
"err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
"err.helpcontext is: " & @TAB & $oMyError.helpcontext _
)
Endfunc