'----******************** tconnstring *****************************----
' Database connection string structure body
Class tconnstring
Public Dbname,dbpath,dbserver,dbuser,dbpass,dbtype
End Class
'----******************** tconnstring *****************************----
'----********************* tdboperate *****************************----
' Common Database Operations class
Class tdboperate
Private cls_oconn,cls_ors ' class proprietary Connection object, Recordset object
Private cls_serrinfo,cls_sconn,cls_ssql,cls_surl,cls_sformaction
Private cls_ipagesize ' page
Private Cls_ltotalpage,cls_ltotalrecord,cls_lpageno
' Class initialization
Private Sub Class_Initialize ()
End Sub
'*****************************************
' Type: Attribute
' Purpose: To create a database connection based on the obtained connection String
' Input: A_sconn: Data type string
' Return: None
'*****************************************
Public Property Let Setconn (A_sconn)
Dim Sobjtype
Sobjtype = LCase (TypeName (A_sconn))
If sobjtype <> "string" Then
Cls_serrinfo = Cls_serrinfo & "<li>setconn: illegal string parameters </li>" & Chr (10)
Exit Property
End If
Set Cls_oconn = CreateObject ("Adodb.connection")
On Error Resume Next
Cls_oconn.open A_sconn
If ERR Then
Err.Clear
Set Cls_oconn = Nothing
On Error Goto 0
Cls_serrinfo = cls_serrinfo & <li> database connection error </li> & CHR (10)
End If
On Error Goto 0
End Property
'*****************************************
' Type: Attribute
' Purpose: To create a database connection based on the acquired connection object
' Input: A_oconn: Data type string
' Return: None
'*****************************************
Public Property Set Setconn (A_oconn)
Dim Sobjtype,sconn
Dim Oconnstr
Sobjtype = LCase (TypeName (A_oconn))
Select Case Sobjtype
Case "Connection"
' Set the Connection object
Set Cls_oconn = A_oconn
Case "Tconnstring"
sconn = ""
Set oconnstr = A_oconn
Select Case (Oconnstr.dbtype)
Case Gbl_idb_access
sconn = "Provider = micorsoft.jet.oledb.4.0; User ID = "& Oconnstr.dbuser &"; Password = "& Replace (Oconnstr.dbpass, Chr (0)," ") &" Initial Catalog = "& Oconnstr.dbname &"; Data Source = "& Sqllocalname &";
Case Gbl_idb_mssql
sconn = "Provider = SQLOLEDB; User ID = "& Oconnstr.dbuser &"; Password = "& Replace (Oconnstr.dbpass, Chr (0)," ") &" Initial Catalog = "& Oconnstr.dbname &"; Data Source = "& Oconnstr.dbserver &";
End Select
If sconn = "" Then
Cls_serrinfo = cls_serrinfo & <li> Database Connection object error, unable to create connection object </li> "& Chr (10)
Exit Property
End If
' Sets the connection connection string value for the ConnStr property to return
Cls_sconn = sconn
Set Cls_oconn = CreateObject ("Adodb.connection")
On Error Resume Next
Cls_oconn.open sconn
If ERR Then
Err.Clear
Set Cls_oconn = Nothing
Cls_serrinfo = cls_serrinfo & <li> database connection error </li> & CHR (10)
End If
On Error Goto 0
Case Else
Cls_serrinfo = Cls_serrinfo & "<li>setconn: Illegal object Parameters </li>" & Chr (10)
Exit Property
End Select
End Property
'*****************************************
' Type: Attribute
' Purpose: Set the Recordset object
' Enter: A_ssql:sql statement.
' Return: None.
'*****************************************
Public Property Let Setrs (A_ssql)
If LCase (TypeName (cls_oconn)) <> "Connection" Then
Cls_serrinfo = cls_serrinfo & <li> Illegal Connection object, unable to create Recordset object </li> "& Chr (10)
Exit Property
End If
Cls_ssql = A_ssql
' Create a Recordset object
Set cls_ors = CreateObject ("Adodb.recordset")
' On Error Resume Next
Cls_ors.open cls_ssql,cls_oconn,1,1
' On Error Goto 0
End Property
'*****************************************
' Type: Attribute
' Purpose: Set the Recordset object
' Input: A_ors:recordset object
' Return: None.
'*****************************************
Public Property Set Setrs (a_ors)
If LCase (TypeName (a_ors)) <> "Recordset" Then
Cls_serrinfo = cls_serrinfo & "<li> illegal Recordset object </li>" & Chr (10)
Exit Property
End If
' Set the Recordset object
Set cls_ors = a_ors
End Property
'*****************************************
' Type: Attribute
' Purpose: Set the Recordset object
' Input: A_ors:recordset object
' Return: Returns a Recordset object
'*****************************************
Public Property Get Getrs ()
Set getrs = cls_ors
End Property
' Get Connection object
Public Property Get Getconn ()
If cls_serrinfo <> "" Then
Call ShowError ()
End If
If LCase (TypeName (cls_oconn)) <> "Connection" Then
Cls_serrinfo = Cls_serrinfo & "<li>connection object get failed </li>"
' Exit Property
End If
Set Getconn = Cls_oconn
End Property
' Returns the database connection string
Public Property Get ConnStr
ConnStr = Cls_sconn
End Property
' Set the number of data displayed on the first page
Public Property Let PageSize (A_ipagesize)
If not IsNumeric (a_ipagesize) Then
Cls_serrinfo = cls_serrinfo & <li> Invalid paging record number parameter </li> "& Chr (10)
Exit Property
End If
Cls_ipagesize = A_ipagesize
End Property
' Set up SQL statements to create a Recordset object
Public Property Let SQL (A_ssql)
If IsNone (a_ssql) Then
Cls_serrinfo = cls_serrinfo & <li> Not set SQL, cannot create Recordset object </li> "& Chr (10)
Exit Property
End If
Cls_ssql = Trim (a_ssql)
End Property