Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
434 lines
17 KiB
VB.net
434 lines
17 KiB
VB.net
#If False Then
|
|
***********************************************************************
|
|
* .netXpert DataAccess Component Version 1.0
|
|
* Written By Funnyfox
|
|
* Last Comment 2001.11.4
|
|
***********************************************************************
|
|
#End If
|
|
|
|
Imports System.Data
|
|
Imports System.Data.SqlClient
|
|
'Imports System.EnterpriseServices ' Serviced Component 를 호출하기 위해 선언된 Namespce
|
|
Imports System.Configuration.ConfigurationSettings 'Config File 정보(AppSettings 값)를 얻기 위해 선언된 Namesapce
|
|
Imports System.Runtime.InteropServices 'Interop Namespace
|
|
|
|
'**********************************************************************************
|
|
' Transaction 지원은 Support
|
|
' COM+ 서비스의 생성문자열을 지원함. Default => " "(space)
|
|
' JIT Activation 지원
|
|
' ClassInterface 는 AutoDual ( COM+ Service 콘솔에서 Interface 를 볼 수 있도록 )
|
|
'**********************************************************************************
|
|
|
|
|
|
Public Class DBAgent
|
|
'Connection Field
|
|
Private m_Connection As SqlConnection
|
|
|
|
'Connection 을 생성하여 Return
|
|
Private Function MakeConnection(ByVal ConnectionString As String) As SqlConnection
|
|
Dim sqlConn As SqlConnection
|
|
|
|
Try
|
|
sqlConn = New SqlConnection(ConnectionString)
|
|
Catch Ex As Exception
|
|
'ErrorUtil.WriteExceptionIntoEventLog(Ex)
|
|
Ex.ToString()
|
|
End Try
|
|
Return sqlConn
|
|
End Function
|
|
|
|
|
|
'Connection String Property
|
|
Property ConnectionString() As String
|
|
Set(ByVal Value As String)
|
|
m_Connection = MakeConnection(Value)
|
|
End Set
|
|
Get
|
|
If m_Connection Is Nothing Then
|
|
Return GetConnection().ConnectionString
|
|
Else
|
|
Return m_Connection.ConnectionString
|
|
End If
|
|
End Get
|
|
End Property
|
|
|
|
|
|
'************************************************************************************
|
|
' Query 구문과 함께, 데이터테이블 명과 데이터를 담을 데이터셋을 파라메터로 넘겨,
|
|
' 데이터셋에 데이터를 채운다
|
|
'************************************************************************************
|
|
|
|
Public Overloads Function FillDataSet(ByVal strQuery As String, ByVal strAlias As String, ByRef dsDataSet As DataSet) As DataSet
|
|
Dim sqlAdapter As SqlDataAdapter = New SqlDataAdapter(strQuery, GetConnection())
|
|
Try
|
|
sqlAdapter.Fill(dsDataSet, strAlias)
|
|
Catch Ex As Exception
|
|
ErrorUtil.WriteExceptionIntoEventLog(Ex)
|
|
End Try
|
|
|
|
Return dsDataSet
|
|
End Function
|
|
|
|
'************************************************************************************
|
|
' Query 구문과 함께, 데이터테이블명을 넘기면 내부적으로 데이터셋을 생성(Untyped) 되돌린다.
|
|
'************************************************************************************
|
|
Public Overloads Function FillDataSet(ByVal strQuery As String, ByVal strAlias As String) As DataSet
|
|
Dim sqlAdapter As SqlDataAdapter = New SqlDataAdapter(strQuery, GetConnection())
|
|
Dim oDs As New DataSet()
|
|
Try
|
|
sqlAdapter.Fill(oDs, strAlias)
|
|
Catch Ex As Exception
|
|
ErrorUtil.WriteExceptionIntoEventLog(Ex)
|
|
End Try
|
|
|
|
Return oDs
|
|
End Function
|
|
|
|
'**************************************************************************************************
|
|
' SP이름과 데이터셋 그리고 데이터를 채울 데이터테이블명과 파라메터들을 넘기면(clsParam객체),
|
|
' 이에 해당하는 데이터를 데이터셋에 채워 되돌린다.
|
|
'**************************************************************************************************
|
|
Public Overloads Function FillDataSet(ByVal SPName As String, ByRef dsDataSet As DataSet, ByVal strAlias As String, ByVal ParamArray objParams() As clsParam) As DataSet
|
|
Dim sqlComm As SqlCommand = New SqlCommand(SPName, GetConnection())
|
|
Dim oEachParams As clsParam
|
|
Dim SqlAdapter As SqlDataAdapter = New SqlDataAdapter()
|
|
|
|
Try
|
|
sqlComm.CommandType = CommandType.StoredProcedure
|
|
sqlComm.CommandText = SPName
|
|
|
|
For Each oEachParams In objParams
|
|
sqlComm.Parameters.Add(MakeParameter(oEachParams))
|
|
Next
|
|
|
|
SqlAdapter.SelectCommand = sqlComm
|
|
SqlAdapter.Fill(dsDataSet, strAlias)
|
|
|
|
Catch Ex As Exception
|
|
ErrorUtil.WriteExceptionIntoEventLog(Ex)
|
|
End Try
|
|
|
|
Return dsDataSet
|
|
End Function
|
|
|
|
'**************************************************************************************************
|
|
' SP이름과 데이터를 채울 데이터테이블명과 파라메터들을 넘기면(clsParam객체),
|
|
' 이에 해당하는 데이터를 데이터셋을 새로 생성하여 이 곳에 채워 데이터셋을 되돌린다.
|
|
'**************************************************************************************************
|
|
Public Overloads Function FillDataSet(ByVal SPName As String, ByVal strAlias As String, ByVal ParamArray objParams() As clsParam) As DataSet
|
|
Dim sqlComm As SqlCommand = New SqlCommand(SPName, GetConnection())
|
|
Dim oEachParams As clsParam
|
|
Dim SqlAdapter As SqlDataAdapter = New SqlDataAdapter()
|
|
Dim oDs As New DataSet()
|
|
|
|
Try
|
|
sqlComm.CommandType = CommandType.StoredProcedure
|
|
sqlComm.CommandText = SPName
|
|
|
|
For Each oEachParams In objParams
|
|
sqlComm.Parameters.Add(MakeParameter(oEachParams))
|
|
Next
|
|
|
|
SqlAdapter.SelectCommand = sqlComm
|
|
SqlAdapter.Fill(oDs, strAlias)
|
|
|
|
Catch Ex As Exception
|
|
ErrorUtil.WriteExceptionIntoEventLog(Ex)
|
|
End Try
|
|
Return oDs
|
|
End Function
|
|
|
|
'**************************************************************************************************
|
|
' Insert / update /delete Query 문이 담긴 SP 를 호출할때 사용하며, SP 명과 요구되는 파라메터들(clsParam 객체)
|
|
' 을 파라메터로 넘기면 SP가 호출되며 이에 따른 실행된 레코드 갯수를 되돌린다.
|
|
'**************************************************************************************************
|
|
Public Overloads Function ExecuteSpNonQuery(ByVal SPName As String, ByVal ParamArray objParams() As clsParam) As Integer
|
|
Dim sqlComm As SqlCommand = New SqlCommand(SPName, GetConnection())
|
|
Dim oEachParams As clsParam
|
|
Dim intRet As Integer
|
|
Try
|
|
sqlComm.CommandType = CommandType.StoredProcedure
|
|
sqlComm.CommandText = SPName
|
|
|
|
For Each oEachParams In objParams
|
|
sqlComm.Parameters.Add(MakeParameter(oEachParams))
|
|
Next
|
|
|
|
sqlComm.Connection.Open()
|
|
intRet = sqlComm.ExecuteNonQuery()
|
|
If Not (sqlComm.Connection.State = ConnectionState.Closed) Then sqlComm.Connection.Close()
|
|
Return intRet
|
|
Catch Ex As Exception
|
|
ErrorUtil.WriteExceptionIntoEventLog(Ex)
|
|
Return 0
|
|
End Try
|
|
End Function
|
|
|
|
|
|
'**************************************************************************************************
|
|
' Insert / update /delete Query 문을 호출할때 사용하며 이에 따른 실행된 레코드 갯수를 되돌린다.
|
|
'**************************************************************************************************
|
|
Public Overloads Function ExecuteNonQuery(ByVal strQuery As String) As Integer
|
|
Dim sqlComm As SqlCommand = New SqlCommand(strQuery, GetConnection())
|
|
Dim oEachParams As clsParam
|
|
Dim intRet As Integer
|
|
Try
|
|
sqlComm.CommandType = CommandType.Text
|
|
sqlComm.CommandText = strQuery
|
|
sqlComm.Connection.Open()
|
|
intRet = sqlComm.ExecuteNonQuery()
|
|
If Not (sqlComm.Connection.State = ConnectionState.Closed) Then sqlComm.Connection.Close()
|
|
Return intRet
|
|
Catch Ex As Exception
|
|
ErrorUtil.WriteExceptionIntoEventLog(Ex)
|
|
Return 0
|
|
End Try
|
|
End Function
|
|
|
|
|
|
|
|
'************************************************************************************
|
|
' SP 명과 clsParam Object를 통해 생성된 파라메터 객체를 통하여 쿼리를 실행,
|
|
' DataReader 를 되돌린다.
|
|
'************************************************************************************
|
|
Public Overloads Function ReturnDataReader(ByVal SPName As String, ByVal ParamArray objParams() As clsParam) As SqlDataReader
|
|
Dim sqlComm As SqlCommand = New SqlCommand(SPName, GetConnection())
|
|
Dim oEachParams As clsParam
|
|
Dim sqlReader As SqlDataReader
|
|
Try
|
|
sqlComm.CommandType = CommandType.StoredProcedure
|
|
sqlComm.CommandText = SPName
|
|
|
|
For Each oEachParams In objParams
|
|
sqlComm.Parameters.Add(MakeParameter(oEachParams))
|
|
Next
|
|
|
|
sqlComm.Connection.Open()
|
|
'DataReader 객체만 close 하면 이에 해당하는 Connection 은 자동으로 닫힌다
|
|
sqlReader = sqlComm.ExecuteReader(CommandBehavior.CloseConnection)
|
|
Catch Ex As Exception
|
|
ErrorUtil.WriteExceptionIntoEventLog(Ex)
|
|
End Try
|
|
Return sqlReader
|
|
End Function
|
|
|
|
'************************************************************************************
|
|
' Sql Query 구문을 실행하여 그 결과를 DataReader 객체를 통해 되돌린다.
|
|
'************************************************************************************
|
|
Public Overloads Function ReturnDataReader(ByVal strQuery As String) As SqlDataReader
|
|
|
|
Dim sqlComm As SqlCommand = New SqlCommand()
|
|
Dim sqlReader As SqlDataReader
|
|
Try
|
|
sqlComm.Connection = GetConnection()
|
|
sqlComm.CommandType = CommandType.Text
|
|
sqlComm.CommandText = strQuery
|
|
|
|
sqlComm.Connection.Open()
|
|
'DataReader 객체만 close 하면 이에 해당하는 Connection 은 자동으로 닫힌다
|
|
sqlReader = sqlComm.ExecuteReader(CommandBehavior.CloseConnection)
|
|
Catch Ex As Exception
|
|
ErrorUtil.WriteExceptionIntoEventLog(Ex)
|
|
End Try
|
|
Return sqlReader
|
|
End Function
|
|
|
|
'************************************************************************************
|
|
' SP 명과 clsParam Object를 통해 생성된 파라메터 객체를 통하여 SP를 실행,
|
|
' 파라메터 컬랙션을 되돌린다(Return Value).
|
|
'************************************************************************************
|
|
Public Function ReturnParameter(ByVal SPName As String, ByVal ParamArray objParams() As clsParam) As SqlParameterCollection
|
|
|
|
Dim sqlComm As SqlCommand = New SqlCommand(SPName, GetConnection())
|
|
Dim oEachParams As clsParam
|
|
Try
|
|
sqlComm.CommandType = CommandType.StoredProcedure
|
|
sqlComm.CommandText = SPName
|
|
If Not (objParams Is Nothing) Then
|
|
For Each oEachParams In objParams
|
|
sqlComm.Parameters.Add(MakeParameter(oEachParams))
|
|
Next
|
|
End If
|
|
|
|
sqlComm.Connection.Open()
|
|
sqlComm.ExecuteNonQuery()
|
|
If Not (sqlComm.Connection.State = ConnectionState.Closed) Then sqlComm.Connection.Close()
|
|
Catch Ex As Exception
|
|
ErrorUtil.WriteExceptionIntoEventLog(Ex)
|
|
End Try
|
|
Return sqlComm.Parameters
|
|
End Function
|
|
|
|
|
|
'************************************************************************************
|
|
' SP 명과 clsParam Object를 통해 생성된 파라메터 객체를 통하여 쿼리를 실행,
|
|
' Scalar 값을 되돌린다.
|
|
'************************************************************************************
|
|
Public Overloads Function ReturnScalarValue(ByVal SPName As String, ByVal ParamArray objParams() As clsParam) As Object
|
|
Dim sqlComm As SqlCommand = New SqlCommand(SPName, GetConnection())
|
|
Dim oEachParams As clsParam
|
|
Dim objRet As Object
|
|
Try
|
|
sqlComm.CommandType = CommandType.StoredProcedure
|
|
sqlComm.CommandText = SPName
|
|
If Not (objParams Is Nothing) Then
|
|
For Each oEachParams In objParams
|
|
sqlComm.Parameters.Add(MakeParameter(oEachParams))
|
|
Next
|
|
End If
|
|
sqlComm.Connection.Open()
|
|
objRet = sqlComm.ExecuteScalar()
|
|
If Not (sqlComm.Connection.State = ConnectionState.Closed) Then sqlComm.Connection.Close()
|
|
Catch Ex As Exception
|
|
ErrorUtil.WriteExceptionIntoEventLog(Ex)
|
|
End Try
|
|
Return objRet
|
|
End Function
|
|
|
|
|
|
Public Overloads Function ReturnScalarValue(ByVal strQuery As String) As Object
|
|
'************************************************************************************
|
|
' Query 구문을 통하여 쿼리를 실행,Scalar 값을 되돌린다.
|
|
'************************************************************************************
|
|
Dim sqlComm As SqlCommand = New SqlCommand(strQuery, GetConnection())
|
|
Dim objRet As Object
|
|
Try
|
|
sqlComm.CommandType = CommandType.Text
|
|
sqlComm.Connection.Open()
|
|
objRet = sqlComm.ExecuteScalar()
|
|
If Not (sqlComm.Connection.State = ConnectionState.Closed) Then sqlComm.Connection.Close()
|
|
Catch Ex As Exception
|
|
ErrorUtil.WriteExceptionIntoEventLog(Ex)
|
|
End Try
|
|
Return objRet
|
|
End Function
|
|
|
|
'Connection 객체를 되돌림, m_Connection 이 설정되어 있지 않으면 내부적으로 m_Connection에 Connection 객체를
|
|
'생성하여 Assign.
|
|
Private Function GetConnection() As SqlConnection
|
|
If m_Connection Is Nothing Then
|
|
m_Connection = MakeConnection(System.Configuration.ConfigurationSettings.AppSettings("ConnectionString"))
|
|
End If
|
|
Return m_Connection
|
|
End Function
|
|
|
|
'clsParam 객체를 통하여 들어온 파라메터 관련 정보를 토대로 하여 SqlParameter 객체를 생성한다.
|
|
Private Function MakeParameter(ByVal oParams As clsParam) As SqlParameter
|
|
Dim MakedParameter As SqlParameter = New SqlParameter()
|
|
With MakedParameter
|
|
.ParameterName = oParams.ParamName
|
|
.SqlDbType = oParams.ParamType
|
|
.Size = oParams.ParamSize
|
|
.Value = oParams.ParamValue
|
|
.Direction = oParams.ParamDirection
|
|
.Precision = oParams.ParamPrecision
|
|
.Scale = oParams.ParamScale
|
|
End With
|
|
Return MakedParameter
|
|
End Function
|
|
End Class
|
|
|
|
|
|
'***********************************************************
|
|
' SqlCommand 의 Parameter 객체 정보를 담아내기 위한 클래스
|
|
'***********************************************************
|
|
Public Class clsParam
|
|
Private m_ParamName As String '파라메터 명
|
|
Private m_ParamType As SqlDbType '파라메터 형타입
|
|
Private m_ParamSize As Integer '파라메터 사이즈
|
|
Private m_ParamValue As Object '파라메터 값
|
|
Private m_ParamDirection As ParameterDirection ' 파라메터의 종류(input / output)
|
|
Private m_ParamPrecision As Byte 'Precision
|
|
Private m_ParamScale As Byte 'Scale
|
|
|
|
ReadOnly Property ParamName() As String
|
|
Get
|
|
Return m_ParamName
|
|
End Get
|
|
End Property
|
|
|
|
ReadOnly Property ParamType() As SqlDbType
|
|
Get
|
|
Return m_ParamType
|
|
End Get
|
|
End Property
|
|
|
|
ReadOnly Property ParamSize() As Integer
|
|
Get
|
|
Return m_ParamSize
|
|
End Get
|
|
End Property
|
|
|
|
ReadOnly Property ParamValue() As Object
|
|
Get
|
|
Return m_ParamValue
|
|
End Get
|
|
End Property
|
|
|
|
ReadOnly Property ParamDirection() As ParameterDirection
|
|
Get
|
|
Return m_ParamDirection
|
|
End Get
|
|
End Property
|
|
|
|
ReadOnly Property ParamScale() As Byte
|
|
Get
|
|
Return m_ParamPrecision
|
|
End Get
|
|
End Property
|
|
|
|
ReadOnly Property ParamPrecision() As Byte
|
|
Get
|
|
Return m_ParamScale
|
|
End Get
|
|
End Property
|
|
|
|
|
|
'Scale 과 Precision 정보가 필요없을때 사용
|
|
Public Sub New(ByVal ParamName As String, ByVal ParamType As SqlDbType, ByVal ParamSize As Integer, _
|
|
ByVal ParamValue As Object, ByVal ParamDirection As ParameterDirection)
|
|
Me.m_ParamName = ParamName
|
|
Me.m_ParamType = ParamType
|
|
Me.m_ParamSize = ParamSize
|
|
Me.m_ParamValue = ParamValue
|
|
Me.m_ParamDirection = ParamDirection
|
|
Me.m_ParamScale = 0
|
|
Me.m_ParamPrecision = 0
|
|
End Sub
|
|
|
|
'Scale 과 Presicion 정보가 필요없으며, 모든 파라메터가 Input 타입일때 사용
|
|
Public Sub New(ByVal ParamName As String, ByVal ParamType As SqlDbType, ByVal ParamSize As Integer, _
|
|
ByVal ParamValue As Object)
|
|
Me.m_ParamName = ParamName
|
|
Me.m_ParamType = ParamType
|
|
Me.m_ParamSize = ParamSize
|
|
Me.m_ParamValue = ParamValue
|
|
Me.m_ParamDirection = ParameterDirection.Input
|
|
Me.m_ParamScale = 0
|
|
Me.m_ParamPrecision = 0
|
|
End Sub
|
|
|
|
'모든 파라메터 정보를 입력해야 할 경우
|
|
Public Sub New(ByVal ParamName As String, ByVal ParamType As SqlDbType, ByVal ParamSize As Integer, _
|
|
ByVal ParamValue As Object, ByVal ParamScale As Byte, ByVal ParamPrecision As Byte)
|
|
Me.m_ParamName = ParamName
|
|
Me.m_ParamType = ParamType
|
|
Me.m_ParamSize = ParamSize
|
|
Me.m_ParamValue = ParamValue
|
|
Me.m_ParamDirection = ParameterDirection.Input
|
|
Me.m_ParamScale = ParamScale
|
|
Me.m_ParamPrecision = ParamPrecision
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
|
|
End Class
|
|
|
|
|
|
|
|
|
|
|
|
|