Easyasp v1.5 Release (contains database operations class, original clsdbctrl.asp) 1th/2 page _asp class class

Source: Internet
Author: User
Tags db2 mssql sql injection access database
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.
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, 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:
<!--#include file= "inc/easp/easp.asp"-->
Or:
<!--#include virtual= "/inc/easp/easp.asp"-->
(2) The class has been instantiated without any further instantiation, directly using the easp. Prefix invocation, such as:
Easp.wn ("Test String") or Easp.db.AutoId ("Table:id")
(3) If you want to operate multiple databases at once, instantiate the new Easpdb object, such as:
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:
Array ("Field1:value1", "Field2:true", "field3:100")
Yes, a bit like JSON format, if it involves variables, that's it:
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:
Easp.db.AddRecord "Table", Array ("FIELDSA: Test Data", "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. In this class, special symbols such as colons (:) separate multiple values in one parameter are used to pass multiple arguments. 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:
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:
Set rs = Easp.db.GetRecord ("table:fieldsa,fieldsb,fieldsc:20", "ID > Ten", "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:
Current 1/2 page 12 Next read the full text
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.