Easyasp v1.5 (including database operations, formerly clsdbctrl. asp) page 1/2

Source: Internet
Author: User

The EASP class provides a large number of practical ASP general processes and methods, which can simplify most ASP operations. Currently, only VBScript is available, and JScript may be available in the future.
Easyasp v1.5 (updated on)
New features:
1. encapsulate the Database Control class (formerly clsdbctrl. asp) into the EASP class, which is called through EASP. DB and can be used independently.
2. added the MSSQL Stored Procedure calling method to flexibly call the stored procedure and return the returned values, record sets, and output parameters.
3. added the DB. creatconn method to connect to the database based on the custom connection string.
4. added the DB. JSON method to output the database record set in JSON format.
5. The db. Rand and DB. randstr methods are added to generate a random number or random string that is not repeated.
6. added a simplified method for database operations to save writing time. Code Time.
7. A large number of new practical methods are added to the EASP class, such as obtaining values safely, preventing SQL injection, and verifying forms on the server.
Other updates:
1. Optimize the database. autoid to automatically obtain the number, and increase the efficiency by more than 20 times. The larger the data volume, the more obvious.
2. Modify the database connection method of DB. openconn to conform to the daily description habits.
3. Modify dB. getrecord to retrieve the record set with fewer parameters. Fixed the bug of array errors.
4. Modify and optimize the DB. deleterecord deletion method. Currently, there are only two parameters.
5. modified the error debugging method and added the debug global attribute Control Error display.
Update description:
I used to write a clsdbctrl. ASP database control class and received some feedback. Some friends sent me an email to tell me some improvement methods. Thank you very much for them. In my post, I saw a message saying "the SQL statements have been written before the time when parameters are recorded", which directly points out the embarrassment. Indeed, although vbs does not have the arguments attribute, however, using too many parameters is not a good idea. So I spent some time rewriting a lot of code in this class. To ensure that the function is only stronger and not weaker, a method can have at most three parameters. In addition, a new method is added to call the MSSQL Stored Procedure, which can call the Stored Procedure flexibly and return one or more Record Sets, output parameters, and return values as needed. Of course, I learned the lesson, this method has only two parameters. It is now encapsulated in this new guy named easyasp. As the name suggests, it is nothing more than thinking that everything is simple.
Another embarrassing thing is that VBScript is not an object-oriented language. Therefore, this class is actually encapsulated by some processes and methods for ease of use, therefore, most of the methods and processes can be used independently. Of course, you can package it into WSC or DLL components if necessary.
========================================================== ======================================
Instructions for use
========================================================== ======================================
1. Usage:
(1) all calls to the EASP class are included in EASP. asp, so you only need to introduce the file at the top, such:
<! -- # Include file = "INC/EASP. asp" -->
Or:
<! -- # Include virtual = "/INC/EASP. asp" -->
(2) the class has been instantiated and can be called directly using the EASP. prefix without the need to be instantiated separately. For example:
EASP. Wn ("test string") or EASP. DB. autoid ("table: ID ")
(3) to operate multiple databases at the same time, create a new easpdb object, for example:
Dim DB2: Set DB2 = new easyasp_db
Db2.dbconn = db2.openconn (0, dBase, server)
2. Parameter conventions:
(1) array parameters: Because VBScript does not have the arguments attribute and cannot use dynamic parameters, array (array) is used in the Code related to database data in this class) to achieve this effect. Some parameters in this class can use arrays (specified in the parameter description), but the following format should be used when using Arrays:
Array ("field1: value1", "field2: True", "field3: 100 ")
Yes, it is a bit like the JSON format. If variables are involved, it will be like this:
Array ("field1:" & value1, "field2:" & value2, "field3:" & value3)
It can be said that almost all content related to database fields in this class can be set with the above array format or get the content, including the parameters to be passed when the stored procedure is called. The biggest advantage of this class is that you do not need to consider the field type when using it. After a field is followed by a colon, you can keep up with the corresponding value. If you write ASP frequently Program You will soon feel the charm of using this method. In addition to data types, it is also very convenient to add and delete conditions at any time. Here is an example to illustrate this usage:
For example, to add a new record:
EASP. DB. addrecord "table", array ("fieldsa: Test Data", "fieldsb:" & now (), "fieldsc: True ")
There are only two parameters, one is the table name, and the other is the array parameter. If you want to change the database structure, it is very easy to modify the above program code.
(2) shared parameters (separated by special symbols): We also consider minimizing the number of parameters. If some parameters are not available in many cases, there is no need to add a parameter for it. In this class, special characters such as colon (:) are used to separate multiple values of a parameter to pass multiple parameters. Here are a few examples to illustrate. You can also preview some advantages of using this class:
For example, you can use the following method to create an MSSQL database connection object:
Set conn = EASP. DB. Open (0, "Database", "User: password @ serveraddress ")
It is clear that it is correct. Here, several parameters are separated with @ and placed in the same parameter. In addition, if the ACCESS database has a password, enter the password in the 3rd parameters. No other parameters are available.
Another example is how to obtain the record set:
Set rs = EASP. DB. getrecord ("table: fieldsa, fieldsb, fieldsc: 20", "id> 10", "id DESC ")
Among them, the 1st parameters contain the table name, the fields to be retrieved, and the number of records to be retrieved, because the number of fields and records can be omitted in many cases, therefore, we simply omit the parameters, which requires a lot less parameters.
For example, there is a geturl () method in this class to get the address of this page. It has been seen in many places, but this method in this class has a parameter, you can obtain many results using this parameter. See the example below:
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.