Use JSP ideas to do ASP

xiaoxiao2021-03-06  112

These days have begun to contact some Bean's writings in JSP, and then think about thinking about it, thinking in ASP can also take this idea. Although not very pure, it is not thorough, but it is possible to separate some logic processing, more suitable for the transplantability of the program, and improve the development cycle. I wrote a class Connex containing some operations for the database, I feel that there should be a major partial logic process, but this also improves the error chance, if you control the SQL statement, it should be greater than the disadvantage It is a little bit of a little here, I hope everyone is correct.

The functionality of the program has a general framework, actually adding some features, such as the starting database connection, you can set the variable and select different types of databases by init ().

<% '******************************************************* ******************************************* * Program: Connex. asp '*' * description: imitation of a class JAVABEAN written specifically to operate the database, offers a variety of methods of operation, but to avoid the SQL syntax error '*' * author:! fields Email: Foxty@sina.com '*' * date : 2005.06.0 '************************************************************************ ************************************************************

'On Error Resume Nextclass Connex Public Connex Public Dbpath' --------- Database Pencil PUBLIC DBTYPE '--------- Database Type 1 (SQLServer) 3 (expand) public ConnMethod '-------- Connection mode (DSN, Non DSN) public user public pass sub coplass_initialize end sub subs init () connStr = "driver = {Microsoft Access Driver (* .mdb)}; dbq =" & Server .MapPath ( "Date.mdb") Set ConnEx = server.Createobject ( "ADODB.CONNECTION") ConnEx.Open ConnStr CatchError ( "Class_Terminate") End Sub Sub CatchError (Str) If Err Then Err.Clear Class_Terminate () Response. Write ("Capturing the error, the program is over!" In "& Str &" Office ") Response.end () end if End sub '************************ ****************** '* Find the record in the record through the SQL statement, it is easy to make an error' **************** ************************* Function HasRecordBysql (SQL) Call Checksql (SQL, "R") DIM RS, HASR SET RS = Connex.execute ( SQL) Catcherror ("haasreordsql") if not (rs.eof or rs.bof) Then HASR = false else HASR = TRUE END IF RS = Nothing hasRecordBysql = HASR END FUNCTION '******************************************************** * '* Find the record with the ID existing "*********************************************** Function HasRecordById (strTableName, IntID) 'CheckValue (IntID, 1) Dim Rs, HasR Sql = "Select top 1 * from" & strTableName & "Where Id =" & IntID Call CheckSql (Sql, "R") Set Rs = ConnEx.Execute ( SQL) Catcherror ("Hasrecordbyid") if not (rs.eof or rs.bof) Then HASR = FALSE ELSE HASR =

True end if rs.close set = nothing haasrecordbyid = HASR END FUNCTION '********************************************** ************ '* Get record set by SQL statement "************************************* ***************** FUNCTION GETRSBYSQL (SQL) Call Checksql (SQL, "R") DIM RS SET RS = Server.createObject ("AdoDb.Recordset") RS.Open SQL , Connex, 1,1 set getrsbysql = rs End function '********************************************** ******** '* gets the value of a field' ****************************************** ************ FUNCTION GETVALUEBYSQL (SQL) Call Checksql (SQL, "R") DIM RS, RETURNVALUE SET RS = Connex.execute (SQL) Catcherror ("getValueBysql") if NOT (RS. EOF or = rs (0) Else ReturnValue = "No Record" end if rs.close set = Nothing getValueBysql = RETURNVALUE END FUNCTION '================ =================================== Update, INSERT ============ ============================================================================================================================================================================================================= ==== '**************************************************** '* Using SQL modification data '****************************************************************** Function UpdateBysql (SQL) Call Checksql (SQL, "W") Connex.execute (SQL) Catcherror ("

UpdateBysql = true end function '************************************************************* *** '* Insert data using SQL statement' ******************************************************** ***** Function INSERTBYSQL (SQL) Call CHECKSQL (SQL, "W") Connex.execute (SQL) Catcherror ("InsertBysql") InsertBysql = true end function '============= ================================================================================================================================================================================================================================== ============================================================================================================================================================================================================= === '**************************************************** * Delete '************************************************************************************ DELETEBYSQL (SQL) CAC CHECKSQL (SQL, "D") Connex.execute (SQL) Catcherror ("deleteBysql") deleteBysql = true end function '****************** ************************* * Check the SQL statement permission, depending on the flag Flag to detect the permissions owned by the statement '******** ********************************************* SUB CHECKSQL (SQL, FLAG) DIM STRSQL, Sincounts, Doucounts, I strsql = lcase (SQL) sinCounts = 0 DOUCOUNTS = 0 for i = 1 to Len (strsql) IF MID (strsql, i, 1) = "'" THEN SINCO UNTS = Sincounts 1 IF MID (strsql, i, 1) = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "

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

New Post(0)