Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 DEV-Group
 DEV Discussions (General)
 members.asp
 New Topic  Topic Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 3

GauravBhabu
Advanced Member

4288 Posts

Posted - 17 October 2002 :  01:53:10  Show Profile
members.asp
Lines 85-88

SearchName = trim(chkString(Request("M_NAME"),"SQLString"))
if SearchName = "" then
	SearchName = trim(chkString(Request.Form("M_NAME"), "SQLString"))
end if

In the statement in red an unqualified call is made to Request Object, so here is what happens
quote:
If the specified variable is not in one of the preceding five collections, the Request object returns EMPTY.

All variables can be accessed directly by calling Request(variable) without the collection name. In this case, the Web server searches the collections in the following order.

QueryString
Form
Cookies
ClientCertificate
ServerVariables
If a variable with the same name exists in more than one collection, the Request object returns the first instance that the object encounters.
It is strongly recommended that when referring to members of a collection the full name be used. For example, rather than Request.(AUTH_USER) use Request.ServerVariables(AUTH_USER). This will allow the server to locate the item more quickly.

quote:
Never access the Request object unqualified (for example, Request("Data")). For items not in Request.Cookies, Request.Form, Request.QueryString, or Request.ClientCertificate, there is an implicit call to Request.ServerVariables. The Request.ServerVariables collection is much slower than the other collections.


In view of the above, IMO the following will also achieve the objective as intended and will be more efficient.
dim SearchName
SearchName = Trim(Request.QueryString("M_NAME"))
if SearchName = "" then	SearchName = Trim(Request.Form("M_NAME"))
SearchName = Trim(chkString(SearchName, "SQLString"))

CSS and HTML4.01 Compilant Snitz Forum . ForumSquare . Rakesh Jain

It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying.

Prayer Of Forgiveness
"I forgive all living beings. May all living beings forgive me!
I cherish the friendliness towards all and harbour enmity towards none." -- Aavashyaka Sutra(Translated)

Edited by - GauravBhabu on 17 October 2002 01:56:32

RichardKinser
Snitz Forums Admin

USA
16655 Posts

Posted - 17 October 2002 :  02:05:43  Show Profile
since we have multiple instances of only using Request, it might be better to write a function for this.
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 17 October 2002 :  02:19:39  Show Profile
You mean something like this
function CheckRequest(strVariable, intRequestType)
    dim strValue
    strValue = ""
    Select Case intRequestType
     Case 1
        strValue = Request.QueryString(strVariable)
     Case 2
        strValue = Request.Form(strVariable)
     Case 3
        strValue = Request.Cookies(strVariable)
     Case 4
        strValue = Request.ClientCertificate(strVariable) 
     Case 5
        strValue = Request.ServerVariables(strVariable)
    End select
    CheckRequest = strValue  
end function
Go to Top of Page

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 17 October 2002 :  02:48:57  Show Profile  Visit Gremlin's Homepage
I don't think that writing a function to handle it is the way to go.

The reason I say this is becuase your effectively emmulating via code exactly what the ASP handler is doing internally when it comes accross an unqalified collection object. I'm pretty confident the code will run slower than the ASP.dll does.

Kiwihosting.Net - The Forum Hosting Specialists
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 17 October 2002 :  03:27:22  Show Profile
quote:
If a variable with the same name exists in more than one collection, the Request object returns the first instance that the object encounters.

Function is not exactly same as unqualified call to Request Object because it looks for variable in a specific collection of Request Object.
Rem -Querystring Value
myValue = CheckRequest("myVar", 1)
or
Rem -Form Field Value
myValue = CheckRequest("myVar", 2)

While an unqualified call to Request Object searches for variable in the entire collection begining with querystring and looks for it in next collection only if the variable is not found in previous collection.
Go to Top of Page

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 17 October 2002 :  03:57:18  Show Profile  Visit Gremlin's Homepage
True that was poorly worded, but I still don't think the use of a function to get around proper coding is the right approach to take.

Kiwihosting.Net - The Forum Hosting Specialists

Edited by - Gremlin on 17 October 2002 03:58:04
Go to Top of Page

RichardKinser
Snitz Forums Admin

USA
16655 Posts

Posted - 17 October 2002 :  04:12:46  Show Profile
I was thinking something like this:

function chkRequest(strVariable)
	dim strValue
	strValue = ""
	strValue = Trim(Request.QueryString(strVariable))
	if strValue = "" then strValue = Trim(Request.Form(strVariable))
	chkRequest = strValue
end function

Then you could replace this:

dim SearchName
SearchName = Trim(Request.QueryString("M_NAME"))
if SearchName = "" then	SearchName = Trim(Request.Form("M_NAME"))
SearchName = Trim(chkString(SearchName, "SQLString"))

with this:

