Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.1 KiB

  1. <%@ LANGUAGE = PerlScript%>
  2. <html>
  3. <head>
  4. <meta name="GENERATOR" content="Tobias Martinsson">
  5. <title>ADO Record Counting</title>
  6. </head>
  7. <body>
  8. <BODY BGCOLOR=#FFFFFF>
  9. <!--
  10. ActiveState PerlScript sample
  11. PerlScript: The coolest way to program custom web solutions.
  12. -->
  13. <!-- Masthead -->
  14. <TABLE CELLPADDING=3 BORDER=0 CELLSPACING=0>
  15. <TR VALIGN=TOP ><TD WIDTH=400>
  16. <A NAME="TOP"><IMG SRC="PSBWlogo.gif" WIDTH=400 HEIGHT=48 ALT="ActiveState PerlScript" BORDER=0></A><P>
  17. </TD></TR></TABLE>
  18. <HR>
  19. <H3>ActiveX Data Objects (ADO) Record Counting</H3>
  20. Counting the number of records in a Recordset is something many find troublesome at first. The solution to why it sometimes return -1 instead of an accurate count is very simple. In order to avoid -1, you must use a cursor that can move all the way to the end of the Recordset and then back. Unless specified, the cursor will default to a cursor that moves only forward in the Recordset, thus can not determine the count. In this example, we use a Keyset cursor, which is a lightweight cursor that can move both forward and backward. When the database connection is open, the Recordset will contain the number of available records matching the query in its RecordCount-property.
  21. <p>
  22. <%
  23. my $adOpenKeySet_CursorType = 1;
  24. $rst = $Server->CreateObject('ADODB.Recordset');
  25. $rst->Open('SELECT * FROM Orders', 'ADOSAMPLES', $adOpenKeySet_CursorType);
  26. $Response->Write("There are ".$rst->{RecordCount}." records in the Recordset");
  27. $rst->Close(); # Close the recordset
  28. undef($rst); # Destroy the object
  29. %>
  30. <!-- +++++++++++++++++++++++++++++++++++++
  31. here is the standard showsource link -
  32. Note that PerlScript must be the default language --> <hr>
  33. <%
  34. $url = $Request->ServerVariables('PATH_INFO')->item;
  35. $_ = $Request->ServerVariables('PATH_TRANSLATED')->item;
  36. s/[\/\\](\w*\.asp\Z)//m;
  37. $params = 'filename='."$1".'&URL='."$url";
  38. $params =~ s#([^a-zA-Z0-9&_.:%/-\\]{1})#uc '%' . unpack('H2', $1)#eg;
  39. %>
  40. <A HREF="index.htm"> Return </A>
  41. <A HREF="showsource.asp?<%=$params%>">
  42. <h4><i>view the source</i></h4></A>
  43. </BODY>
  44. </HTML>