(TR) It is the first known compact, Classic ASP utility library (according to my research). It has a structure that shortens the operations you frequently perform, helps you speed up your database work and software development stages with practicality, and makes your developments easier. You can integrate it with your existing libraries, develop and distribute it. Please don't forget to give it a Star and add it to your Watch list.
(EN) First Classic ASP Coding Helper Utility
(TR) First, include the file from its physical path into your project file. (EN) ...
<!--#include file= "/{path}/casphelper.asp" -->
(TR) If you want to start the library yourself, add the code below to your project to run first (EN) ...
< %
Set Query = New QueryManager
% >
(TR) Now you just need to use the Query variable for all your operations. (EN) ...
< %
Dim Query
Set Query = New QueryManager
Query.Debug = False
Query.Host = "localhost"
Query.Database = "my_db_name"
Query.User = "my_db_username"
Query.Password = "MyS3c3tP4ssw0d"
Query.Connect()
% >
If we want to INSERT or UPDATE a SQL query, we need to keep our form input name values the same as the column names of the relevant table. The library does a few things here.
As a result, two types of responses are returned from the library.
(TR) The RunExtend function is a simple return function and the INSERT parameter returns the primaryKey (ID) value (INT) of the row added as a result of the operation. This result informs whether the INSERT operation was successful or not. (EN) ...
Query.RunExtend( "INSERT" , "table_name" , Null)
(TR) The following structure can be used for example use. (EN) ...
< %
If Query.Data( "Cmd" ) = "InsertSample" Then
Dim QueryResult
QueryResult = Query.RunExtend( "INSERT" , "tbl_users" , Null)
If IsNumeric( QueryResult ) Then
Response.Write "Başarılı / Success"
Response.Write "ID: " & QueryResult
Else
Response.Write "Başarısız / Failed"
End If
End If
% >
(TR) The form structure should be as follows. (EN) ...
< form action =" /?Cmd=InsertSample " method =" post " >
< input name =" NAME " value =" Anthony Burak " />
< input name =" SURNAME " value =" Dursun " />
< input name =" BIRTHDAY " value =" 24.07.1986 " />
< button type =" submit " > Insert </ button >
</ form >
(TR) The database structure is as follows (EN) ...
FIELD NAME | TYPE |
---|---|
ID | (INT) Primary Key |
NAME | (VARCHAR) |
SURNAME | (VARCHAR) |
BIRTHDAY | (DATE) |
(TR) The RunExtend function is a simple return function and the UPDATE parameter returns true or false (boolean) as a result of the operation. This result informs whether the UPDATE operation was successful or not (EN)...
Query.RunExtend( "UPDATE" , "table_name" , "ID={ID}" )
(TR) The following structure can be used for example use. (EN) ...
< %
If Query.Data( "Cmd" ) = "UpdateSample" Then
Dim QueryResult
QueryResult = Query.RunExtend( "UPDATE" , "tbl_uyeler" , "ID={ID}" )
If QueryResult = True Then
Response.Write "Başarılı / Success"
Else
Response.Write "Başarısız / Failed"
End If
End If
% >
(TR) The form structure should be as follows. (EN) ...
< form action =" /?Cmd=UpdateSample&ID=123 " method =" post " >
< input name =" NAME " value =" Anthony Burak " />
< input name =" SURNAME " value =" Dursun " />
< input name =" BIRTHDAY " value =" 24.07.1986 " />
< button type =" submit " > Update </ button >
</ form >
(TR) The database structure is as follows (EN) ...
FIELD NAME | TYPE |
---|---|
ID | (INT) Primary Key |
NAME | (VARCHAR) |
SURNAME | (VARCHAR) |
BIRTHDAY | (DATE) |
(TR) The combination of Collector and Run commands in the first version of the library is as follows. The CollectForm function collects the Request.Form parameters that come with the FORM Post method and combines them for INSERT or UPDATE. There is no control mechanism. Parameter error returns to Error Raise. (EN) ...
< %
If Query.Data( "Cmd" ) = "UpdateSample" Then
Query.CollectForm( "INSERT" )
Query.AppendRows = "EKSTRA1, EKSTRA2"
Query.AppendValues = "'Manuel Eklenecek Veri 1', 'Manuel Eklenecek Veri 2'"
Query.Run( "INSERT INTO tbl_tableName(" & Query.Rows & ") VALUES(" & Query.Values & ")" )
Query.Go( "?Msg=Success" )
End If
% >
(TR) Returns the result of a SQL query as true or false . It is used as an EOF substitute in traditional methods. (EN) ...
< %
Dim QueryResult
QueryResult = Query.RecordExist( "SELECT ID FROM tbl_users WHERE ID = 1" )
If QueryResult = True Then
Response.Write "Record Exist"
Else
Response.Write "Record Not Exist"
End If
% >
(TR) Enables the maximum ID (PrimaryKey) value to be returned in any table and condition. There is no error checking. (EN) ...
Query.MaxID( "tbl_tableName" )
(TR) For conditional situations (EN) ...
Query.MaxID( "tbl_tableName WHERE EMAIL = '[email protected]'" )
(TR) The only customization for this function is that the data to be received with Request.Querystring can be replaced . If the URL structure is /?Cmd=Update&ID=123, the {ID} parameter is updated to 123 in the query. . It implements the standard obj.Execute(sql) parameter. (EN) ...
< %
Query.Run( "SELECT ID FROM tbl_tableName WHERE ID = {ID} " )
Query.Run( "SELECT ID FROM tbl_tableName WHERE ID = " & Query.Data( "ID" ) & " " )
Query.Run( "SELECT ID FROM tbl_tableName WHERE ID = 1 " )
% >
(TR) If you want to get a form or querystring data, you can get it as Query.Data("key") or inline as {key} . Your software will capture all parameters even in 404 url structure. Can be used instead of Requet.Form(key) or Request.QueryString(key). (EN) ...
< %
Dim SampleValue
SampleValue = Query.Data( "ID" )
% >
(TR) If the existence of the data is not found (Null, Empty), the result can always be returned with Empty. (EN) ...
/script.asp?Cmd=Test&Data1=value&Data2=&Data3=value3
/ 404 url/params/?Cmd=Test&Data1=value&Data2=&Data3=value3
< %
Response.Write Query.Data( "Cmd" ) ' return Test (String)
Response.Write Query.Data( "Data1" ) ' return value (String)
Response.Write Query.Data( "Data2" ) ' return
Response.Write Query.Data( "Data3" ) ' return value3 (String)
% >
(TR) Response.Redirect is a command that you can use instead of "url.asp?some=string" after completing your transaction. You can process current Request data. Parametric Updates can be used to retrieve form or Querystring parameters. (EN) ...
< %
Query.Go( "url.asp?some=string" )
Query.Go( "url.asp?some={ID}" )
% >
(TR) Instead of using the standard Response.Write("test") , Query.Echo("test") can be used. (EN) ...
< %
Query.Echo( "test" )
% >
(TR) Query.Kill() can be used instead of the standard Response.End() . (EN) ...
< %
Query.Kill()
% >
(TR) It can check the existence of any variable. Performs IsNull, IsEmpty, Len()>0 checks and returns true or false (boolean) result (EN) ...
< %
str_value1 = ""
str_value2 = 2
If Query.Exist(str_value1) = True Then
' return true
End If
If Query.Exist(str_value2) = False Then
' return false
End If
% >
(TR) Searches for any string data in an array group. It performs an exact match check and applies automatic Trim(). If a result is found, the index number is returned. If no result is found, Null result is returned. (EN) ...
< %
Dim str_array
str_array = Array( "test" , "apple" , "fruit" , "banana" , "mercedes" )
Dim QueryResult
QueryResult = Query.FindInArray( "apple" , str_array)
If IsNull( QueryResult ) Then
Query.Echo "Not Found"
Else
Query.Echo "apple found in array index: " & QueryResult
End If
% >
(TR) In some cases, you can limit access to the relevant transaction area only by certain methods. For example, if you use Method="POST" for a form, you can confirm in the greeting that the method is indeed "POST". (EN) ...
< %
If Query.AllowedMethod( "POST" ) = False Then
Query.Echo "Only POST Method Allowed"
Query.Kill
End If
% >