dim SearchName
SearchName = Trim(chkString(chkRequest("M_NAME"), "SQLString"))
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 17 October 2002 :  04:19:35  Show Profile  Visit HuwR's Homepage
One question, how does that really help, since you are still checing the query object then the form object in exactly the same way as the asp engine, those objects are refered to as request("") because they may be returned as either the querystring or the form so you are not gaining anything by checking one and then the other, since that is already done for you.
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 17 October 2002 :  07:06:04  Show Profile
I agree, using a function may not be any better but there is a differnce between making two qualified calls and one unqualified call.

Request("M_NAME") will not check the Request.Form("M_NAME"), if it has already found the Request.Querystring("M_NAME"). So the suggestion in my first post seems to be more efficient.
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 17 October 2002 :  07:32:29  Show Profile  Visit HuwR's Homepage
I know, that is the whole point, if the string is passed in the querystring, it uses it, if not it checks the form and uses that, this is because members.asp can recieve M_NAME from either the query string or the form

if as your code suggests it finds it in querystring, you are executing an unnesesary if comparison, since if you used request("M_NAME") and it finds it in the querystring, it stops, but your code retrieves the querystring and then checks if it is empty. an extra line of code.
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 17 October 2002 :  07:50:57  Show Profile
Looking at the current code, it looks like the intention is to check for the
Request.Form("M_NAME")

only if
Request.QueryString("M_NAME")= ""

There may be a scenario when both
Request.QueryString("M_NAME")
and
Request.Form("M_NAME")

exist, and
Request.QueryString("M_NAME") = ""

while
Request.Form("M_NAME") = "something"


In such a scenario, the following statement
SearchName = trim(chkString(Request("M_NAME"),"SQLString"))
Returns (SearchName = "")

and the following statements
SearchName = Trim(Request.QueryString("M_NAME"))
if SearchName = "" then	SearchName = Trim(Request.Form("M_NAME"))
SearchName = Trim(chkString(SearchName, "SQLString"))

Returns (SearchName = "something")




Go to Top of Page

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 17 October 2002 :  09:26:54  Show Profile  Visit HuwR's Homepage
I am not aware of anywhere that the querystring would pass M_NAME= without a value to members.asp

so really all you require is

SearchName = trim(chkString(Request("M_NAME"),"SQLString"))

I am not saying this is correct in all cases, but for members.asp, it is either in the querystring or the form, but never both.

which will pick up either option, since when the form is executed there is no querystring just the form object

Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 17 October 2002 :  09:58:57  Show Profile
quote:
Originally posted by HuwR

I am not aware of anywhere that the querystring would pass M_NAME= without a value to members.asp

so really all you require is

SearchName = trim(chkString(Request("M_NAME"),"SQLString"))

I am not saying this is correct in all cases, but for members.asp, it is either in the querystring or the form, but never both.

which will pick up either option, since when the form is executed there is no querystring just the form object



Correct HUWR, but there is also a scenario when M_NAME is neither in querystring and nor in Form Object and in that case Request("M_NAME") will search for "M_NAME" in all collections of Request Object.
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 17 October 2002 :  10:32:49  Show Profile
forum/members.asp
More... Loading members.asp without any value in querystring and Form Object results in 8 calls to Request Object, when the following statements are encountered in members.asp. Since these are unqualified calls it multiplies to 40 (8 x 5).

Lines 74-101
if trim(chkString(Request("method"), "SQLString")) <> "" then
	SortMethod = trim(chkString(Request("method"),"SQLString"))
	strSortMethod = "&method=" & SortMethod
	strSortMethod2 = "?method=" & SortMethod
end if

if trim(chkString(Request("mode"), "SQLString")) <> "" then
	strMode = trim(chkString(Request("mode"),"SQLString"))
	if strMode <> "search" then strMode = ""
end if

SearchName = trim(chkString(Request("M_NAME"), "SQLString"))
if SearchName = "" then
	SearchName = trim(chkString(Request.Form("M_NAME"), "SQLString"))
end if

if Request("UserName") <> "" then
	if IsNumeric(Request("UserName")) = True then srchUName = cLng(Request("UserName")) else srchUName = "1"
end if
if Request("FirstName") <> "" then
	if IsNumeric(Request("FirstName")) = True then srchFName = cLng(Request("FirstName")) else srchFName = "0"
end if
if Request("LastName") <> "" then
	if IsNumeric(Request("LastName")) = True then srchLName = cLng(Request("LastName")) else srchLName = "0"
end if
if Request("INITIAL") <> "" then
	if IsNumeric(Request("INITIAL")) = True then srchInitial = cLng(Request("INITIAL")) else srchInitial = "0"
end if


Rem -Check if querystring or Form object exist

