Mssql.au3的update函数增加多列update功能
本帖最后由 anypac 于 2013-12-5 17:30 编辑由于个人经常使用Mssql,原本的udf里面的update过程只能更新单列数据,现在加入多列更新,分隔符"|",列和值的数量要相等,如果要更新的值含有"|"字符的,请单列更新
;===============================================================================
;
; 函数名称.........: _MSSQL_UpdateRecord
; 描述.............: 在数据库表中修改指定列的数据
; 语法.............: _MSSQL_UpdateRecord($oConnectionObj, $sTable, $sColumn , $sValue, $condition = "")
; 参数(s)..........: $oConnectionObj = Object, returned by _MSSQL_Con
; $sTable = 表名
; $sColumn = 列名,多列更新用"|"作为分隔符
; $sValue = 新值,多列更新用"|"作为分隔符
; $condition = [可选参数] 查询的条件,可指定某值为查询内容 [默认 = "" (不按条件查询)]
; 返回值(s)........: 成功 - 1
; 失败 - 0, sets @error
; |1 - $oConnectionObj is not an object
; |2 - $sTable does not exist
; |3 - $sColumn does not exist
; |4 - $sColumn 和$sValue 数量不匹配
; 作者.............: TheLuBu <LuBu@veytal.com>
;2013-12-05 增加多列更新功能<anypac>
;===============================================================================
Func _MSSQL_UpdateRecord($oConnectionObj, $sTable, $sColumn, $sValue, $condition = "")
Local $tableexist, $columnexist, $str, $quer, $sColumnArr, $sValueArr, $sStr = ""
If StringInStr($sColumn, "|") > 0 Then
If StringInStr($sValue, "|") > 0 Then
$sColumnArr = StringSplit($sColumn, "|")
$sValueArr = StringSplit($sValue, "|")
For$i = 1 To $sColumnArr
$columnexist = _MSSQL_ColumnExist($oConnectionObj, $sTable, $sColumnArr[$i])
If $columnexist = 0 Then Return SetError(3, 0, 0)
Next
If Not @error Then
If $sColumnArr = $sValueArr Then
For $i = 1 To $sColumnArr
$sStr = $sStr & $sColumnArr[$i] & "=" & $sValueArr[$i] & ","
Next
$sStr = StringTrimRight($sStr, 1)
Else
SetError(4, 0, 0)
EndIf
EndIf
Else
SetError(4, 0, 0)
EndIf
Else
$columnexist = _MSSQL_ColumnExist($oConnectionObj, $sTable, $sColumn)
If $columnexist = 0 Then Return SetError(3, 0, 0)
If Not @error Then $sStr = $sColumn & "=" & $sValue
EndIf
If IsObj($oConnectionObj) And Not @error Then
$tableexist = _MSSQL_TableExist($oConnectionObj, $sTable)
If $tableexist = 0 Then Return SetError(2, 0, 0)
If $condition = "" Then
$str = "UPDATE " & $sTable & " SET " & $sStr & ";"
$quer = $oConnectionObj.execute($str)
Else
$str = "UPDATE " & $sTable & " SET " & $sStr & " " & $condition & ";"
$quer = $oConnectionObj.execute($str)
EndIf
Return 1
Else
Return SetError(1, 0, 0)
EndIf
EndFunc ;==>_MSSQL_UpdateRecord 对了,不要替换,本人水平有限,标注了老的,增加上面的代码,如果有错,请提出 好的,标注收藏,以后要用到的。 学习,以后要用到的! 感謝大大分享
页:
[1]