Source code of Windows XP (NT5)
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.

142 lines
3.8 KiB

  1. //Query.java
  2. //+-------------------------------------------------------------------------
  3. //
  4. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  5. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  6. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  7. // PARTICULAR PURPOSE.
  8. //
  9. // Copyright 1998-1999, Microsoft Corporation. All Rights Reserved.
  10. //
  11. // PROGRAM: VJQuery
  12. //
  13. // PURPOSE: Illustrates using Visual J++ and ADO to execute
  14. // SQL queries with Indexing Service.
  15. //
  16. // PLATFORM: Windows 2000
  17. //
  18. //--------------------------------------------------------------------------
  19. import java.io.*;
  20. // NOTE: The com.ms.wfc imports will become just wfc imports for distribution.
  21. import com.ms.wfc.*;
  22. import com.ms.wfc.core.*;
  23. import com.ms.wfc.data.*;
  24. import com.ms.com.*;
  25. //+-------------------------------------------------------------------------
  26. //
  27. // Class: Query
  28. //
  29. // Synopsis: Encapsulates setting/executing/displaying a query.
  30. //
  31. //--------------------------------------------------------------------------
  32. public class Query
  33. {
  34. Query()
  35. {
  36. this.m_SqlText = "";
  37. }
  38. //+-------------------------------------------------------------------------
  39. //
  40. // Method: Query::SetRawSql
  41. //
  42. // Synopsis: Stores a complete SQL query statement (SELECT, FROM, WHERE).
  43. //
  44. // Arguments: [RawSql] -- SQL Query.
  45. //
  46. //--------------------------------------------------------------------------
  47. void SetRawSql( String RawSql )
  48. {
  49. this.m_SqlText = RawSql;
  50. }
  51. //+-------------------------------------------------------------------------
  52. //
  53. // Method: Query::SetSqlWhere
  54. //
  55. // Synopsis: Stores an SQL WHERE clause. Remainder of query is fixed.
  56. //
  57. // Arguments: [Where] -- SQL WHERE clause, sans WHERE keyword.
  58. //
  59. //--------------------------------------------------------------------------
  60. void SetSqlWhere( String Where )
  61. {
  62. m_SqlText = "SELECT Filename, Size, Write, Path FROM SCOPE('DEEP TRAVERSAL OF \"\\\"') WHERE ";
  63. m_SqlText = m_SqlText + Where;
  64. }
  65. //+-------------------------------------------------------------------------
  66. //
  67. // Method: Query::Execute
  68. //
  69. // Synopsis: Execute query.
  70. //
  71. // Notes: May throw ADO exceptions.
  72. //
  73. //--------------------------------------------------------------------------
  74. void Execute()
  75. {
  76. m_RS = new Recordset();
  77. m_RS.open( m_SqlText,
  78. "provider=MSIDXS",
  79. AdoEnums.CursorType.STATIC,
  80. AdoEnums.LockType.BATCHOPTIMISTIC,
  81. AdoEnums.CommandType.TEXT );
  82. }
  83. //+-------------------------------------------------------------------------
  84. //
  85. // Method: Query::Display
  86. //
  87. // Synopsis: Display query results
  88. //
  89. // Arguments: [PS] -- Results are written to here.
  90. //
  91. // Notes: May throw ADO exceptions.
  92. //
  93. //--------------------------------------------------------------------------
  94. void Display( PrintStream PS )
  95. {
  96. try
  97. {
  98. int cFields = m_RS.getFields().getCount();
  99. while ( !m_RS.getEOF() )
  100. {
  101. for ( int j = 0; j < cFields; j++ )
  102. PS.print( m_RS.getFields().getItem(j).getValue() + "\t" );
  103. PS.print( "\n" );
  104. m_RS.moveNext();
  105. }
  106. }
  107. catch( com.ms.wfc.data.AdoException e )
  108. {
  109. System.out.println( "Caught " + e.getErrorNumber() );
  110. try
  111. {
  112. int i = System.in.read();
  113. }
  114. catch( java.lang.Exception e2 )
  115. {
  116. }
  117. }
  118. }
  119. // Members
  120. private String m_SqlText;
  121. private Recordset m_RS;
  122. }