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.

151 lines
3.9 KiB

  1. //***************************************************************************
  2. //
  3. // SQL_1.H
  4. //
  5. // Level 1 Syntax SQL Parser
  6. //
  7. // Copyright 1999 Microsoft Corporation
  8. //
  9. //
  10. //=================================================================
  11. #ifndef _SQL_1_H_
  12. #define _SQL_1_H_
  13. #include <wbemprov.h>
  14. struct SQL_LEVEL_1_TOKEN
  15. {
  16. enum { OP_EXPRESSION = 1, TOKEN_AND, TOKEN_OR, TOKEN_NOT };
  17. enum { IFUNC_NONE = 0, IFUNC_UPPER = 1, IFUNC_LOWER = 2 };
  18. int nTokenType; // OP_EXPRESSION,TOKEN_AND, TOKEN_OR, TOKEN_NOT
  19. // If the field is a OP_EXPRESSION, then the following are used.
  20. enum { OP_EQUAL = 1, OP_NOT_EQUAL, OP_EQUALorGREATERTHAN,
  21. OP_EQUALorLESSTHAN, OP_LESSTHAN, OP_GREATERTHAN, OP_LIKE };
  22. BSTR pPropertyName; // Name of the property on which the operator is applied
  23. int nOperator; // Operator that is applied on property
  24. BOOL bConstIsStrNumeric; // True if the vConstValue is a BSTR and is a UINT32 or any 64bit number
  25. VARIANT vConstValue; // Value applied by operator
  26. BSTR pPropName2; // Property compared to.
  27. DWORD dwPropertyFunction; // 0=no instrinsic function applied
  28. DWORD dwConstFunction; // "
  29. SQL_LEVEL_1_TOKEN();
  30. SQL_LEVEL_1_TOKEN(SQL_LEVEL_1_TOKEN&);
  31. ~SQL_LEVEL_1_TOKEN();
  32. SQL_LEVEL_1_TOKEN& operator=(SQL_LEVEL_1_TOKEN &Src);
  33. void Dump(FILE *);
  34. };
  35. // Contains RPN version of expression.
  36. // ===================================
  37. struct SQL_LEVEL_1_RPN_EXPRESSION
  38. {
  39. int nNumTokens;
  40. int nCurSize;
  41. SQL_LEVEL_1_TOKEN *pArrayOfTokens;
  42. BSTR bsClassName;
  43. int nNumberOfProperties; // Zero means all properties selected
  44. int nCurPropSize;
  45. BSTR *pbsRequestedPropertyNames; // Array of property names which values are to be returned if
  46. SQL_LEVEL_1_RPN_EXPRESSION();
  47. ~SQL_LEVEL_1_RPN_EXPRESSION();
  48. //Note: this method deletes the token it is passed as an argument
  49. void AddToken(SQL_LEVEL_1_TOKEN *pTok);
  50. void AddToken(SQL_LEVEL_1_TOKEN &pTok);
  51. void AddProperty(LPWSTR pProp);
  52. void Dump(const char *pszTextFile);
  53. };
  54. class SQL1_Parser
  55. {
  56. CGenLexer *m_pLexer;
  57. int m_nLine;
  58. wchar_t* m_pTokenText;
  59. int m_nCurrentToken;
  60. SQL_LEVEL_1_RPN_EXPRESSION* m_pExpression;
  61. //Cleanup used by d'tor and SetSource
  62. void Cleanup();
  63. //Init used by c'tor and SetSource
  64. void Init(CGenLexSource *pSrc);
  65. // Semantic transfer variables.
  66. // ============================
  67. VARIANT m_vTypedConst;
  68. int m_nRelOp;
  69. DWORD m_dwConstFunction;
  70. DWORD m_dwPropFunction;
  71. LPWSTR m_pIdent;
  72. LPWSTR m_pPropComp;
  73. BOOL m_bConstIsStrNumeric;
  74. // Parsing functions.
  75. // ==================
  76. BOOL Next();
  77. int parse();
  78. int prop_list();
  79. int class_name();
  80. int opt_where();
  81. int expr();
  82. int property_name();
  83. int prop_list_2();
  84. int term();
  85. int expr2();
  86. int simple_expr();
  87. int term2();
  88. int leading_ident_expr();
  89. int finalize();
  90. int rel_operator();
  91. int equiv_operator();
  92. int comp_operator();
  93. int is_operator();
  94. int trailing_prop_expr();
  95. int trailing_prop_expr2();
  96. int trailing_or_null();
  97. int trailing_const_expr();
  98. int unknown_func_expr();
  99. int typed_constant();
  100. public:
  101. enum {
  102. SUCCESS,
  103. SYNTAX_ERROR,
  104. LEXICAL_ERROR,
  105. FAILED,
  106. BUFFER_TOO_SMALL
  107. };
  108. SQL1_Parser(CGenLexSource *pSrc);
  109. ~SQL1_Parser();
  110. int GetQueryClass(LPWSTR pBuf, int nBufSize);
  111. int Parse(SQL_LEVEL_1_RPN_EXPRESSION **pOutput);
  112. // use operator delete on pOutput
  113. int CurrentLine() { return m_nLine; }
  114. LPWSTR CurrentToken() { return m_pTokenText; }
  115. void SetSource(CGenLexSource *pSrc);
  116. };
  117. #endif