SoFunction
Updated on 2025-04-09

EasyASP v1.5 release (including database operation class, original) page 1/2

The Easp class provides a large number of practical ASP general processes and methods, which can simplify most ASP operations. Currently, only VBScript version is available, and the JScript version may be available in the future.
EasyASP v1.5 (updated on 2008-10-22)
New features:
1. Encapsulate the database control class (original) into the Easp class, all of which are called and can also be used independently.
2. Added a new MSSQL stored procedure call method, which can flexibly call stored procedures and return the return value, record set and parameter output.
3. New method is added, which can connect to the database according to the customized connection string.
4. Added a new method to output the database record set in Json format.
5. Added new methods to generate a random number or random string without duplication
6. Added abbreviation methods for various database operation methods, which saves code writing time.
7. A large number of practical methods have been added to the Easp class, such as secure acquisition of values, anti-Sql injection, server-side form verification, etc.
Other updates:
1. Optimize automatic number acquisition, improve efficiency by more than 20 times, and the larger the data volume, the more obvious it is.
2. Modify the database connection method to be more in line with daily description habits.
3. Modify the record set method to obtain fewer parameters. Fixed the bug that the conditional error was reported using array.
4. Modify and optimize the deletion record method. Currently, there are only two parameters.
5. Modified the error debugging method and added Debug global attribute control error display.
Update instructions:
I used to write a database control class and received some feedback. Some friends sent me an email to tell me some improvement methods. I am very grateful to them. And I saw a message in the comments of the original post saying "I have remembered the parameters, and the SQL statement has been written long ago", which directly pointed out the embarrassment. Indeed, although VBS does not have the arguments attribute, it is not a good idea to use too many parameters. So I spent some time rewritten a lot of the code of this class. On the premise that the function can only be stronger but not weaker, a method has only 3 parameters at most. In addition, a new method is added to call MSSQL stored procedures, which can flexibly call stored procedures and return one or more record sets, output parameters and return values ​​as needed. Of course, learning from the lesson, this method has only two parameters. Now they are all encapsulated in this new guy named EasyASP. As the name suggests, it is nothing more than thinking that everything is simpler.
There is another more embarrassing thing, that is, VBScript is not an object-oriented language, so this class is actually just a wrapper of some processes and methods, which is convenient for use, so most of them can be proposed for use alone. Of course, if necessary, it can also be encapsulated as a wsc or dll component for use.
=================================================================
Instructions for use
=================================================================
1. How to use:
(1) All calls to the Easp class are already included, so you only need to introduce the file at the top of the page, such as:
<!--#include file="inc/easp/" -->
or:
<!--#include virtual="/inc/easp/"-->
(2) This class has been instantiated and does not need to be instantiated separately. You can just call it directly using the Easp. prefix, such as:
("Test String") or ("Table:ID")
(3) If you want to operate multiple databases at the same time, please instantiate a new easpdb object, such as:
Dim db2 : Set db2 = New EasyASP_db
= (0,dbase,server)
2. Parameter convention:
(1) Array parameters: Since VBScript does not have arguments attribute and cannot use dynamic parameters, in the code that involves database data in this class, Array (array) is used to achieve this effect. Some parameters in this class can use arrays (noted in the parameter description), but when using arrays, you should refer to the following format:
Array("Field1:Value1", "Field2:True", "Field3:100")
Yes, it's a bit like json format, if variables are involved, then that's it:
Array("Field1:" & Value1, "Field2:" & Value2, "Field3:" & Value3)
It can be said that almost all the content related to database fields in this class can be set in the above array format or obtain the content, including calling the stored procedure to pass. The biggest advantage of this class is that you don’t have to consider the type of the field when using it. Just follow the field with a colon and follow the corresponding value. If you often write ASP programs, you will soon feel the charm of using this method. In addition to not considering the data type, it is also convenient to add and delete conditions at any time. Here is an example to illustrate this usage:
For example, how to add new records:
"Table", Array("FieldsA:test data","FieldsB:"&Now(),"FieldsC:True")
There are only two parameters, one is the table name and the other is such an array parameter. If you want to change the database structure, it will be very simple to modify the above program code.
(2) Shared parameters (separated by special symbols): It is also considered that parameters should be minimized. If some parameters can be missing in many cases, there is no need to add a parameter specifically for them. In this class, special symbols such as colon (:) are used to separate multiple values ​​in a parameter to achieve the effect of passing multiple parameters. Let me give you a few examples to illustrate, and you can also preview some of the advantages of using this class:
For example, how to establish an MSSQL database connection object:
Set Conn = (0,"Database","User:Password@ServerAddress")
It's very clear at a glance, right? Here we use: and @ to separate several parameters and put them in the same parameter. In addition, if the Access database has a password, just enter it in the third parameter, there are no other parameters.
For example, the method of obtaining a record set:
Set rs = ("Table:FieldsA,FieldsB,FieldsC:20","ID > 10","ID Desc")
The first parameter contains the table name, the field to be taken and the number of records to be taken. Because fields and records can often be omitted, I simply omitted the parameters, so there are many fewer parameters to be remembered.
For example, there is a GetUrl() method to get the address of this page in many places. It has been seen in many places, right? However, this method in this class contains a parameter, and many results can be obtained through this parameter. See example:
12Next pageRead the full text