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 Bug Reports (Closed)
 ADJUST (3.1final): chkForumModerator Function
 Forum Locked  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Darker
Starting Member

USA
7 Posts

Posted - 15 October 2000 :  18:54:48  Show Profile
File: inc_functions.asp
Function: chkForumModerator()

Description:
The function as distributed performs an unnecessary query.

Detail:

function chkForumModerator(fForum_ID, fMember_Name)

'## Forum_SQL
strSql = "SELECT " & strMemberTablePrefix & "MEMBERS.MEMBER_ID "
strSql = strSql & " FROM " & strMemberTablePrefix & "MEMBERS "
if strAuthType = "db" then
strSql = strSql & " WHERE " & strMemberTablePrefix & "MEMBERS.M_NAME = '" & fMember_Name & "'"
else
if strAuthType = "nt" then
strSql = strSql & " WHERE " & strMemberTablePrefix & "MEMBERS.M_USERNAME = '" & fMember_Name & "'"
end if
end if

set rsUsrName = my_Conn.Execute (strSql)

if rsUsrName.EOF or rsUsrName.BOF or not(ChkQuoteOk(fMember_Name)) or not(ChkQuoteOk(fForum_ID)) then
chkForumModerator = "0"
rsUsrName.close
exit function
else
MEMBER_ID = rsUsrName("MEMBER_ID")
rsUsrName.close
end if

set rsUsrName = nothing

'## Forum_SQL
strSql = "SELECT * "
strSql = strSql & " FROM " & strTablePrefix & "MODERATOR "
strSql = strSql & " WHERE FORUM_ID = " & fForum_ID & " "
strSql = strSql & " AND MEMBER_ID = " & MEMBER_ID

set rsChk = my_Conn.Execute (strSql)

if rsChk.bof or rsChk.eof then
chkForumModerator = "0"
else
chkForumModerator = "1"
end if

rsChk.close
set rsChk = nothing

end function


The code in red can be combined with the 2nd sql query to simplify the operation of this function, and speed it up at the same time.

Proposed replacement:

function chkForumModerator(fForum_ID, fMember_Name)

'## Forum_SQL
strSql = "SELECT mo.FORUM_ID "
strSql = strSql & " FROM " & strTablePrefix & "MODERATOR mo, " & strTablePrefix & "MEMBERS me "
strSql = strSql & " WHERE mo.FORUM_ID = " & fForum_ID & " "
strSql = strSql & " AND mo.MEMBER_ID = me.MEMBER_ID "
if strAuthType = "db" then
strSql = strSql & " AND me.M_NAME = '" & fMember_Name & "'"
else
if strAuthType = "nt" then
strSql = strSql & " AND me.M_USERNAME = '" & fMember_Name & "'"
end if
end if

set rsChk = my_Conn.Execute (strSql)

if rsChk.bof or rsChk.eof then
chkForumModerator = "0"
else
chkForumModerator = "1"
end if

rsChk.close
set rsChk = nothing
end function


By performing a join between the Moderator table and the Members table during the check for existence of a record for the current member id in a given forum, the database performs the 'match this user's name to his id and see if that's in the moderator table for this forum' logic faster than ASP can create the recordset object, open it, check it, close it, etc. Further, by specifically enumerating a field for the query to select from the Moderators table, you save the database time figuring out what fields are there. You really only need one field, because you're only checking for existence of a matching record - not for any specific data in it.

Note: This mod was designed for use with MS Sql Server 7 and has not been tested for compatibility with MS Access or MySql, but it's straight SQL, so it ought to work.

Darker


Reinsnitz
Snitz Forums Admin

USA
3545 Posts

Posted - 16 October 2000 :  22:02:12  Show Profile  Visit Reinsnitz's Homepage  Send Reinsnitz an AOL message  Send Reinsnitz an ICQ Message  Send Reinsnitz a Yahoo! Message
anyone know any possibility of incompatibility with MySQL or MS Access 97/2000 or MS SQL 6.5/2000? Or better yet... a test would be better to verify cross compatibility.

Reinsnitz (Mike)
><)))'>

Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make your path straight.
-- Proverbs 3:5-6
Go to Top of Page

Reinsnitz
Snitz Forums Admin

USA
3545 Posts

Posted - 25 October 2000 :  19:07:09  Show Profile  Visit Reinsnitz's Homepage  Send Reinsnitz an AOL message  Send Reinsnitz an ICQ Message  Send Reinsnitz a Yahoo! Message
<sanity check please>

Reinsnitz (Mike)
><)))'>

"I no longer call you servants, because a servant does not know his master's business. Instead I have called you friends..."
-- John 15:15
Go to Top of Page

davemaxwell
Access 2000 Support Moderator

USA
3020 Posts

Posted - 26 October 2000 :  07:59:16  Show Profile  Visit davemaxwell's Homepage  Send davemaxwell an AOL message  Send davemaxwell an ICQ Message  Send davemaxwell a Yahoo! Message
I can try it on Access 2000. If it works there, it'll work in 97 since they're basically the same.

It does look like a straight join, so it should work on all versions of SQL.

Dave Maxwell
--------------
When's the next meeting of Snitzaholics Anonymous
Go to Top of Page

Reinsnitz
Snitz Forums Admin

USA
3545 Posts

Posted - 26 October 2000 :  14:04:14  Show Profile  Visit Reinsnitz's Homepage  Send Reinsnitz an AOL message  Send Reinsnitz an ICQ Message  Send Reinsnitz a Yahoo! Message
Sorry... I was just geting back into the dev team stuff when I posted the original reply on the 16th... and was in crisis mode the other day with the other one... after looking it over, the mo. and me. threw me off with a casual glance... but it is a simple thing... sorry for the confusion on my part :) will do this very soon


Reinsnitz (Mike)
><)))'>

"I no longer call you servants, because a servant does not know his master's business. Instead I have called you friends..."
-- John 15:15
Go to Top of Page

davemaxwell
Access 2000 Support Moderator

USA
3020 Posts

Posted - 26 October 2000 :  14:47:34  Show Profile  Visit davemaxwell's Homepage  Send davemaxwell an AOL message  Send davemaxwell an ICQ Message  Send davemaxwell a Yahoo! Message
OK. I won't worry about it then....

Dave Maxwell
--------------
When's the next meeting of Snitzaholics Anonymous
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 24 June 2001 :  10:54:42  Show Profile  Visit HuwR's Homepage
Implemented in v3.3 source

Go to Top of Page
  Previous Topic Topic Next Topic  
 Forum Locked  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.14 seconds. Powered By: Snitz Forums 2000 Version 3.4.07