Forums

This topic is locked

UltraDev Newbie -- Navbar Live object Code

Posted 29 Jul 2002 12:02:50
1
has voted
29 Jul 2002 12:02:50 john weare posted:
I am a UltraDev Newbie trying to understand the way the MM code takes into account that cursorType=0 returns a record count of -1. Their code works around this and goes through an iterative process to arrive at this. What I don't understand is the:

If (MM_rs.CursorType > 0) Then
MM_rs.MoveFirst
Else
MM_rs.Requery
End If

What happens during the requery?

I have submitted the standard code (with extra comments - that may be incorrect do to my limited knowledge of VBscript) based on a situation that the total records is 15 and the displayed records is 10. I don't understand how the code arrives at returning the proper values. Any help would be appreciated
<pre id=code><font face=courier size=2 id=code>
&lt;%@LANGUAGE="VBSCRIPT"%&gt;
&lt;!--#include file="../../Connections/KoolKards.asp" --&gt;
&lt;%
set rsProducts = Server.CreateObject("ADODB.Recordset"
rsProducts.ActiveConnection = MM_KoolKards_STRING
rsProducts.Source = "SELECT artist, occasion, cost, ref_number FROM products ORDER BY occasion ASC"
rsProducts.CursorType = 0
rsProducts.CursorLocation = 2
rsProducts.LockType = 3
rsProducts.Open()
rsProducts_numRows = 0
%&gt;
&lt;%
Dim rsProducts_total
Dim Repeat1__numRows
Repeat1__numRows = 10
Dim Repeat1__index
Repeat1__index = 0
rsProducts_numRows = rsProducts_numRows + Repeat1__numRows
' rsProducts_numRow=10
%&gt;
&lt;%
rsProducts_total = rsProducts.RecordCount
response.write(rsProducts_total)
' rsProducts_total=-1
%&gt;

&lt;%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

' set the record count
rsProducts_total = rsProducts.RecordCount

' set the number of rows displayed on this page
' (1)rsProducts_numRow=10
' (1)rsProducts_total=-1
If (rsProducts_numRows &lt; 0) Then
rsProducts_numRows = rsProducts_total
Elseif (rsProducts_numRows = 0) Then
rsProducts_numRows = 1
End If

' set the first and last displayed record
rsProducts_first = 1
rsProducts_last = rsProducts_first + rsProducts_numRows - 1
' rsProducts_first = 1
' rsProducts_last = 10

' if we have the correct record count, check the other stats
' (1) no
If (rsProducts_total &lt;&gt; -1) Then
If (rsProducts_first &gt; rsProducts_total) Then rsProducts_first = rsProducts_total
If (rsProducts_last &gt; rsProducts_total) Then rsProducts_last = rsProducts_total
If (rsProducts_numRows &gt; rsProducts_total) Then rsProducts_numRows = rsProducts_total
End If
%&gt;
&lt;%
' *** Move To Record and Go To Record: declare variables
' (1)duplicate recordSet
Set MM_rs = rsProducts
MM_rsCount = rsProducts_total
' (1)MM_rsCount=rsProducts_total=-1
MM_size = rsProducts_numRows
' (1)MM_size=rsProducts_numRow=10
MM_uniqueCol = ""
MM_paramName = ""
MM_offset = 0
MM_atTotal = false
MM_paramIsDefined = false
If (MM_paramName &lt;&gt; "" Then
MM_paramIsDefined = (Request.QueryString(MM_paramName) &lt;&gt; ""
' (x)will evaluate true since it: Request.QueryString(MM_paramName) won't be empty
End If
%&gt;
&lt;%
' *** Move To Record: handle 'index' or 'offset' parameter

' (1) Not MM_paramIsDefined (true) MM_rsCount &lt;&gt; 0 (true)
' (2) Not MM_paramIsDefined (true) MM_rsCount &lt;&gt; 0 (true)
if (Not MM_paramIsDefined And MM_rsCount &lt;&gt; 0) then

' use index parameter if defined, otherwise use offset parameter
' (1) Not Defined
' (2) Not Defined
r = Request.QueryString("index"
If r = "" Then r = Request.QueryString("offset"
If r &lt;&gt; "" Then MM_offset = Int(r)

' if we have a record count, check if we are past the end of the recordset
' (1) No
' (2) No
' (3) MM_rsCount = 5
If (MM_rsCount &lt;&gt; -1) Then
If (MM_offset &gt;= MM_rsCount Or MM_offset = -1) Then ' past end or move last
If ((MM_rsCount Mod MM_size) &gt; 0) Then ' last page not a full repeat region
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If

' move the cursor to the selected record
' (1) No because MM_offset = 0
' (2) No because MM_offset = 0
i = 0
While ((Not MM_rs.EOF) And (i &lt; MM_offset Or MM_offset = -1))
MM_rs.MoveNext
i = i + 1
Wend
' (3) MM_offset = 5
If (MM_rs.EOF) Then MM_offset = i ' set MM_offset to the last possible record

End If
%&gt;
&lt;%
' *** Move To Record: if we dont know the record count, check the display range

' (1) Yes
If (MM_rsCount = -1) Then

' walk to the end of the display range for this page
' (1) i = 0
i = MM_offset
' (1) MM_offset + MM_size = 10
' (1) continues through file -- skips to requery
' (1) i will iterate up to 10 and then exit to requery
' (2) i will iterate up to 15, encounter EOF, and then assign new values
While (Not MM_rs.EOF And (MM_size &lt; 0 Or i &lt; MM_offset + MM_size))
MM_rs.MoveNext
' once end of file is found exit loop
' 1 will be 5
i = i + 1
Wend

' if we walked off the end of the recordset, set MM_rsCount and MM_size
' (1) No
' (2) i will iterate up to 10 and then exit to requery
If (MM_rs.EOF) Then
MM_rsCount = i
' (2) MM_rsCount = 5 ??
' (2) next line MM_size (10) &gt; MM_rsCount (5) MM_size = 5
If (MM_size &lt; 0 Or MM_size &gt; MM_rsCount) Then MM_size = MM_rsCount
End If

' if we walked off the end, set the offset based on page size
If (MM_rs.EOF And Not MM_paramIsDefined) Then
' (3) MM_offset(0) &gt; MM_rsCount(5) - MM_Size(10)
If (MM_offset &gt; MM_rsCount - MM_size Or MM_offset = -1) Then
' (No) MM_rsCount(5) Mod (10) = 0
If ((MM_rsCount Mod MM_size) &gt; 0) Then
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
' (3) MM_offset(-5) = MM_rsCount(5)-MM_size(10)
MM_offset = MM_rsCount - MM_size
End If
End If
End If

' reset the cursor to the beginning
' (1) CursorType = 0 will requery
If (MM_rs.CursorType &gt; 0) Then
MM_rs.MoveFirst
Else
MM_rs.Requery
End If




' move the cursor to the selected record
i = 0
While (Not MM_rs.EOF And i &lt; MM_offset)
MM_rs.MoveNext
i = i + 1
Wend
End If
%&gt;
</font id=code></pre id=code>

Edited by - jsw on 29 Jul 2002 12:04:52

Edited by - jsw on 29 Jul 2002 12:10:46

Replies

Replied 30 Jul 2002 21:19:52
30 Jul 2002 21:19:52 john weare replied:
Anyone have an idea about what happens when the requery is called within this script
<pre id=code><font face=courier size=2 id=code>
If (MM_rs.CursorType &gt; 0) Then
MM_rs.MoveFirst
Else
MM_rs.Requery
End If
</font id=code></pre id=code>

I am unfamiliar with it, though I have read the MS documentation. What gets returned when it is called under conditions of MM_rs.CursorType=0 (default). Thank in advance.
Replied 31 Jul 2002 00:17:29
31 Jul 2002 00:17:29 Dave Thomas replied:
A requery will re-execute the original query you ran to retrieve the records in the Recordset
object.
This refreshes the contents of the recordset.

"Get the kettle on, time for a brew"

Reply to this topic