00001 ' Attribute VB_Name = "DbCommand"
00002 Option Explicit
00003
00004 '! @brief ADODB.Commandのショートカットクラス
00005 '! @require common.vbs
00006
00007 '! @require Configuration.cls
00008 '! @require Logger.cls
00009 '! @require DbAccess.cls
00010 '----------------------------------------------
00011 Class DbCommand
00012 '* ADODB.Commandオブジェクト
00013 Private command
00014
00015 '----------------------------------------------
00016 '* 新しいコマンドの生成(コンストラクタパラメータが使えない苦肉の策)
00017 '----------------------------------------------
00018 Public Sub newCommand(querytype,sql,con)
00019 With command
00020 .CommandType = querytype
00021 .CommandText = sql
00022 Set .ActiveConnection = con
00023 End With
00024 End Sub
00025
00026 '----------------------------------------------
00027 '* パラメータ追加
00028 '* @param pName パラメータ名称
00029 '* @param pType パラメータタイプ
00030 '* @param pIO パラメータIO
00031 '* @param pLength パラメータLength
00032 '* @param pValue パラメータの値
00033 '----------------------------------------------
00034 Public Sub addParameter(pName, pType, pIO, pLength, pValue)
00035 Dim param
00036 Select Case pType
00037 Case adVarChar,adChar,adDecimal '可変長なら長さを指定。
00038 Set param=command.CreateParameter(pName, pType, pIO, pLength)
00039 command.Parameters.Append param
00040 command.Parameters(pName).Value = pValue
00041
00042 Case Else '固定長のデータなら長さを無視する。
00043 Select Case pIO
00044 Case adParamReturnValue 'return value
00045 Set param = command.CreateParameter(pName, adType, adParamReturnValue)
00046 command.Parameters.Append param
00047 Case adParamInput
00048 Set param=command.CreateParameter(pName, pType, pIO)
00049 command.Parameters.Append param
00050 command.Parameters(pName).Value = pValue
00051 Case adParamOutput
00052 Set param=command.CreateParameter(pName, pType, pIO)
00053 command.Parameters.Append param
00054 End Select
00055 End Select
00056 End Sub
00057
00058 '----------------------------------------------
00059 '* @brief パラメータ再設定
00060 '* @param pName パラメータ名称
00061 '* @param pValue パラメータの値
00062 '----------------------------------------------
00063 Public Sub setParameter(pName, pValue)
00064 Dim param
00065 Set param = getParameter(pName)
00066 if(param is nothing) then
00067 end if
00068
00069 param.value = pValue
00070 End Sub
00071 '----------------------------------------------
00072 '* @brief パラメータダンプ
00073 '----------------------------------------------
00074 Public Function d()
00075 On Error Resume Next
00076 Logger.Debug "query = " & command.CommandText
00077 Logger.Debug "parameters..."
00078 dim i
00079 for i = 0 to command.Parameters.Count - 1
00080 Logger.Debug command.Parameters(i).Name & command.Parameters(i).Value
00081 next
00082 End Function
00083
00084 '----------------------------------------------
00085 '* @brief パラメータ取得
00086 '----------------------------------------------
00087 Public Function getParameter(key)
00088 On Error Resume Next
00089 Set getParameter = command.Parameters.Item(key)
00090 If Err.Number <> 0 Then
00091 WScript.echo Err.Description
00092 Set getParameter = Nothing
00093 End If
00094 End Function
00095
00096 '----------------------------------------------
00097 '* @brief Recordsetを返さないコマンド実行
00098 '* @return 影響を受けた行数
00099 '----------------------------------------------
00100 Public Function execute()
00101 Dim result
00102 command.Execute result
00103 execute = result
00104 End Function
00105 '----------------------------------------------
00106 '* @brief Recordsetを返すマンド実行
00107 '* @return コマンド実行結果のRecordset
00108 '----------------------------------------------
00109 Public Function openRecordset()
00110 Dim rs
00111 Set rs = CreateObject("ADODB.Recordset")
00112 rs.open command
00113 Set openRecordSet = rs
00114 End Function
00115
00116 '----------------------------------------------
00117 '* @brief オブジェクト初期化
00118 '----------------------------------------------
00119 Sub Class_Initialize()
00120 Set command = CreateObject("ADODB.Command")
00121 End Sub
00122 '----------------------------------------------
00123 '* @brief オブジェクト破棄
00124 '----------------------------------------------
00125 Sub Class_Terminate()
00126 Set command = Nothing
00127 End Sub
00128 End Class