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.

107 lines
2.1 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. WQLTEST.CPP
  5. Abstract:
  6. History:
  7. --*/
  8. #include "precomp.h"
  9. #include <stdio.h>
  10. #include <genlex.h>
  11. #include <flexarry.h>
  12. #include <wqllex.h>
  13. #include <wqlnode.h>
  14. #include <wql.h>
  15. void dumpextra(CWQLParser &parser)
  16. {
  17. const CFlexArray *pAliases = parser.GetSelectedAliases();
  18. const CFlexArray *pColumns = parser.GetSelectedColumns();
  19. printf("------------------------------------------------------\n");
  20. printf("Selected Aliases:\n");
  21. for (int i = 0; i < pAliases->Size(); i++)
  22. {
  23. SWQLNode_TableRef *pTR = (SWQLNode_TableRef *) pAliases->GetAt(i);
  24. printf(" Alias = %S Table = %S\n", pTR->m_pAlias, pTR->m_pTableName);
  25. }
  26. printf("Selected Columns:\n");
  27. for (i = 0; i < pColumns->Size(); i++)
  28. {
  29. SWQLColRef *pCR = (SWQLColRef *) pColumns->GetAt(i);
  30. printf(" Alias = %S Table = %S\n", pCR->m_pTableRef, pCR->m_pColName);
  31. }
  32. printf("------------------------------------------------------\n");
  33. }
  34. void xmain(int argc, char **argv)
  35. {
  36. if (argc < 2)
  37. {
  38. printf("No SQL query specified\n");
  39. return;
  40. }
  41. char buf[8192];
  42. FILE *f = fopen(argv[1], "rt");
  43. int nCnt = fread(buf, 1, 8192, f);
  44. fclose(f);
  45. buf[nCnt] = 0;
  46. wchar_t buf2[8192];
  47. MultiByteToWideChar(CP_ACP, 0, buf, -1, buf2, 8192);
  48. CTextLexSource src(buf2);
  49. CWQLParser parser(&src);
  50. int nRes = parser.Parse();
  51. if (nRes)
  52. {
  53. printf("ERROR: %d\n", nRes);
  54. }
  55. else
  56. {
  57. printf("--------------- QUERY DUMP ----------------------\n");
  58. parser.GetParseRoot()->DebugDump();
  59. CWStringArray aTbls;
  60. parser.GetReferencedTables(aTbls);
  61. printf("\n\n---Referenced Tables---\n");
  62. for (int i = 0; i < aTbls.Size(); i++)
  63. printf(" Referenced Table = %S\n", aTbls[i]);
  64. printf("-------------------------------------------------\n");
  65. dumpextra(parser);
  66. printf("No errors.\n");
  67. }
  68. }
  69. void main(int argc, char **argv)
  70. {
  71. for (int i = 0; i < 100; i++)
  72. xmain(argc, argv);
  73. }