|
Public Class DbHelper
Public Shared dic As New Dictionary(Of Object, Object)
' ******************************************************
' ディクショナリに文字列を値として追加する
' ******************************************************
Public Shared Sub AddValue(ByVal str As String)
dic.Add(dic.Count, str)
End Sub
' ******************************************************
' テキストファイルより文字列を取得
' ******************************************************
Public Shared Function GetSql(ByVal path As String) _
As String
Dim hReader As New System.IO.StreamReader(path, System.Text.Encoding.Default)
Dim myQuery As String = hReader.ReadToEnd()
hReader.Close()
myQuery = System.Text.RegularExpressions.Regex.Replace( _
myQuery, "([^\n-]*)--[^\n]*\n", "$1" & vbLf _
)
Return myQuery
End Function
' ******************************************************
' テキストファイルより文字列を取得( 配列置き換え )
' 第二引数が Nothing の場合は、置き換えをせずにそのまま
' 第二引数は文字列の配列
' ******************************************************
Public Shared Function GetSql(ByVal path As String, ByVal rpl As String()) _
As String
Dim hReader As New System.IO.StreamReader(path, System.Text.Encoding.Default)
Dim myQuery As String = hReader.ReadToEnd()
hReader.Close()
myQuery = System.Text.RegularExpressions.Regex.Replace( _
myQuery, "([^\n-]*)--[^\n]*\n", "$1" & vbLf _
)
If rpl Is Nothing Then
Return myQuery
Else
Return String.Format(myQuery, rpl)
End If
End Function
' ******************************************************
' テキストファイルより文字列を取得( 配列置き換え )
' 第二引数が Nothing の場合は、置き換えをせずにそのまま
' 第二引数は Dictionary
' ******************************************************
Public Shared Function GetSqlDic(ByVal path As String, _
ByVal rpl As Dictionary(Of Object, Object)) As String
Dim hReader As New System.IO.StreamReader(path, System.Text.Encoding.Default)
Dim myQuery As String = hReader.ReadToEnd()
hReader.Close()
myQuery = System.Text.RegularExpressions.Regex.Replace( _
myQuery, "([^\n-]*)--[^\n]*\n", "$1" & vbLf _
)
If rpl Is Nothing Then
Return myQuery
Else
Dim rplString As String() = New String(rpl.Count - 1) {}
Dim valueColl As _
Dictionary(Of Object, Object).ValueCollection = _
rpl.Values
Dim cnt As Integer = 0
For Each str As Object In valueColl
rplString(cnt) = str.ToString()
cnt += 1
Next
Return String.Format(myQuery, rplString)
End If
End Function
' ******************************************************
' テキストファイルより文字列を取得( 配列置き換え )
' 置き換えは、クラス変数(Dictionary)より行う
' ******************************************************
Public Shared Function GetSqlDic(ByVal path As String) As String
Dim hReader As New System.IO.StreamReader(path, System.Text.Encoding.Default)
Dim myQuery As String = hReader.ReadToEnd()
hReader.Close()
myQuery = System.Text.RegularExpressions.Regex.Replace( _
myQuery, "([^\n-]*)--[^\n]*\n", "$1" & vbLf _
)
Dim rplString As String() = New String(dic.Count - 1) {}
Dim valueColl As _
Dictionary(Of Object, Object).ValueCollection = _
dic.Values
Dim cnt As Integer = 0
For Each str As Object In valueColl
rplString(cnt) = str.ToString()
cnt += 1
Next
Return String.Format(myQuery, rplString)
End Function
End Class
| |