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.

129 lines
3.0 KiB

  1. /*++
  2. Copyright Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. SQL_TEST.CPP
  5. Abstract:
  6. Test driver for Level 1 Syntax QL Parser
  7. Takes the filename of a file containing one or more WQL queries (one per
  8. line). Writes the output to the console.
  9. History:
  10. 23-Apr-99 Modified to improve output.
  11. --*/
  12. #include "precomp.h"
  13. #include <genlex.h>
  14. #include <sqllex.h>
  15. #include <sql_1.h>
  16. void xmain(int argc, char **argv)
  17. {
  18. if (argc < 2 || strchr(argv[1], '?') != NULL)
  19. {
  20. printf("Usage: ql_test WQL-query-file\n");
  21. return;
  22. }
  23. int nLine = 1;
  24. char buf[2048];
  25. FILE *f = fopen(argv[1], "rt");
  26. if (f == NULL)
  27. {
  28. printf("Usage: ql_test WQL-query-file\nError: cannot open file %s!\n", argv[1]);
  29. return;
  30. }
  31. while (fgets(buf, 2048, f) != NULL)
  32. {
  33. // get rid of newline
  34. char* ptr;
  35. if ((ptr = strchr(buf, '\n')) != NULL)
  36. {
  37. *ptr = '\0';
  38. }
  39. // get start of text
  40. ptr = buf;
  41. while (*ptr == ' ')
  42. {
  43. ptr++;
  44. }
  45. // ignore blank lines
  46. if (*ptr != '\0')
  47. {
  48. wchar_t buf2[2048];
  49. MultiByteToWideChar(CP_ACP, 0, ptr, -1, buf2, 2048);
  50. CTextLexSource src(buf2);
  51. SQL1_Parser parser(&src);
  52. SQL_LEVEL_1_RPN_EXPRESSION *pExp = NULL;
  53. // get the class
  54. wchar_t classbuf[128];
  55. *classbuf = 0;
  56. printf("----GetQueryClass----\n");
  57. int nRes = parser.GetQueryClass(classbuf, 128);
  58. if (nRes)
  59. {
  60. printf("ERROR %d: line %d, token %S\n",
  61. nRes,
  62. parser.CurrentLine(),
  63. parser.CurrentToken()
  64. );
  65. goto ContinueRead;
  66. }
  67. printf("Query class is %S\n", classbuf);
  68. // parse the full query
  69. nRes = parser.Parse(&pExp);
  70. if (nRes)
  71. {
  72. printf("ERROR %d: line %d, token %S\n",
  73. nRes,
  74. parser.CurrentLine(),
  75. parser.CurrentToken()
  76. );
  77. //goto ContinueRead;
  78. }
  79. else
  80. {
  81. printf("No errors.\n");
  82. }
  83. // call Dump function to display the tokens
  84. if (pExp)
  85. {
  86. pExp->Dump("CON");
  87. }
  88. ContinueRead:
  89. delete pExp;
  90. printf("%S\n", buf2);
  91. printf("=================================================EOL %d=======================================================\n", nLine);
  92. }
  93. nLine++;
  94. }
  95. if (ferror(f) != 0)
  96. {
  97. printf("\nError: line %d", nLine);
  98. }
  99. fclose(f);
  100. }
  101. void main(int argc, char **argv)
  102. {
  103. xmain(argc, argv);
  104. }