ASP Public Data Access Class

xiaoxiao2021-03-05  20

I have no sound in recent days, I want to write a public data access class, but because I am dull, I don't know much about Oracle and Sybase database, so I have been in my heart, I will be ignorant, I hope to know more people. Pointer.

Class design:

Class design

Class code:

<% '******************************************************* *********************** 'Module: Common.asp' Author: Shi Wei 'MODIFIED: March 3, 2005 13:22:12' Purpose: 'Comment: Basic Module' ****************************************************** ****************************

'********************************************************** ******************************* BEGIN >>> 'Use the regular expression to determine whether the string meets a mode' 'strfound: String' strMode: Replacement, regular expression '' Return Value: Non 0- The first appearance location, 0- Did not find '************ *********************************************************** ***************** Function InstrRegExp (strFound, strMode) On Error Resume Next InstrRegExp = 0 If Len (strMode)> 0 Then Dim objRegExp Dim objMatchs, objMatch Set objRegExp = New RegExp objRegExp.Pattern = strMode objRegExp.IgnoreCase = True objRegExp.Global = False objRegExp.Multiline = True Set objMatchs = objRegExp.Execute (strFound) If objMatchs.Count <> 0 Then Set objMatch = objMatchs.Item (0) InstrRegExp = objMatch. FirstIndex 1 set objmatch = Nothing end if set objmatchs = nothing set objregexp = Nothing end if if Err.Number <> 0 THEN 'error handling (to be renewed) err.clear end ifend function' ******** *********************** ******************************************* BEGIN> >> 'Use the regular expression to determine whether the string complies with a mode' 'strfound: String' strMode: Replacement body, regular expression '' return value: Non 0- First appearance position, 0- Didn't find '<<< end' ************************************************* ***********************************************

'********************************************************** **************************************** 'Begin >>>' Use regular expressions replace strings '' Strinput: input To replace the original string 'strreplaced: is replaced, regular expression' strreplace: replacement body, regular expression '************************ *********************************************************** ****** Function ReplaceRegExp (strInput, strReplaced, strReplace) On Error Resume Next ReplaceRegExp = strInput If Len (strReplaced)> 0 Then Dim objRegExp Set objRegExp = New RegExp objRegExp.Pattern = strReplaced objRegExp.IgnoreCase = True objRegExp.Global = True objRegExp.Multiline = True ReplaceRegExp = objRegExp.Replace (strInput, strReplace) Set objRegExp = Nothing End If If Err.Number <> 0 Then 'error processing (Continued) Err.Clear End IfEnd Function' ***** *********************************************************** ************************ "Use the regular expression replace the string '' STRINPUT: Enter the original string to replace" Strreplaced: Replaced Body, regular expression 'strreplace: replacement body, regular expression' <<< end '***************************************** **************************************** *****************

'********************************************************** **************************************** 'Begin >>>' Use regular expressions to extract strings '' STRINPUT: input To extract the original string of strings' strMode: extraction mode, regular expression 'strpicker: extract, regular expression' ********************************** *********************************************************** ******* Function PickRegExp (strInput, strMode, strPicker) On Error Resume Next PickRegExp = "" If Len (strMode)> 0 Then Dim objRegExp Dim objMatchs, objMatch Set objRegExp = New RegExp objRegExp.Pattern = strMode objRegExp. IgnoreCase = True objRegExp.Global = False objRegExp.Multiline = True Set objMatchs = objRegExp.Execute (strInput) If objMatchs.Count <> 0 Then Set objMatch = objMatchs.Item (0) PickRegExp = objRegExp.Replace (objMatch.Value, strPicker ) Set objmatch = Nothing end if set objmatchs = Nothing set objReGexp = Nothing end if if err.Number <> 0 TEN 'error handling (to be continued) Err.clear end ifend function' *********** *********************************************************** ******************* The use of regular expressions extract string '' STRINPUT: Enter the original string to extract strings' strMode: extract mode, regular expression "StrPicker: extract, regular expression" <<< end '****************************************** ***********************************%>

