First of all, think that the ASP is obsolete, please ignore this post, thank you. I just provide a way of thinking, I hope to give a lot of people are still learning and using ASP's friends a convenience. Although I do not use ASP now, but I believe that as long as can meet the application, there is no outdated, perhaps its language is not so advanced, but the application does not necessarily on the lower level, hehe.
easyasp is a convenient and rapid development of the ASP class, which contains a database control class ( The original clsdbctrl.asp, the original code has been optimized and modified, including the database of various operations and stored procedures of the call, all encapsulated in the easp.db, it will be more convenient to use, the call is simpler). And the Easp class provides a lot of practical ASP common process and method, can simplify most ASP operation. Only the VBScript version is currently available, and the JScript version may be available in the future. For more information, please download the Help manual, which has a very detailed description of the use of methods and source code examples.
Follow-up update please pay attention to: http://code.google.com/p/easyasp/
=================================================================
Easyasp v1.5 (updated in 2008-10-22)
new Features:
1, the Database control class (original clsdbctrl.asp) encapsulated into the Easp class, through the EASP.DB call, can also be used independently.
2, add the MSSQL stored procedure call method, you can flexibly invoke the stored procedure and return return value, Recordset and out parameters.
3, add db. Creatconn method, you can connect to a database based on a custom connection string.
4, add db. Json method, you can output a database recordset in JSON format.
5, add db. Rand and Db.randstr methods that generate a random or random string that is not repeated
6, the new database operation methods of shorthand method, more economical writing code time.
7, in the Easp class to add a large number of practical methods, such as secure access to the value, anti-SQL injection, server-side form validation.
Other updates:
1, optimize DB. Autoid automatically gets the number, the efficiency is increased more than 20 times times, the data quantity is bigger more obvious.
2, modify DB. Openconn database connection method, more consistent with the daily description habits.
3, modify DB. Getrecord Recordset method with fewer parameters. Fix the bug with an array error.
4, modify and optimize db. DeleteRecord Delete Logging method, there are currently only two parameters.
5, modified the error debugging method, add Debug global Property Control error display.
Update Description:
Previously wrote a clsdbctrl.asp database control class ("ASP Operation database class, let data operation becomes simple"), received some feedback, and a friend sent me a message to tell me some ways to improve, thank them. And I in the thread of the original post to see a message that "there is a memory of the parameters of the time, the SQL statement has been written all over", but also directly pointed out that the embarrassment, indeed, although the VBS does not have arguments attributes, but too many parameters are not a good idea. So it took me a while to rewrite a lot of the code for this class, a method with a maximum of 3 parameters in the premise that the function can only be stronger and not weaker. In addition, a new method called the MSSQL stored procedures, you can flexibly invoke the stored procedure and return one or more records, output parameters and return values as needed, of course, the lesson, this method has only two parameters. are now encapsulated in this new name easyasp, as the name suggests, nothing more than to think that everything is simple.
There is also a more embarrassing, that is VBScript is not an object-oriented language, so this class in fact, it is only a few processes and methods of encapsulation, easy to use, so most of the methods and procedures can be proposed to use alone. Of course, if necessary, it can also be encapsulated into WSC or DLL components to use.
=================================================================
Instructions for use
=================================================================
1, the use of methods:
(1) All calls to the Easp class are already contained in easp.asp, so you only need to introduce the file at the top of the page, such as:
copy content to clipboard
Code:
<!--#include file="inc/easp/easp.asp" -->
Or:
copy content to clipboard
Code:
<!--#include virtual="/inc/easp/easp.asp"-->
(2) The class has been instantiated without any further instantiation, directly using the easp. Prefix invocation, such as:
copy content to clipboard
Code:
Easp.wn("Test String") 或 Easp.db.AutoId("Table:ID")
(3) If you want to operate multiple databases at once, instantiate the new Easpdb object, such as:
copy content to clipboard
Code:
Dim db2 : Set db2 = New EasyASP_db
db2.dbConn = db2.OpenConn(0,dbase,server)
2. Parameter agreement:
(1) Array parameters: Because VBScript has no arguments properties and cannot use dynamic parameters, array (array) is used to achieve this effect in the code that involves database data in this class. Some of the parameters in this class can be used in arrays (as noted in the parameter descriptions), but the following format should be used when using arrays:
copy content to clipboard
Code:
Array("Field1:Value1", "Field2:True", "Field3:100")
Yes, a bit like JSON format, if it involves variables, that's it:
copy content to clipboard
Code:
Array("Field1:" & Value1, "Field2:" & Value2, "Field3:" & Value3)
It can be said that almost all of the content associated with database fields in this class can be set with the above array format or get content, including calling parameters to be passed by the stored procedure. The biggest advantage of this class is that you don't have to consider the type of field when you use it, and then follow the field with a colon, followed by the corresponding value. If you often write ASP programs, you will soon feel the charm of using this method, in addition to the data type not to consider, it is also easy to add and delete conditions at any time. Here's an example to illustrate this usage:
For example, how to add a new record:
copy content to clipboard
Code:
Easp.db.AddRecord "Table", Array("FieldsA:测试数据","FieldsB:"&Now(),"FieldsC:True")
There are only two arguments, one is the table name, and the other is the array parameter. If you want to change the structure of the database, it is very easy to modify the program code above.
(2) Common parameters (separated by special symbols): It is also considered to minimize parameters, if some of the parameters in many cases can not, there is no need to specifically add a parameter for it. Special symbols such as colons (separating multiple values in one parameter) are used in this class to pass multiple parameters. For a few examples, you can also preview some of the advantages of using this class:
For example, to establish the MSSQL database connection object method:
copy content to clipboard
Code:
Set Conn = Easp.db.Open(0,"Database","User:Password@ServerAddress")
At a glance right, here it is: and @ separated a few parameters and placed in the same parameter. In addition, if the Access database has a password, enter in the 3rd argument, no more arguments.
Again, for example, to get a recordset:
copy content to clipboard
Code:
Set rs = Easp.db.GetRecord("Table:FieldsA,FieldsB,FieldsC:20","ID > 10","ID Desc")
The 1th parameter contains the table name, the field to take and the number of records to take, because the number of fields and records can be omitted many times, so I simply omitted the parameters, so that the parameters to be recorded a lot less.
Another example of this class has a geturl () to get the address of this page, many places have seen it, but this method in this class with a parameter, through this parameter can achieve a lot of results, see examples:
For example, the actual address of this page is:
copy content to clipboard
Code:
http://www.domain.com/news/index.asp?type=public&feed=on&page=23
The following results are returned using different parameters:
copy content to clipboard
Code:
方法 返回结果
GetUrl("") http://www.domain.com/news/index.asp?type=public&feed=on&page=23
GetUrl(0) /news/index.asp
GetUrl(1) /news/index.asp?type=public&feed=on&page=23
GetUrl("page") /news/index.asp?page=23
GetUrl("-page") /news/index.asp?type=public&feed=on
GetUrl(":") /news/?type=public&feed=on&page=23
GetUrl(":-feed,-page") /news/?type=public
No more explanation, hehe. This class of flexible use of common parameters where there are many, this is also a major feature of easyasp, we look at the manual.
Methods and Properties Overview:
(1) Database operation:
Property:
Easp.db.dbConn (read-write) setting and getting current database connection objects
Easp.db.DatabaseType (read-only) query the type of database currently in use
Easp.db.Debug (read-write) setup and query error debug switch
EASP.DB.DBERR (read-only) query error message
Method:
Easp.db.OpenConn database connection objects based on templates
Easp.db.CreatConn Establish a database connection object based on a custom string
Easp.db.AutoID get automatic numbering based on table name
Easp.db.GetRecord get recordsets based on conditions
Easp.db.wGetRecord output Gets the recordset's SQL statement
Easp.db.GetRecordBySQL get a recordset based on a custom SQL statement
Easp.db.GetRecordDetail get details of a record
Easp.db.AddRecord Add a new record
Easp.db.wAddRecord an SQL statement that adds a new record to the output
Easp.db.UpdateRecord update records based on criteria
Easp.db.wUpdateRecord output update record SQL statement
Easp.db.DeleteRecord Delete records based on criteria
Easp.db.wDeleteRecord output Deletes a record's SQL statement
Easp.db.ReadTable to get the specified field data according to the criteria
Easp.db.Json generates Json-formatted data from a recordset
Easp.db.doSP invokes a stored procedure and returns a variety of data
Easp.db.Rand generates a random number that is not repeated
EASP.DB.RANDSTR generates a random string that is not duplicated
EASP.DB.C closes the recordset and frees resources
(2) String processing:
EASP.W Output string
Easp.wn output string and one HTML wrap ("<br/>")
Easp.we the output string and terminates the program
EASP.ISN determine if a string is a null value
Easp.js output JavaScript code
Easp.alert Popup JS message box and return to the previous page
Easp.alerturl Popup JS message box and jump to new page
Easp.jsencode convert string to secure JavaScript string
Easp.cutstring intercept a string and replace the truncated part with a custom symbol
Easp.htmlencode HTML Overweight function
Easp.htmldecode HTML decoding function
Easp.htmlfilter Filter HTML Tags
Easp.randstr a random string that generates a specified length
EASP.R gets the request value and converts it to a SQL security string
Easp.ra secure the request value and eject the JS message box when the error occurs
Easp.test validation of data legality based on regular expressions
(3) Time and date processing:
Easp.datetime formatted date of day
Easp.diffhour returns the number of hours that a date-time variable differs from the present
Easp.diffday returns the number of days that a date-time variable differs from the present
Easp.getscripttime returns accurate to millisecond script execution time based on the timestamp
(4) Digital processing:
Easp.rand generates a random number
Easp.tonumber converts a number to a format that specifies the number of decimal places
Easp.toprice convert number to currency format
Easp.topercent convert number to percent format
(5) Cookies and application processing:
Easp.setcookie set a cookie value
Easp.getcookie Get a cookie value
Easp.removecookie Delete a cookie value
Easp.setapp set a application value
Easp.getapp Gets a application value
Easp.removeapp Deletes a application value
(6) Other:
Three-dimensional expression of easp.ifthen judgment
EASP.RR server-side jump page
Easp.geturl gets the URI address of the current page
Easp.getip Get the Visitor IP
Easp.nocache Settings page does not cache
Easp.close closes objects and frees resources
Easp.checkform server-side form authentication pop-up JS message box
Easp.checkdatafrom Authentication Submission Data source
Easp.checkdatafroma Verify that the data source is out of code. Popup JS message box
Easp.checksql anti-SQL injection strong verification
EASP.CHECKSQLA anti-SQL injection strong validation irregularities pop-up JS message box
The following is a reference fragment: Easp.db.doSP method
Call an SQL stored procedure and return the data
Grammar
[[Set]obj =] [Easp.] Db.dosp (Spname:sptype, Spparams)
Parameters
Obj The value returned by the stored procedure, the output parameter collection, or the Record object Spname The name of the stored procedure to invoke Sptype The type of stored procedure to invoke, which can be the following values: 0 or omitted-a stored procedure that has no parameters or only input parameters 1 or "Out"-stored procedures with output parameters 2 or "RS"-a stored procedure that does not have an output parameter and returns one or more recordsets 3 or "All"-stored procedures that have output parameters and return one or more recordsets Spparams The input or output parameters to pass to the stored procedure, as the array should follow the array parameter convention (slightly different, see the example). In the name of the parameter in the array, follow the following format: Input parameter: @+ parameter name + colon (:) + value Output parameter: @@+ parameter name Note: The order of the parameters is exactly the same as the order in the stored procedure
Comments
Calling this method invokes an MS SQL Server stored procedure and can return one or more recordsets, output parameters, or return values. The value returned might be an object, an array, or a string, as detailed in the following example.
Example
Because stored procedure content is different, the return data is different, the input output parameter requirements are different, so in several cases, this method calls the stored procedure:
1, no input output parameters, does not return the recordset's stored procedure call: Copy Content to Clipboard Code: Dim MYSP MYSP = Easp.db.doSP ("mytestsp", "") EASP.W MYSP ' output return value 2, only input parameters, no output parameters, do not return the recordset's stored procedure calls: Copy Content to Clipboard Code: MYSP = Easp.db.doSP ("mytestsp", Array ("@param1:" & Value1, "@param2:" & Value2)) ' Or, in a simpler way, just the item with the array parameter (applies only to this case): ' MYSP = Easp.db.doSP ("mytestsp", Array (value1,value2)) EASP.W MYSP ' output return value 3, there is or no input parameters, there are output parameters, do not return the recordset's stored procedure calls: Copy Content to Clipboard Code: Set MYSP = Easp.db.doSP ("Mytestsp:1", Array ("@inParam1:" & Vlaue1, "@inParam2:" & Value2, "@ @outParam1", "@@ OutParam2 ")) Easp.wn MYSP ("return") ' output returned value Easp.wn MYSP ("@ @outParam1") ' outputs the specified output parameter value Easp.close (MYSP) 4, with or without input parameters, no output parameters, only returns the recordset's stored procedure call: Copy Content to Clipboard Code: Set MYSP = Easp.db.doSP ("Mytestsp:2", Array ("@param1:" & Value1, "@param2:" & Value2)) While not mysp.eof ' output recordset contents Easp.wn "ID:" & MYSP (0) Easp.wn "Name:" & MYSP (1) Mysp.movenext () Wend EASP.DB.C (MYSP) 5, with or without input parameters, there are output parameters, but also to return the recordset's stored procedure call: Copy Content to Clipboard Code: MYSP = Easp.db.doSP ("Mytestsp:3", Array ("@inParam1:" & Vlaue1, "@inParam2:" & Value2, "@ @outParam1", "@@ OutParam2 ")) ' MYSP will return an array, the first element is the Recordset object, and the second element is the parameter and return value Dim Rs:set rs = MYSP (0) ' The RS Recordset object can be manipulated here. ’... ... Easp.wn MYSP (1) ("return") ' output returned value Easp.wn MYSP (1) ("@ @outParam2") ' output specified parameter value Note again: The order of the parameters is exactly the same as the order in the stored procedure. But the parameter name is not mandatory to be the same as in the stored procedure, but only for the code to be readable, it is recommended that you do this (except for the output parameter, which requires two @, and only one @ in the stored procedure).
In addition, if you want to return multiple Recordset objects, you can do this in a way that allows you to manipulate multiple recordsets you get: Copy Content to Clipboard Code: Set rs = Easp.db.doSP ("Mytestsp:rs", Array ("@param1:" & Value1, "@param2:" & Value2)) While not Rs. Eof ' output recordset content Easp.wn "ID:" & RS (0) Easp.wn "Name:" & RS (1) Easp.wn "-----" Rs.movenext () Wend Easp.wn "the Next Recordset = =" Set rs = rs. NextRecordset () ' Get next recordset While not Rs. Eof Easp.wn "ProductID:" & RS (0) Easp.wn "Photo:" & RS (1) Easp.wn "-----" Rs.movenext () Wend EASP.DB.C (RS) |