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.

140 lines
3.7 KiB

  1. // VJQuery.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. // NOTE: The com.ms.wfc imports will become just wfc imports for distribution.
  20. import com.ms.wfc.*;
  21. import com.ms.wfc.core.*;
  22. import com.ms.wfc.data.*;
  23. import com.ms.com.*;
  24. /**
  25. * This class can take a variable number of parameters on the command
  26. * line. Program execution begins with the main() method. The class
  27. * constructor is not invoked unless an object of type 'VJQuery'
  28. * created in the main() method.
  29. */
  30. public class VJQuery
  31. {
  32. /**
  33. * The main entry point for the application.
  34. *
  35. * @param args Array of parameters passed to the application
  36. * via the command line.
  37. */
  38. public static void main (String[] args)
  39. {
  40. // Parse arguments.
  41. if ( ( 0 == args.length ) ||
  42. ( 1 == args.length && args[0].equalsIgnoreCase("-?") ) )
  43. {
  44. Usage();
  45. }
  46. else
  47. {
  48. Query Q = new Query();
  49. if ( args[0].equalsIgnoreCase("-s") )
  50. {
  51. String S = args[1];
  52. for ( int i = 2; i < args.length; i++ )
  53. S = S + " " + args[i];
  54. S = StripEndQuotes(S);
  55. Q.SetRawSql( S );
  56. }
  57. else
  58. {
  59. String S = args[0];
  60. for ( int i = 1; i < args.length; i++ )
  61. S = S + " " + args[i];
  62. S = StripEndQuotes(S);
  63. Q.SetSqlWhere( S );
  64. }
  65. try
  66. {
  67. // Run Query.
  68. Q.Execute();
  69. // Display the result.
  70. Q.Display( System.out );
  71. }
  72. catch( com.ms.wfc.data.AdoException e )
  73. {
  74. System.out.println( "Caught " + e.getErrorNumber() );
  75. }
  76. }
  77. try
  78. {
  79. System.out.println( "Press enter to continue..." );
  80. System.in.read();
  81. }
  82. catch( java.io.IOException e )
  83. {
  84. }
  85. }
  86. //+-------------------------------------------------------------------------
  87. //
  88. // Method: VJQuery::StripEndQuotes
  89. //
  90. // Synopsis: Removes beginning and ending quotes.
  91. //
  92. // Arguments: [S] -- String to strip.
  93. //
  94. // Returns: [S], sans initial and final quotes, if any.
  95. //
  96. //--------------------------------------------------------------------------
  97. static String StripEndQuotes( String S )
  98. {
  99. if ( S.indexOf("\"") == 0 )
  100. S = S.substring(1, S.length() - 1);
  101. if ( S.lastIndexOf("\"") == S.length() - 1 )
  102. S = S.substring(0, S.length() - 1);
  103. return S;
  104. }
  105. //+-------------------------------------------------------------------------
  106. //
  107. // Method: VJQuery::Usage
  108. //
  109. // Synopsis: Usage message.
  110. //
  111. //--------------------------------------------------------------------------
  112. static void Usage()
  113. {
  114. System.out.println( "Usage: VJQuery [-s] [<Query>]" );
  115. System.out.println( " <Query> WHERE clause or complete SELECT statement" );
  116. System.out.println( " -s <Query> is complete SELECT statement" );
  117. }
  118. }