<% '******************************************************* ****************************** The MathSfield_data.asp 'Author: Shi Wei' Modified: March 3, 2005 13:22:12 ' Purpose: 'Comment: Basic Data Access Class' ***************************************** ********************************************************** * Class Mathfield_Data 'Attributes Private McLassName Private Objconn Private MDatabaseType Private MDatabaseServer' Connections for Database Servers string Private mDataBaseName Private mDataBaseUser Private mDataBasePass Private mConnectionString Public ErrorNO Public dicConnectionString 'connection string list Public dicConnectionDriver' database list of connection types Public dicTypeReplaced 'data type conversion list of regular expressions is replaced bodies Public dicTypeReplace' data type conversion exchange body Regular expression list 'Properties Public Property Get ClassName () classname = mclassName End Property

Public property Get DatabaseType () DatabaseType = MDATABASEPE End Property

Public Property Let DataBaseType (ByVal newDataBaseType) On Error Resume Next Select Case UCase (Replace (newDataBaseType, "", "")) Case "SQL", "SQLSERVER" newDataBaseType = "SQLSERVER" Case "ACCESS" newDataBaseType = "ACCESS" Case "MYSQL" newDataBaseType = "MYSQL" Case "ORACLE" newDataBaseType = "ORACLE" Case Else newDataBaseType = "SQLSERVER" End Select If Err.Number <> 0 Then ErrorNO = Err.Number Err.Clear newDataBaseType = "SQLSERVER" End If mDataBaseType = NewDatabaseType End PropertyPublic Property Get DatabaseName () DatabaseName = MDATABASENAME End Property

Public Property Let DataBaseName (ByVal newDataBaseName) On Error Resume Next newDataBaseName = Trim (CStr (newDataBaseName)) If Err.Number <> 0 Then ErrorNO = Err.Number Err.Clear newDataBaseName = "" End If mDataBaseName = newDataBaseName End Property

Public property get databaseuseuser () DatabaseUser = MDATABASEUSER End Property

Public Property Let DataBaseUser (ByVal newDataBaseUser) On Error Resume Next newDataBaseUser = Trim (CStr (newDataBaseUser)) If Err.Number <> 0 Then ErrorNO = Err.Number Err.Clear newDataBaseUser = "" End If mDataBaseUser = newDataBaseUser End Property

Public Property Get DataBasePass () DataBasePass = mDataBasePass End PropertyPublic Property Let DataBasePass (ByVal newDataBasePass) On Error Resume Next newDataBasePass = Trim (CStr (newDataBasePass)) If Err.Number <> 0 Then ErrorNO = Err.Number Err.Clear newDataBasePass = " "End if mdatabasepass = newDatabasepass endproperty

Public property Get DatabaseServer () DatabaseServer = MDATABASERVER End Property

Public Property Let DataBaseServer (ByVal newDataBaseServer) On Error Resume Next Select Case mDataBaseType Case "SQLSERVER", "ORACLE" newDataBaseServer = Trim (CStr (newDataBaseServer)) If Err.Number <> 0 Then ErrorNO = Err.Number Err.Clear newDataBaseServer = "" End if case else newdatabaseServer = "" End Select MDatabaseServer = NewDatabaseServer End Property

Public property Get Connectionstring () Connectionstring = MCONNECTIONSTRING End Property