If Request.Form = "" And Request.Querystring = "" then
 strMode = "" : SearchName = ""
 srchUName = ""
 srchFName = ""
 srchLName = ""
 srchInitial = ""
else
 Code between Lines 74-101
end if

Edited by - GauravBhabu on 17 October 2002 10:41:26
Go to Top of Page

davemaxwell
Access 2000 Support Moderator

USA
3020 Posts

Posted - 17 October 2002 :  10:57:01  Show Profile  Visit davemaxwell's Homepage  Send davemaxwell an AOL message  Send davemaxwell an ICQ Message  Send davemaxwell a Yahoo! Message
I've got to agree with making it a function that only limits the checks to what it needs to do. Why make unnecessary calls if needed? Plus, some of this code doesn't make a whole lotta sense.

quote:

if trim(chkString(Request("method"), "SQLString")) <> "" then
	SortMethod = trim(chkString(Request("method"),"SQLString"))
	strSortMethod = "&method=" & SortMethod
	strSortMethod2 = "?method=" & SortMethod
end if

if trim(chkString(Request("mode"), "SQLString")) <> "" then
	strMode = trim(chkString(Request("mode"),"SQLString"))
	if strMode <> "search" then strMode = ""
end if
if Request("UserName") <> "" then
	if IsNumeric(Request("UserName")) = True then srchUName = cLng(Request("UserName")) else srchUName = "1"
end if
if Request("FirstName") <> "" then
	if IsNumeric(Request("FirstName")) = True then srchFName = cLng(Request("FirstName")) else srchFName = "0"
end if
if Request("LastName") <> "" then
	if IsNumeric(Request("LastName")) = True then srchLName = cLng(Request("LastName")) else srchLName = "0"
end if
if Request("INITIAL") <> "" then
	if IsNumeric(Request("INITIAL")) = True then srchInitial = cLng(Request("INITIAL")) else srchInitial = "0"
end if




These are all doing a double set of requests each time. Moving it to a local variable once and then check it would be best.

quote:


SearchName = trim(chkString(Request("M_NAME"), "SQLString"))
if SearchName = "" then
	SearchName = trim(chkString(Request.Form("M_NAME"), "SQLString"))
end if



Uhhmmmm...if it can't find it in the generic request object on the first check, it's not going to find it in the request.form object since the generic checks request.form.
quote:

Rem -Check if querystring or Form object exist

If Request.Form = "" And Request.Querystring = "" then
 strMode = "" : SearchName = ""
 srchUName = ""
 srchFName = ""
 srchLName = ""
 srchInitial = ""
else
 Code between Lines 74-101
end if




Nice idea here. If the objects are empty, then why check any further?

Dave Maxwell
Barbershop Harmony Freak
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 17 October 2002 :  10:59:03  Show Profile
Here is my solution...
dim SortMethod, strSortMethod, strSortMethod2 
dim strMode
dim SearchName
dim srchUName, srchFName, srchLName, srchInitial

if ((Request.Form = "") And (Request.QueryString = "")) then
 strMode = "" : SearchName = ""
 srchUName = "" : srchFName = "" 
 srchLName = "" : srchInitial = ""
else
 Call InitRequestVars()
end if
sub InitRequestVars()
    dim objRequest
    if Request.QueryString <> "" then 
     Set objRequest = Request.QueryString
    else
     Set objRequest = Request.Form
    end if
    SortMethod = Trim(objRequest("method"))
    if SortMethod <> "" then
    	SortMethod = Trim(chkString(SortMethod, "SQLString"))
    	strSortMethod = "&method=" & SortMethod
    	strSortMethod2 = "?method=" & SortMethod
    end if
    strMode = (objRequest("mode"))
    strMode = Trim(chkString(strMode, "SQLString"))
    if strMode <> "search" then strMode = ""
 
    SearchName = objRequest("M_NAME")
    SearchName = Trim(chkString(SearchName, "SQLString"))
 
    srchUName = objRequest("UserName")
    if srchUName <> "" then
    	if IsNumeric(srchUName) then srchUName = cLng(srchUName) else srchUName = "1"
    end if
    srchFName = objRequest("FirstName")
    if srchFName <> "" then
    	if IsNumeric(srchFName) then srchFName = cLng(srchFName) else srchFName = "0"
    end if
    srchLName = objRequest("LastName")
    if srchLName <> "" then
    	if IsNumeric(srchLName) then srchLName = cLng(srchLName) else srchLName = "0"
    end if
    srchInitial = objRequest("INITIAL")
    if srchInitial <> "" then
    	if IsNumeric(srchInitial) then srchInitial = cLng(srchInitial) else srchInitial = "0"
    end if
    Set objRequest = Nothing
end sub
Go to Top of Page
Page: of 3 Previous Topic Topic Next Topic  
Next Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.19 seconds. Powered By: Snitz Forums 2000 Version 3.4.07