Public Property Let ConnectionString (ByVal newConnectionString) On Error Resume Next Dim strTemp, strTempType Dim ii 'acquisition database type strType = "" strTemp = PickRegExp (newConnectionString, "Driver / s * = / s * ([A-Za-z0-9_ /* / (/ )/ (/ }]*) "," $ 1 ") 'odbc driver if len (strtemp) = 0 dam (newconnectionstring," provider / s * = / s * ([a -ZA-Z0-9_ /*/./ (/)/ }]* "" "$ 1") 'OLEDB Driver if len (strtemp)> 0 damtype = "OLEDB" end if else strtemptype = "ODBC "End if for Each ii in dicConnectionDriver If InstrRegExp (strTemp, ii)> 0 Then strTemp = dicConnectionDriver (ii) Exit for End If Next dataBaseType = strTemp 'acquisition database Select Case strTempType Case to be operated" ODBC "Select Case mDataBaseType Case" SQL Server "DatabaseServer = PickRegeXP (NewConnectionstring, "Server / s * = / s * ([/ )/.]*)", "$ 1") DatabaseName = PickRegexp (Newconnectionstring, "Database / S * = / s * ([A-ZA-Z0-9_ / * / (/)] *) "," $ 1 ") case" access "DatabaseServer =" "DatabaseName = PickRegeXP (NewConnectionstring," DBQ / S * = / s * ([A-ZA-Z0-9_: ////.] *) "," $ 1 ") case" mysql "DatabaseServer =" DatabaseName =

PickRegeXP (NewConnectionstring, "Database / S * = / S * ([A-ZA-Z0-9_ /*/ ((/ )]*)", "$ 1") Case "Oracle" DatabaseServer = PickRegeXP (NewConnectionstring, " Server / s * = / s * ([A-ZA-Z0-9_ /*/ (/)]* )/s*/./s* ([([A-ZA-Z0-9_ / * / (/)] *) "," $ 1 ") DatabaseName = PickRegeXP (NewConnectionstring," Server / S * = / S * ([A-ZA-Z0-9_ / * / (/)] *) / s * /. / S * ( [A-ZA-Z0-9_ / * / (/)] *) "," $ 2 ") Case Else DatabaseServer =" DatabaseName = "" End Select 'Get Database User Name and Password DatabaseUser = PickRegeXP (NewConnectionstring, "UID / S * = / s * ([A-ZA-Z0-9_] * "," $ 1 ") DatabasePass = PickRegeXP (NewConnectionstring," PWD / S * = / S * ([A-ZA-Z0-9_] * ), "$ 1") case "oledb" select case mdatabaseType case "SQL Server" DatabaseServer = PickRegeXP (NewConnectionstring, "DATA / S * SOURCE / S * = / S * ([A-ZA-Z0-9_ / * / /) / .]*) "," $ 1 ") DatabaseName = PickRegeXP (NewConnectionstring, "Initial / s * catalog / s * = / s * ([A-ZA-Z0-9_ / * / (/)] *)", "$ 1") case "access" DatabaseServer = " "DatabaseName = PickRegeXP (NewConnectionstring," DATA / S * SOURCE / S * = / S * ([A-ZA-Z0-9_: //// * / (/) /.] *) "," $ 1 ") case "Mysql" DatabaseServer = "" DatabaseName = ""

Case "Oracle" DatabaseServer = PickRegeXp (NewConnectionstring, "DATA / S * SOURCE / S * = / S * ([A-ZA-Z0-9_: //// * / (/) /.] *) /. ([[[ A-ZA-Z0-9_: /// * / (/) /.] *) "" $ 1 ") DatabaseName = PickRegexp (NewConnectionstring," DATA / S * SOURCE / S * = / S * ([A- ZA-Z0-9_: /// * / (/) /.] *) /. ([A-ZA-Z0-9_: //// * / (/) /.] * "," $ 2 ") Case Else DatabaseServer = "DatabaseName =" "End Select" Get database username and password DatabaseUser = PickRegeXP (NewConnectionstring, "User ID / S * = / s * ([A-ZA-Z0-9_] *)", "$ 1 ") DatabasePass = pickregEXP (NewConnectionstring," Password / s * = / s * ([A-ZA-Z0-9_] * "," $ 1 ") end select if err.number <> 0 Then DatabaseType =" "DatabaseServer = "" DatabaseName = "" DatabaseUser = "" DatabasePass = "" ERRORNO = Err.Number Err.clear End if End Property 'Implements

'Procedures' constructor (VB) Private Sub Class_Initialize () On Error Resume Next' initialization data mClassName = "Mathsfield_Data" Set objConn = Server.CreateObject ( "ADODB.Connection") mDataBaseType = "SQLSERVER" mDataBaseServer = "" mDataBaseName = " "Mdatabaseuseuser =" "MDatabasePass =" "MConnectionstring =" "" ERRORNO = 0 set DicConnectionstring = Server.createObject ("scripting.dictionary") '******************* *********************************************************** ********** 'Begin >>>' Connection String String Regular Expression List '' Microsoft SQL Server: SQLServer 'Microsoft Access: Access' MySQL: MySQL 'Oracle: Oracle' ****** *********************************************************** ************************ The ODBC connection DicConnectionstring.add "odbc_sqlserver", "driver = {SQL Server}; server = [DatabaseServer]; Database = [DatabaseName]; UID = [DatabaseUser]; PWD = [databasepass]; "DICCONNECTION String.Add "ODBC_ACCESS", "Driver = {Microsoft Access driver (* mdb.)}; Dbq = [DataBaseName]; Uid = [DataBaseUser]; Pwd = [DataBasePass];" dicConnectionString.Add "ODBC_MYSQL", "Driver = {Mysql}; database = [databasename]; uid = [dataBaseuser]; PWD = [DatabasePass]; Option = 16386; "'Here you must depend on the specific situation, sometimes add the version number DicConnectionstring.Add" ODBC_Oracle "," Driver = {microsoft odbc for oracle}; server = [dataBaseserver]; uid = [databaseuseuser]; PWD =

[DataBasePass]; " 'OLEDB connection dicConnectionString.Add" OLEDB_SQLSERVER "," Provider = SQLOLEDB; Data Source = [DataBaseServer]; Initial Catalog = [DataBaseName]; User Id = [DataBaseUser]; Password = [DataBasePass]; "dicConnectionString. Add "OLEDB_ACCESS", "Provider = Microsoft.Jet.Oledb.4.0; Data Source = [DataBaseName]; User Id = [dataBaseUser]; Password = [DataBasePass];" dicConnectionString.Add "OLEDB_MYSQL", "Driver = {MySQL} ; Database = [DataBaseName]; Uid = [dataBaseUser]; Pwd = [DataBasePass]; Option = 16386; "dicConnectionString.Add" OLEDB_ORACLE "," Provider = Oraoledb.Oracle; Data Source = [DataBaseServer] [DataBaseName];. User ID = [DatabaseUser]; Password = [DatabasePass]; "'***************************************************** ******************************************* The connection string is represented List 'Microsoft SQL Server: SQLServer' Microsoft Access: Access 'Mysql: MySQL' Oracle: Oracle '<<< End' ********************* *************************************** ************************* SET DICCONNECONNECTIONDRIVER = Server.createObject ("scripting.dictionary") '**************** *********************************************************** ************************> 'Database driver regular expression list' 'Microsoft SQL Server: SQLServer' Microsoft Access: Access 'MySQL: MySQL' Oracle : Oracle '********************************************************* ********************************* The 'ODBC connection DicConnectionDriver.add "

/ {/ s * SQL / S Server / S * /} "," SQLServer "DicconnectionDriver.add" / s*microsoft/s access/s driver/ (/*/.mdb/ )/s* /} "," Access "DicConnectionDriver.Add" / {/ S * mysql / s * /} "," MySQL "DICCONNECTIONDRIVER.ADD" / {/ S * Microsoft / S ODBC / S FOR / S ORACLE / S * /} "," Oracle "'OLEDB Connect DicconnectionDriver.Add" / S * SQLOLEDB / S * "," SQLServer "DicconnectionDriver.add" /s*microsoft/s*/./s*jet/s*/. / s*4/s*/s*/./s*0/s* "," Access "DicconnectionDriver.add" /s*oledb/s*/./s*oracle/s* "," Oracle "" ************************************************************** *********************************** The database driver regular expression list '' Microsoft SQL Server: SQLServer 'Microsoft Access: ACCESS' MYSQL: MySQL 'Oracle: Oracle' <<< End '****************************************** ******************************************************************** DictypeReplaced = Server.createObject ("scripting.dictionary") '**************************************************** *********************** ******************* 'Begin >>>' Data Type Conversion User Replacement Regular Expression List '' String String, Date Date, Real Real, Integer Int , Content Text '******************************************************** ********************************** DICTYPEREPLAECED.ADD "String", "(/ [string /]) ( [/ S / S] *) (/ [/ String /]) "DictypeReplaced.Add" Date "," (/ [DATE /]) (/ D {2} | / d {4}) - (/ d { 1, 2}) - (/ D {1, 2}) (/ [/ date /]) "DictypeReplaced.Add" Real "," (/[Real/]) (/D |/d /.?/d * | / d * /.? / d ) (/ [/ real /]) "

DictypeReplaced.Add "int", "(/ [/ /]) (/ [/ int /])" DictypeReplaced.Add "text", "(/ [text /]) ([/ s / s] *) (/ [/ Text /]) "'*********************************************** ********************************************* The data type conversion is regularly Expression list '<<< End' ********************************************************** ************************************************ SET DICTYPEREPLACE = Server.createObject ("scripting.dictionary ") '**************************************************** ******************************************** The replacement regular expression list " 'String String, Date Date, Real Real, Integer INT, Content Text' ******************************************** ***************************************************************** Both SQL Server dicTypeReplace.Add "SQLSERVERSTRING", " '$ 2'" dicTypeReplace.Add "SQLSERVERDATE", " '$ 2- $ 3- $ 4'" dicTypeReplace.Add "SQLSERVERREAL", "$ 2" dicTypeReplace.Add "SQLSERVERINT", "$ 2" dicTypeReplace. Add "SQLServertext", "'$ 2'" 'Access DictypeReplace.Add "AccessString", "'$ 2'" DictypeReplace.add "AccessDate", "# $ 2- $ 3- $ 4 #" DictypeReplace.add "AccessReal", "$ 2" DictypeReplace.Add "Accessint", "$ 2" DictypeReplace.add "Accessxt" Accesster "," '$ 2' "'mysql dictypereplace.add" mysqlstring ","' $ 2 '"DictypeReplace.Add" mysqldate "," $ 2- $ 3- $ 4 "DictypeReplace.add" mysqlreal "

"$ 2" DictypeReplace.add "mysqlint", "$ 2" DictypeReplace.add "Mysqltext", "'$ 2'" 'Oracle DictypeReplace.add "ORACLESTRING", "' $ 2 '" "DictypeReplace.add" OracleDate "," "" " $ 3- $ 4 '"DictypeReplace.add" OracleAl "," $ 2 "DictypeReplace.add" Oracleint "," $ 2 "DictypeReplace.add" Oracletext ","' $ 2 '"" "" "" "" *********************************************************** ******************* The data type conversion replacement regimen regular expression list '<<< End' ************* *********************************************************** **************** If Err.Number <> 0 Then ErrorNo = Err.Number Err.Clear End If End Sub 'Destructor (VB) Private Sub Class_Terminate () ON Error Resume Next 'release objects dicTypeReplaced.RemoveAll dicTypeReplace.RemoveAll dicConnectionDriver.RemoveAll dicConnectionString.RemoveAll Set dicTypeReplaced = Nothing Set dicTypeReplace = Nothing Set dicConne Ctiondriver = Nothing set Dicconnectionstring = Nothing call disconnect set objconn = Nothing

If Err.Number <> 0 Then ErrorNo = Err.Number Err.Clear End If End Sub

'Functions' connect to the database, the return value: 1- success; 0- failure Public Function Connect () On Error Resume Next If objConn.State <> 0 Then objConn.Close End if mConnectionString = FormatConnectionString ( "ODBC") objConn.ConnectionString = mConnectionString objConn.Open If Err.Number <> 0 Then Err.Clear mConnectionString = FormatConnectionString ( "OLEDB") objConn.ConnectionString = mConnectionString objConn.Open End If Connect = 1If Err.Number <> 0 Then Connect = 0 mConnectionString = "" Errorno = err.Number Err.clear end if End function

'Disconnect the database connection, return the value: 1 - success; 0- Failed public function disconnect () on error resume next if objconn.state <> 0 Then objconn.close end if mconnectionstring = "" disconnect = 1

If Err.Number <> 0 THEN DISCONNECT = 0 erroorno = err.Number Err.clear end if End function

'Performs a set of SQL statements that return record' the Recordset returns a 'set according to the state of the recording, it is determined whether the statement succeeded Public Function RunSQLRecordset (ByVal strSQL) On Error Resume Next Dim objRs Set objRs = Server.CreateObject ( "ADODB.Recordset") Set objrs = objconn.execute (strsql)) set runsqlrecordset = objrs if err.Number <> 0 Then ErrorNo = err.Number Err.clear end if End Function

'Do not return SQL statements that record' Return Value: 1- success; 0- failure Public Function RunSQLNull (ByVal strSQL) On Error Resume Next objConn.Execute FormatCondition (strSQL),, adCmdText adExcuteNoRecords RunSQLNull = 1 If Err.Number <> 0 Then RunSQLNull = 0 ErrorNO = Err.Number Err.Clear End if End Function 'generates a query record set' the recordset returns a 'set according to the state of the recording, it is determined whether the statement successfully Public Function SelectRecordset (ByVal strFields, ByVal strTableName, ByVal strCondition) On Error Resume Next Dim strSQL, objRs Set objRs = Server.CreateObject ( "ADODB.Recordset") strCondition = Trim (strCondition) If Len (strCondition) = 0 Then strCondition = "(1 = 1)" End If strSQL = "SELECT" & strfields strsql = strsql & "from" & start STRSQL = strsql & "where" & formatcondition (strcondition) set objrs = Objconn.execute (strsql) set selectrecordset = ObJRS

If Err.Number <> 0 Then ErrorNo = Err.Number Err.Clear End If End Function

'Insert data Return Value: 1- success; 0- failure Public Function InsertRecord (ByVal strTable, ByVal strFields, ByVal strValues) On Error Resume Next Dim strSQL Dim arrFields, arrValues ​​Dim intUFields, intLFields Dim intUValues, intLValues ​​Dim ii arrFields = Split (strFields, ",") arrValues ​​= Split (strValues, ",") intUFields = Ubound (arrFields) intLFields = LBound (arrFields) intUValues ​​= Ubound (arrValues) intLValues ​​= LBound (arrValues) If (intUFields - intLFields) <> ( INTUVALUES - INTLVALUES) THENERR.RAISE 1000 'ourselves (for treatment) End if if not (Err.Number <> 0) THEN for II = Intlvalues ​​To Intuvalues ​​Arrvalues ​​(II) = formatValue (Arrvalues ​​(II)) Next Strsql = "INSERT INTO" & Strtable Strsql = strsql & "(" & Join (Arrfields, ",") "strsql = strsql &" values ​​("& join (arrvalues,", ") &") "Objconn.execute STRSQL, AdcmdText Adexcutenorecords end if insertrecord = 1if err.Number <> 0 THEN INSERTRECORD = 0 erroorno = err.Number Err.clear end if End Function

'Insert data and return to the specified field at the data' Returns a recordset 'According to the status of the recordset, the statement is determined whether the statement is successful' InsertRetReturnValue (Byval StRTable, ByVal Strfields, Byval Strvalues) On Error Resume NEXT DIM STRSQL , objRs Dim arrFields, arrValues ​​Dim intUFields, intLFields Dim intUValues, intLValues ​​Dim ii Set InsertReturnValue = Server.CreateObject ( "ADODB.Recordset") arrFields = Split (strFields, ",") arrValues ​​= Split (strValues, ",") intUFields = Ubound (arrFields) intLFields = LBound (arrFields) intUValues ​​= Ubound (arrValues) intLValues ​​= LBound (arrValues) If (intUFields - intLFields) <> (intUValues ​​- intLValues) Then Err.Raise 1000 'own settings (Continued) End If If not (Err.Number <> 0) THEN SET OBJRS = Server.createObject ("AdoDb.Recordset") strsql = "SELECT *" & strappable "where (1 <> 1)" with objrs .cursortype = 2 .lockType = 3 .CursorLocation = 3 .Open strSQL, objConn .AddNew For ii = intLFields To intUFields .Fields (arrFields (ii)) = arrValues ​​(intLValues ​​ ii - intLFields) Next If Err.Number = 0 Then .Update End If End With End If IF not (err.Number <> 0) THEN SET INSERTRETURNVALUE = objrs end ifif err.number <> 0 Then erroorno = err.Number Err.clear end if End function

'Update data, and return values: 1- success; 0- failure Public Function UpdateRecord (ByVal strTable, ByVal strFields, ByVal strValues, ByVal strCondition) On Error Resume Next Dim strSQL Dim arrFields, arrValues ​​Dim intUFields, intLFields Dim intUValues, intLValues ​​Dim ii arrFields = Split (strFields, ",") arrValues ​​= Split (strValues, ",") intUFields = Ubound (arrFields) intLFields = LBound (arrFields) intUValues ​​= Ubound (arrValues) intLValues ​​= LBound (arrValues) If (intUFields - intLFields) <> (intuvalues ​​- intlvalues) Then Err.raise 1000 'ourselves set (to be renewed) End if if not (Err.Number <> 0) Then strcondition = trim (strcondition) if len (strcondition) = 0 dam strcondition = " 1 <> 1) "end if strcondition = formatcondition (strcondition) for II = INTLVALUES To Intuvalues ​​Arrvalues ​​(II) = Arrfields (Intlfields II - INTLVALUES &" = "& FormatValue (arrValues ​​(ii)) Next strSQL = "UPDATE" & strTable strSQL = strSQL & "SET" & Join (arrValues, ",") strSQL = strSQL & "WHERE" & strCondition objConn.Execute strSQL,, adCmdText adExcuteNoRecords End IF updateRecord = 1if err.Number <> 0 Then updateRecord = 0 erroorno = err.Number Err.clear end if end function

'Delete data, return value: 1- Success; 0- Failed' When the constraint condition is empty, do not delete any data public function deleteRecord (ByVal Strtable, Byval Strcondition) on Error Resume Next Dim Strsql strcondition = trim (strcondition) if Len (strCondition) = 0 Then strCondition = "(1 <> 1)" End If strSQL = "DELETE FROM" & strTable strSQL = strSQL & "WHERE" & FormatCondition (strCondition) objConn.Execute strSQL,, adCmdText adExcuteNoRecords DeleteRecord = 1If Err.Number <> 0 Then DeleteRecord = 0 erroorno = err.Number Err.clear end if end function

'Format a string of value participation, enabling him that the given database type Private function FormatValue (Byval Strinput) On Error Resume Next Dim Arrtype, II Arrtype = Array ("String", "Date", "Real", " INT "," text "for Each II in Arrtype Strinput = ReplacereGexp (Strinput, DictypeReplaced (II), DictypeReplace (MDatabaseType & II) Next FormatValue = STRINPUT END FUNCTION

'Format the condition string so that he meets the given database type' here included formatting value and various operator private function formatcondition (Byval Strinput) on error resume next formatcondition = formatValue (STRINPUT) End Function

'Generate standard connection string Private Function FormatConnectionString (ByVal strType) On Error Resume Next FormatConnectionString = "" strType = UCase (Trim (strType)) Select Case strType Case "ODBC", "OLEDB" Case Else strType = "ODBC" End Select Select Case mDataBaseType Case "SQLSERVER" If Len (mDataBaseServer) * Len (mDataBaseName)> 0 Then FormatConnectionString = dicConnectionString (strType & "_" & mDataBaseType) FormatConnectionString = ReplaceRegExp (FormatConnectionString, "/ [DataBaseServer /]", mDataBaseServer) FormatConnectionString = ReplaceRegExp (FormatConnectionString, "/ [DataBaseName /]", mDataBaseName) End if Case "ACCESS" If Len (mDataBaseName)> 0 Then FormatConnectionString = dicConnectionString (strType & "_" & mDataBaseType) FormatConnectionString = Rep laceRegExp (FormatConnectionString, "/ [DataBaseName /]", mDataBaseName) End if Case "MYSQL" If Len (mDataBaseName)> 0 Then FormatConnectionString = dicConnectionString (strType & "_" & mDataBaseType) FormatConnectionString = ReplaceRegExp (FormatConnectionString, "/ [DataBaseName /] ", MDatabaseName) end if case" Oracle "IF LEN (MDatabaseServer) * Len (MDatabaseName)> 0 Then FormatConnectionstring =

dicConnectionString (strType & "_" & mDataBaseType) FormatConnectionString = ReplaceRegExp (FormatConnectionString, "/ [DataBaseServer /]", mDataBaseServer) FormatConnectionString = ReplaceRegExp (FormatConnectionString, "/ [DataBaseName /]", mDataBaseName) End if End Select FormatConnectionString = ReplaceRegExp ( FormatConnectionstring, "/ [Databaseuseuser /]", MDatabaseUser) FormatConnectionstring = ReplaceRegexp (FormatConnectionstring, "/ [DatabasePass /], MDatabasePass) End Functionend Class%> class test:

Test Access Test MySQL Test SQL Server

转载请注明原文地址:https://www.9cbs.com/read-38680.html

New Post(0)