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.

4699 lines
174 KiB

  1. %{
  2. //--------------------------------------------------------------------
  3. // Microsoft Monarch
  4. //
  5. // Copyright (c) Microsoft Corporation, 1997 - 1999.
  6. //
  7. // @doc OPTIONAL EXTRACTION CODES
  8. //
  9. // @module MS-sql.y |
  10. // Monarch SQL YACC Script
  11. //
  12. // @devnote none
  13. //
  14. // @rev 0 | 04-Feb-97 | v-charca | Created
  15. //
  16. /* 3.4 Object identifier for Database Language SQL */
  17. #pragma hdrstop
  18. #pragma optimize("g", off)
  19. #include "msidxtr.h"
  20. EXTERN_C const IID IID_IColumnMapperCreator;
  21. #define VAL_AND_CCH_MINUS_NULL(p1) (p1), ((sizeof(p1) / sizeof(*(p1))) - 1)
  22. #ifdef YYDEBUG
  23. #define YYTRACE(a,b,c) wprintf(L"** %s[%s%s] ** \n", a, b, c);
  24. #else
  25. #define YYTRACE(a,b,c)
  26. #endif
  27. #ifdef DEBUG
  28. #define AssertReq(x) Assert(x != NULL)
  29. #else
  30. #define AssertReq(x)
  31. #endif
  32. #define DEFAULTWEIGHT 1000
  33. typedef struct tagDBTYPENAMETABLE
  34. {
  35. LPWSTR pwszDBTypeName;
  36. DBTYPE dbType;
  37. } DBTYPENAMETABLE;
  38. // J F M A M J J A S O N D
  39. const short LeapDays[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  40. const short Days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  41. #define IsLeapYear(yrs) ( \
  42. (((yrs) % 400 == 0) || \
  43. ((yrs) % 100 != 0) && ((yrs) % 4 == 0)) ? \
  44. TRUE \
  45. : \
  46. FALSE \
  47. )
  48. #define DaysInMonth(YEAR,MONTH) ( \
  49. IsLeapYear(YEAR) ? \
  50. LeapDays[(MONTH)] : \
  51. Days[(MONTH)] \
  52. )
  53. //-----------------------------------------------------------------------------
  54. // @func GetDBTypeFromStr
  55. //
  56. // This function takes a TypeName as input, and returns the DBTYPE of the string
  57. //
  58. // @rdesc DBTYPE
  59. //-----------------------------------------------------------------------------
  60. DBTYPE GetDBTypeFromStr(
  61. LPWSTR pwszDBTypeName ) // @parm IN
  62. {
  63. DBTYPE dbType = DBTYPE_EMPTY;
  64. if ( 9 <= wcslen(pwszDBTypeName) )
  65. switch ( pwszDBTypeName[7] )
  66. {
  67. case L'U':
  68. case L'u':
  69. if (10 == wcslen(pwszDBTypeName))
  70. switch ( pwszDBTypeName[9])
  71. {
  72. case L'1':
  73. if (0 == _wcsicmp(L"DBTYPE_UI1", pwszDBTypeName))
  74. dbType = DBTYPE_UI1;
  75. break;
  76. case L'2':
  77. if (0 == _wcsicmp(L"DBTYPE_UI2", pwszDBTypeName))
  78. dbType = DBTYPE_UI2;
  79. break;
  80. case L'4':
  81. if (0 == _wcsicmp(L"DBTYPE_UI4", pwszDBTypeName))
  82. dbType = DBTYPE_UI4;
  83. break;
  84. case L'8':
  85. if (0 == _wcsicmp(L"DBTYPE_UI8", pwszDBTypeName))
  86. dbType = DBTYPE_UI8;
  87. break;
  88. default:
  89. break;
  90. }
  91. break;
  92. case L'I':
  93. case L'i':
  94. switch ( pwszDBTypeName[8] )
  95. {
  96. case L'1':
  97. if ( 0 == _wcsicmp(L"DBTYPE_I1", pwszDBTypeName) )
  98. dbType = DBTYPE_I1;
  99. break;
  100. case L'2':
  101. if ( 0 == _wcsicmp(L"DBTYPE_I2", pwszDBTypeName) )
  102. dbType = DBTYPE_I2;
  103. break;
  104. case L'4':
  105. if ( 0 == _wcsicmp(L"DBTYPE_I4", pwszDBTypeName) )
  106. dbType = DBTYPE_I4;
  107. break;
  108. case L'8':
  109. if ( 0 == _wcsicmp(L"DBTYPE_I8", pwszDBTypeName) )
  110. dbType = DBTYPE_I8;
  111. break;
  112. default:
  113. break;
  114. }
  115. break;
  116. case L'R':
  117. case L'r':
  118. switch ( pwszDBTypeName[8] )
  119. {
  120. case L'4':
  121. if ( 0 == _wcsicmp(L"DBTYPE_R4", pwszDBTypeName) )
  122. dbType = DBTYPE_R4;
  123. break;
  124. case L'8':
  125. if (0 == _wcsicmp(L"DBTYPE_R8", pwszDBTypeName))
  126. dbType = DBTYPE_R8;
  127. break;
  128. default:
  129. break;
  130. }
  131. break;
  132. case L'B':
  133. case L'b':
  134. if ( 10 <= wcslen(pwszDBTypeName) )
  135. switch ( pwszDBTypeName[8] )
  136. {
  137. case L'S':
  138. case L's':
  139. if ( 0 == _wcsicmp(L"DBTYPE_BSTR", pwszDBTypeName) )
  140. dbType = DBTYPE_BSTR;
  141. break;
  142. case L'O':
  143. case L'o':
  144. if ( 0 == _wcsicmp(L"DBTYPE_BOOL", pwszDBTypeName) )
  145. dbType = DBTYPE_BOOL;
  146. break;
  147. case L'Y':
  148. case L'y':
  149. if ( 0 == _wcsicmp(L"DBTYPE_BYREF", pwszDBTypeName) )
  150. dbType = DBTYPE_BYREF;
  151. break;
  152. default:
  153. break;
  154. }
  155. break;
  156. case L'E':
  157. case L'e':
  158. if ( 0 == _wcsicmp(L"DBTYPE_EMPTY", pwszDBTypeName) )
  159. dbType = DBTYPE_EMPTY;
  160. break;
  161. case L'N':
  162. case L'n':
  163. if ( 0 == _wcsicmp(L"DBTYPE_NULL", pwszDBTypeName) )
  164. dbType = DBTYPE_NULL;
  165. break;
  166. case L'C':
  167. case L'c':
  168. if ( 0 == _wcsicmp(L"DBTYPE_CY", pwszDBTypeName) )
  169. dbType = DBTYPE_CY;
  170. break;
  171. case L'D':
  172. case L'd':
  173. if ( 0 == _wcsicmp(L"DBTYPE_DATE", pwszDBTypeName) )
  174. dbType = DBTYPE_DATE;
  175. break;
  176. case L'G':
  177. case L'g':
  178. if ( 0 == _wcsicmp(L"DBTYPE_GUID", pwszDBTypeName) )
  179. dbType = DBTYPE_GUID;
  180. break;
  181. case L'S':
  182. case L's':
  183. if ( 0 == _wcsicmp(L"DBTYPE_STR", pwszDBTypeName) )
  184. dbType = DBTYPE_STR;
  185. break;
  186. case L'W':
  187. case L'w':
  188. if ( 0 == _wcsicmp(L"DBTYPE_WSTR", pwszDBTypeName) )
  189. dbType = DBTYPE_WSTR;
  190. break;
  191. case L'T':
  192. case L't':
  193. if ( 0 == _wcsicmp(L"VT_FILETIME", pwszDBTypeName) )
  194. dbType = VT_FILETIME;
  195. break;
  196. case L'V':
  197. case L'v':
  198. if ( 0 == _wcsicmp(L"DBTYPE_VECTOR", pwszDBTypeName) )
  199. dbType = DBTYPE_VECTOR;
  200. break;
  201. default:
  202. break;
  203. }
  204. return dbType;
  205. }
  206. const DBTYPENAMETABLE dbTypeNameTable[] =
  207. {
  208. {L"DBTYPE_EMPTY", DBTYPE_EMPTY},
  209. {L"DBTYPE_NULL", DBTYPE_NULL},
  210. {L"DBTYPE_I2", DBTYPE_I2},
  211. {L"DBTYPE_I4", DBTYPE_I4},
  212. {L"DBTYPE_R4", DBTYPE_R4},
  213. {L"DBTYPE_R8", DBTYPE_R8},
  214. {L"DBTYPE_CY", DBTYPE_CY},
  215. {L"DBTYPE_DATE", DBTYPE_DATE},
  216. {L"DBTYPE_BSTR", DBTYPE_BSTR},
  217. {L"DBTYPE_BOOL", DBTYPE_BOOL},
  218. {L"DBTYPE_UI1", DBTYPE_UI1},
  219. {L"DBTYPE_I1", DBTYPE_I1},
  220. {L"DBTYPE_UI2", DBTYPE_UI2},
  221. {L"DBTYPE_UI4", DBTYPE_UI4},
  222. {L"DBTYPE_I8", DBTYPE_I8},
  223. {L"DBTYPE_UI8", DBTYPE_UI8},
  224. {L"DBTYPE_GUID", DBTYPE_GUID},
  225. {L"DBTYPE_STR", DBTYPE_STR},
  226. {L"DBTYPE_WSTR", DBTYPE_WSTR},
  227. {L"DBTYPE_BYREF", DBTYPE_BYREF},
  228. {L"VT_FILETIME", VT_FILETIME},
  229. {L"DBTYPE_VECTOR", DBTYPE_VECTOR}
  230. };
  231. //-----------------------------------------------------------------------------
  232. // @func PctCreateContentNode
  233. //
  234. // This function takes a content string as input and creates a content node
  235. // with the specified generate method and weight.
  236. //
  237. // @rdesc DBCOMMANDTREE*
  238. //-----------------------------------------------------------------------------
  239. DBCOMMANDTREE* PctCreateContentNode(
  240. LPWSTR pwszContent, // @parm IN | content for the node
  241. DWORD dwGenerateMethod,//@parm IN | generate method
  242. LONG lWeight, // @parm IN | weight
  243. LCID lcid, // @parm IN | locale identifier
  244. DBCOMMANDTREE* pctFirstChild ) // @parm IN | node to link to new node
  245. {
  246. DBCOMMANDTREE* pct = PctCreateNode( DBOP_content, DBVALUEKIND_CONTENT, pctFirstChild, NULL );
  247. if ( 0 != pct )
  248. {
  249. pct->value.pdbcntntValue->pwszPhrase = CoTaskStrDup( pwszContent );
  250. if (pct->value.pdbcntntValue->pwszPhrase)
  251. {
  252. pct->value.pdbcntntValue->dwGenerateMethod = dwGenerateMethod;
  253. pct->value.pdbcntntValue->lWeight = lWeight;
  254. pct->value.pdbcntntValue->lcid = lcid;
  255. }
  256. else
  257. {
  258. DeleteDBQT( pct );
  259. pct = 0;
  260. }
  261. }
  262. return pct;
  263. }
  264. //-----------------------------------------------------------------------------
  265. // @func PctCreateBooleanNode
  266. //
  267. // This function creates a content node with the specified children and weight.
  268. //
  269. // @rdesc DBCOMMANDTREE*
  270. //-----------------------------------------------------------------------------
  271. DBCOMMANDTREE* PctCreateBooleanNode(
  272. DBCOMMANDOP op, // @parm IN | op tag for new node
  273. LONG lWeight, // @parm IN | Weight of the boolean node
  274. DBCOMMANDTREE* pctChild, // @parm IN | child of boolean node
  275. DBCOMMANDTREE* pctSibling )// @parm IN | second child of boolean node
  276. {
  277. DBCOMMANDTREE* pct = PctCreateNode( op, DBVALUEKIND_I4, pctChild, pctSibling, NULL );
  278. if ( 0 != pct )
  279. pct->value.lValue = lWeight;
  280. return pct;
  281. }
  282. //-----------------------------------------------------------------------------
  283. // @func PctCreateNotNode
  284. //
  285. // This function creates a not node with the specified child and weight.
  286. //
  287. // @rdesc DBCOMMANDTREE*
  288. //-----------------------------------------------------------------------------
  289. DBCOMMANDTREE* PctCreateNotNode(
  290. LONG lWeight, // @parm IN | Weight of the boolean node
  291. DBCOMMANDTREE* pctChild ) // @parm IN | child of NOT node
  292. {
  293. DBCOMMANDTREE* pct = PctCreateNode( DBOP_not, DBVALUEKIND_I4, pctChild, NULL );
  294. if ( 0 != pct )
  295. pct->value.lValue = lWeight;
  296. return pct;
  297. }
  298. //-----------------------------------------------------------------------------
  299. // @func PctCreateRelationalNode
  300. //
  301. // This function creates a relational node with the specied op and weight.
  302. //
  303. // @rdesc DBCOMMANDTREE*
  304. //-----------------------------------------------------------------------------
  305. DBCOMMANDTREE* PctCreateRelationalNode(
  306. DBCOMMANDOP op, // @parm IN | op tag for new node
  307. LONG lWeight ) // @parm IN | Weight of the relational node
  308. {
  309. DBCOMMANDTREE* pct = PctCreateNode(op, DBVALUEKIND_I4, NULL);
  310. if ( 0 != pct)
  311. pct->value.lValue = lWeight;
  312. return pct;
  313. }
  314. //-----------------------------------------------------------------------------
  315. // @func SetLWeight
  316. //
  317. // This function sets the lWeight value for vector searches
  318. //
  319. //-----------------------------------------------------------------------------
  320. void SetLWeight(
  321. DBCOMMANDTREE* pct, // @parm IN | node or subtree to set
  322. LONG lWeight ) // @parm IN | weight value for node(s)
  323. {
  324. if ( DBOP_content == pct->op )
  325. pct->value.pdbcntntValue->lWeight = lWeight;
  326. else
  327. {
  328. AssertReq( pct->pctFirstChild );
  329. AssertReq( pct->pctFirstChild->pctNextSibling );
  330. SetLWeight(pct->pctFirstChild, lWeight);
  331. DBCOMMANDTREE* pctNext = pct->pctFirstChild->pctNextSibling;
  332. while ( pctNext )
  333. {
  334. // A content_proximity node can have lots of siblings
  335. SetLWeight( pctNext, lWeight );
  336. pctNext = pctNext->pctNextSibling;
  337. }
  338. }
  339. }
  340. //-----------------------------------------------------------------------------
  341. // @func GetLWeight
  342. //
  343. // This function gets the lWeight value for vector searches
  344. //-----------------------------------------------------------------------------
  345. LONG GetLWeight(
  346. DBCOMMANDTREE* pct ) // @parm IN | node or subtree to set
  347. {
  348. if ( DBOP_content == pct->op )
  349. return pct->value.pdbcntntValue->lWeight;
  350. else
  351. {
  352. AssertReq( pct->pctFirstChild );
  353. return GetLWeight( pct->pctFirstChild );
  354. }
  355. }
  356. //-----------------------------------------------------------------------------
  357. // @func PctBuiltInProperty
  358. //
  359. // This function takes a column name string as input and creates a column_name
  360. // node containing the appropriate GUID information if the column_name is a
  361. // built-in property
  362. //
  363. // @rdesc DBCOMMANDTREE*
  364. //-----------------------------------------------------------------------------
  365. DBCOMMANDTREE* PctBuiltInProperty(
  366. LPWSTR pwszColumnName, // @parm IN | name of column
  367. CImpIParserSession* pIPSession, // @parm IN | Parser Session
  368. CImpIParserTreeProperties* pIPTProps ) // @parm IN | Parser Properties
  369. {
  370. DBCOMMANDTREE* pct = 0;
  371. DBID *pDBID = 0;
  372. DBTYPE uwType = 0;
  373. UINT uiWidth = 0;
  374. BOOL fOk = 0;
  375. IColumnMapper* pIColumnMapper = pIPSession->GetColumnMapperPtr();
  376. if ( 0 != pIColumnMapper )
  377. {
  378. // we were able to use the IColumnMapper interface
  379. HRESULT hr = S_OK;
  380. // Olympus kludge
  381. if ( 0 == _wcsicmp(pwszColumnName, L"URL") )
  382. hr = pIColumnMapper->GetPropInfoFromName( L"VPATH", &pDBID, &uwType, &uiWidth );
  383. else
  384. hr = pIColumnMapper->GetPropInfoFromName( pwszColumnName, &pDBID, &uwType, &uiWidth );
  385. if ( SUCCEEDED(hr) )
  386. fOk = TRUE;
  387. else
  388. fOk = FALSE;
  389. }
  390. else
  391. fOk = FALSE; // @TODO: this should generate some sort of error message.
  392. if ( fOk ) // this is a built-in (well known) property
  393. {
  394. pIPTProps->SetDBType( uwType ); // remember the type of this
  395. pct = PctCreateNode( DBOP_column_name, DBVALUEKIND_ID, NULL );
  396. if ( 0 != pct )
  397. {
  398. pct->value.pdbidValue->eKind = pDBID->eKind;
  399. pct->value.pdbidValue->uGuid.guid = pDBID->uGuid.guid;
  400. switch ( pct->value.pdbidValue->eKind )
  401. {
  402. case DBKIND_NAME:
  403. case DBKIND_GUID_NAME:
  404. {
  405. // need to create a new string
  406. pct->value.pdbidValue->uName.pwszName = CoTaskStrDup(pDBID->uName.pwszName);
  407. if ( 0 == pct->value.pdbidValue->uName.pwszName )
  408. {
  409. pct->value.pdbidValue->eKind = DBKIND_GUID_PROPID;
  410. DeleteDBQT( pct );
  411. pct = 0;
  412. }
  413. break;
  414. }
  415. case DBKIND_GUID:
  416. case DBKIND_GUID_PROPID:
  417. pct->value.pdbidValue->uName.pwszName = pDBID->uName.pwszName;
  418. break;
  419. case DBKIND_PGUID_NAME:
  420. {
  421. // need to create a new string
  422. pct->value.pdbidValue->uName.pwszName = CoTaskStrDup(pDBID->uName.pwszName);
  423. if ( 0 == pct->value.pdbidValue->uName.pwszName )
  424. {
  425. pct->value.pdbidValue->eKind = DBKIND_GUID_PROPID;
  426. DeleteDBQT( pct );
  427. pct = 0;
  428. break;
  429. }
  430. // need to allocate and copy guid
  431. pct->value.pdbidValue->uGuid.pguid = (GUID*)CoTaskMemAlloc(sizeof(GUID));
  432. if ( 0 == pct->value.pdbidValue->uName.pwszName )
  433. {
  434. CoTaskMemFree( pct->value.pdbidValue->uName.pwszName );
  435. pct->value.pdbidValue->uName.pwszName = 0;
  436. pct->value.pdbidValue->eKind = DBKIND_GUID_PROPID;
  437. DeleteDBQT( pct );
  438. pct = 0;
  439. break;
  440. }
  441. *pct->value.pdbidValue->uGuid.pguid = *pDBID->uGuid.pguid;
  442. break;
  443. }
  444. case DBKIND_PGUID_PROPID:
  445. {
  446. // need to allocate and copy guid
  447. pct->value.pdbidValue->uGuid.pguid = (GUID*)CoTaskMemAlloc(sizeof(GUID));
  448. if ( 0 == pct->value.pdbidValue->uGuid.pguid )
  449. {
  450. pct->value.pdbidValue->eKind = DBKIND_GUID_PROPID;
  451. DeleteDBQT( pct );
  452. pct = 0;
  453. break;
  454. }
  455. *pct->value.pdbidValue->uGuid.pguid = *pDBID->uGuid.pguid;
  456. break;
  457. }
  458. default:
  459. Assert(0);
  460. }
  461. }
  462. }
  463. return pct;
  464. }
  465. //-----------------------------------------------------------------------------
  466. // @func PctMkColNodeFromStr
  467. //
  468. // This function takes a column name string as input and creates a column_name
  469. // node containing the appropriate GUID information.
  470. //
  471. // @rdesc DBCOMMANDTREE*
  472. //-----------------------------------------------------------------------------
  473. DBCOMMANDTREE* PctMkColNodeFromStr(
  474. LPWSTR pwszColumnName, // @parm IN | name of column
  475. CImpIParserSession* pIPSession, // @parm IN | Parser Session
  476. CImpIParserTreeProperties* pIPTProps ) // @parm IN | Parser Properties
  477. {
  478. DBCOMMANDTREE* pct = 0;
  479. pct = PctBuiltInProperty( pwszColumnName, pIPSession, pIPTProps );
  480. if ( 0 == pct )
  481. { // this may be a user defined property, or is undefined
  482. DBTYPE dbType = 0;
  483. HRESULT hr = pIPSession->m_pCPropertyList->LookUpPropertyName( pwszColumnName, &pct, &dbType );
  484. if ( E_OUTOFMEMORY == hr )
  485. pIPTProps->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  486. else if ( FAILED(hr) )
  487. {
  488. pIPTProps->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_COLUMN_NOT_DEFINED );
  489. pIPTProps->SetErrorToken( pwszColumnName );
  490. }
  491. else
  492. {
  493. AssertReq( 0 != pct );
  494. pIPTProps->SetDBType( dbType );
  495. }
  496. }
  497. return pct;
  498. }
  499. /* ************************************************************************************************ */
  500. /* ************************************************************************************************ */
  501. /* ************************************************************************************************ */
  502. %}
  503. /***
  504. *** Tokens (used also by flex via sql_tab.h)
  505. ***/
  506. %left ','
  507. %left '='
  508. %left _OR
  509. %left _AND
  510. %left _NOT
  511. %left '+' '-'
  512. %left '*' '/'
  513. %left '(' ')'
  514. %nonassoc _UMINUS
  515. %left mHighest
  516. /***
  517. *** reserved_words
  518. ***/
  519. %token _ALL
  520. %token _ANY
  521. %token _ARRAY
  522. %token _AS
  523. %token _ASC
  524. %token _CAST
  525. %token _COERCE
  526. %token _CONTAINS
  527. %token _CONTENTS
  528. %token _CREATE
  529. %token _DEEP_TRAVERSAL
  530. %token _DESC
  531. %token _DOT
  532. %token _DOTDOT
  533. %token _DOTDOT_SCOPE
  534. %token _DOTDOTDOT
  535. %token _DOTDOTDOT_SCOPE
  536. %token _DROP
  537. %token _EXCLUDE_SEARCH_TRAVERSAL
  538. %token _FALSE
  539. %token _FREETEXT
  540. %token _FROM
  541. %token _IS
  542. %token _ISABOUT
  543. %token _IS_NOT
  544. %token _LIKE
  545. %token _MATCHES
  546. %token _NEAR
  547. %token _NOT_LIKE
  548. %token _NULL
  549. %token _OF
  550. %token _ORDER_BY
  551. %token _PASSTHROUGH
  552. %token _PROPERTYNAME
  553. %token _PROPID
  554. %token _RANKMETHOD
  555. %token _SELECT
  556. %token _SET
  557. %token _SCOPE
  558. %token _SHALLOW_TRAVERSAL
  559. %token _FORMSOF
  560. %token _SOME
  561. %token _TABLE
  562. %token _TRUE
  563. %token _TYPE
  564. %token _UNION
  565. %token _UNKNOWN
  566. %token _URL
  567. %token _VIEW
  568. %token _WHERE
  569. %token _WEIGHT
  570. /***
  571. *** Two character comparison tokens
  572. ***/
  573. %token _GE
  574. %token _LE
  575. %token _NE
  576. /***
  577. *** Terminal tokens
  578. ***/
  579. %token _CONST
  580. %token _ID
  581. %token _TEMPVIEW
  582. %token _INTNUM
  583. %token _REALNUM
  584. %token _SCALAR_FUNCTION_REF
  585. %token _STRING
  586. %token _DATE
  587. %token _PREFIX_STRING
  588. /***
  589. *** Terminal tokens that don't actually make it out of the lexer
  590. ***/
  591. %token _DELIMITED_ID // A delimited id is processed (quotes stripped) in ms-sql.l.
  592. // A regular id is converted to upper case in ms-sql.l
  593. // _ID is returned for either case.
  594. %start entry_point
  595. %%
  596. /***
  597. *** SQL YACC grammar
  598. ***/
  599. entry_point:
  600. definition_list
  601. {
  602. $$ = NULL;
  603. }
  604. | definition_list executable_statement
  605. {
  606. $$ = $2;
  607. }
  608. | executable_statement
  609. {
  610. $$ = $1;
  611. }
  612. ;
  613. executable_statement:
  614. ordered_query_specification semicolon
  615. {
  616. if ($2)
  617. {
  618. // There is a semicolon, either as a statement terminator or as
  619. // a statement separator. We don't allow either of those.
  620. m_pIPTProperties->SetErrorHResult(DB_E_MULTIPLESTATEMENTS, MONSQL_SEMI_COLON);
  621. YYABORT(DB_E_MULTIPLESTATEMENTS);
  622. }
  623. $$ = $1;
  624. }
  625. /* *************************************************** *
  626. | _PASSTHROUGH '(' _STRING ',' _STRING ',' _STRING ')'
  627. {
  628. CITextToFullTree(((PROPVARIANT*)$5->value.pvValue)->bstrVal, // pwszRestriction
  629. ((PROPVARIANT*)$3->value.pvValue)->bstrVal, // pwszColumns
  630. ((PROPVARIANT*)$7->value.pvValue)->bstrVal, // pwszSortColumns
  631. NULL, // pwszGroupings, not used yet. Must be NULL
  632. &$$,
  633. 0,
  634. NULL,
  635. m_pIPSession->GetLCID());
  636. }
  637. /* *************************************************** */
  638. ;
  639. semicolon:
  640. /* empty (correct) */
  641. {
  642. $$ = NULL;
  643. }
  644. | ';'
  645. {
  646. $$ = PctAllocNode(DBVALUEKIND_NULL, DBOP_NULL);
  647. }
  648. ;
  649. definition_list:
  650. definition_list definition opt_semi
  651. {
  652. $$ = NULL;
  653. }
  654. | definition opt_semi
  655. {
  656. $$ = NULL;
  657. }
  658. ;
  659. definition:
  660. create_view_statement
  661. {
  662. $$ = NULL;
  663. }
  664. | drop_view_statement
  665. {
  666. $$ = NULL;
  667. }
  668. | set_statement
  669. {
  670. $$ = NULL;
  671. }
  672. ;
  673. opt_semi:
  674. /* empty */
  675. | ';'
  676. ;
  677. typed_literal:
  678. _INTNUM
  679. {
  680. AssertReq($1);
  681. Assert(VT_UI8 == ((PROPVARIANT*)$1->value.pvValue)->vt ||
  682. VT_I8 == ((PROPVARIANT*)$1->value.pvValue)->vt ||
  683. VT_BSTR == ((PROPVARIANT*)$1->value.pvValue)->vt);
  684. m_pIPTProperties->AppendCiRestriction((YY_CHAR*)m_yylex.YYText(), wcslen(m_yylex.YYText()));
  685. HRESULT hr = CoerceScalar(m_pIPTProperties->GetDBType(), &$1);
  686. if (S_OK != hr)
  687. YYABORT(hr);
  688. $$ = $1;
  689. }
  690. | _REALNUM
  691. {
  692. AssertReq($1);
  693. Assert(VT_R8 == ((PROPVARIANT*)$1->value.pvValue)->vt ||
  694. VT_BSTR == ((PROPVARIANT*)$1->value.pvValue)->vt);
  695. m_pIPTProperties->AppendCiRestriction((YY_CHAR*)m_yylex.YYText(), wcslen(m_yylex.YYText()));
  696. HRESULT hr = CoerceScalar(m_pIPTProperties->GetDBType(), &$1);
  697. if (S_OK != hr)
  698. YYABORT(hr);
  699. $$ = $1;
  700. }
  701. | _STRING
  702. {
  703. AssertReq($1);
  704. Assert(VT_BSTR == ((PROPVARIANT*)$1->value.pvValue)->vt);
  705. if (VT_DATE == m_pIPTProperties->GetDBType() ||
  706. VT_FILETIME == m_pIPTProperties->GetDBType())
  707. m_pIPTProperties->AppendCiRestriction(((PROPVARIANT*)$1->value.pvValue)->bstrVal,
  708. wcslen(((PROPVARIANT*)$1->value.pvValue)->bstrVal));
  709. else
  710. {
  711. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"\""));
  712. m_pIPTProperties->AppendCiRestriction(((PROPVARIANT*)$1->value.pvValue)->bstrVal,
  713. wcslen(((PROPVARIANT*)$1->value.pvValue)->bstrVal));
  714. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"\""));
  715. }
  716. HRESULT hr = CoerceScalar(m_pIPTProperties->GetDBType(), &$1);
  717. if (S_OK != hr)
  718. YYABORT(hr);
  719. $$ = $1;
  720. }
  721. | relative_date_time
  722. {
  723. AssertReq($1);
  724. Assert(VT_FILETIME == ((PROPVARIANT*)$1->value.pvValue)->vt);
  725. SYSTEMTIME stValue = {0, 0, 0, 0, 0, 0, 0, 0};
  726. if (FileTimeToSystemTime(&(((PROPVARIANT*)$1->value.pvValue)->filetime), &stValue))
  727. {
  728. WCHAR wchDateTime[50];
  729. if (NULL == wchDateTime)
  730. {
  731. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  732. YYABORT(E_OUTOFMEMORY);
  733. }
  734. int cItems = swprintf(wchDateTime, L" %4d/%02d/%02d %02d:%02d:%02d",
  735. stValue.wYear,
  736. stValue.wMonth,
  737. stValue.wDay,
  738. stValue.wHour,
  739. stValue.wMinute,
  740. stValue.wSecond);
  741. m_pIPTProperties->AppendCiRestriction(wchDateTime, wcslen(wchDateTime));
  742. }
  743. HRESULT hr = CoerceScalar(m_pIPTProperties->GetDBType(), &$1);
  744. if (S_OK != hr)
  745. YYABORT(hr);
  746. $$ = $1;
  747. }
  748. | boolean_literal
  749. {
  750. m_pIPTProperties->AppendCiRestriction((YY_CHAR*)m_yylex.YYText(), wcslen(m_yylex.YYText()));
  751. HRESULT hr = CoerceScalar(m_pIPTProperties->GetDBType(), &$1);
  752. if (S_OK != hr)
  753. YYABORT(hr);
  754. $$ = $1;
  755. }
  756. ;
  757. unsigned_integer:
  758. _INTNUM
  759. {
  760. HRESULT hr = CoerceScalar(VT_UI4, &$1);
  761. if (S_OK != hr)
  762. YYABORT(hr);
  763. $$ = $1;
  764. }
  765. ;
  766. integer:
  767. _INTNUM
  768. {
  769. HRESULT hr = CoerceScalar(VT_I4, &$1);
  770. if (S_OK != hr)
  771. YYABORT(hr);
  772. $$ = $1;
  773. }
  774. ;
  775. relative_date_time:
  776. identifier '(' identifier ',' _INTNUM ',' relative_date_time ')'
  777. {
  778. // should be DateAdd(<datepart>, <negative integer>, <relative date/time>)
  779. AssertReq($1);
  780. AssertReq($3);
  781. AssertReq($5);
  782. AssertReq($7);
  783. if (0 != _wcsicmp(L"DateAdd", $1->value.pwszValue))
  784. {
  785. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  786. m_pIPTProperties->SetErrorToken($1->value.pwszValue);
  787. m_pIPTProperties->SetErrorToken(L"DateAdd");
  788. YYABORT(DB_E_ERRORSINCOMMAND);
  789. }
  790. HRESULT hr = CoerceScalar(VT_I4, &$5);
  791. if (S_OK != hr)
  792. YYABORT(hr);
  793. if (((PROPVARIANT*)$5->value.pvValue)->iVal > 0)
  794. {
  795. WCHAR wchError[30];
  796. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  797. swprintf(wchError, L"%d", ((PROPVARIANT*)$5->value.pvValue)->iVal);
  798. m_pIPTProperties->SetErrorToken(wchError);
  799. swprintf(wchError, L"%d", -((PROPVARIANT*)$5->value.pvValue)->iVal);
  800. m_pIPTProperties->SetErrorToken(wchError);
  801. YYABORT(DB_E_ERRORSINCOMMAND);
  802. }
  803. LARGE_INTEGER hWeek = {686047232, 1408};
  804. LARGE_INTEGER hDay = {711573504, 201};
  805. LARGE_INTEGER hHour = {1640261632, 8};
  806. LARGE_INTEGER hMinute = {600000000, 0};
  807. LARGE_INTEGER hSecond = {10000000, 0};
  808. LARGE_INTEGER hIncr = {0,0};
  809. bool fHandleMonth = false;
  810. ULONG ulMonths = 1;
  811. switch ( $3->value.pwszValue[0] )
  812. {
  813. case L'Y':
  814. case L'y':
  815. if (0 == (_wcsicmp(L"YY", $3->value.pwszValue) & _wcsicmp(L"YEAR", $3->value.pwszValue)))
  816. {
  817. // fall through and handle as 12 months
  818. ulMonths = 12;
  819. }
  820. case L'Q':
  821. case L'q':
  822. if (0 == (_wcsicmp(L"QQ", $3->value.pwszValue) & _wcsicmp(L"QUARTER", $3->value.pwszValue)))
  823. {
  824. // fall through and handle as 3 months
  825. ulMonths = 3;
  826. }
  827. case L'M':
  828. case L'm':
  829. if ( 0 == (_wcsicmp(L"YY", $3->value.pwszValue) & _wcsicmp(L"YEAR", $3->value.pwszValue)) ||
  830. 0 == (_wcsicmp(L"QQ", $3->value.pwszValue) & _wcsicmp(L"QUARTER", $3->value.pwszValue)) ||
  831. 0 == (_wcsicmp(L"MM", $3->value.pwszValue) & _wcsicmp(L"MONTH", $3->value.pwszValue)))
  832. {
  833. //
  834. // Convert to system time
  835. //
  836. SYSTEMTIME st = { 0, 0, 0, 0, 0, 0, 0, 0 };
  837. FileTimeToSystemTime( &((PROPVARIANT*)$7->value.pvValue)->filetime, &st );
  838. LONGLONG llDays = 0;
  839. LONG lMonthsLeft = ulMonths * -((PROPVARIANT*)$5->value.pvValue)->iVal;
  840. LONG yr = st.wYear;
  841. LONG lCurMonth = st.wMonth-1;
  842. while ( lMonthsLeft )
  843. {
  844. LONG lMonthsDone = 1;
  845. while ( lMonthsDone<=lMonthsLeft )
  846. {
  847. // Will we still be in the current year when looking at the prev month?
  848. if ( 0 == lCurMonth )
  849. break;
  850. // Subtract the number of days in the previous month. We will adjust
  851. llDays += DaysInMonth( yr, lCurMonth-1);
  852. lMonthsDone++;
  853. lCurMonth--;
  854. }
  855. // Months left over in prev year
  856. lMonthsLeft -= lMonthsDone-1;
  857. if ( 0 != lMonthsLeft )
  858. {
  859. yr--;
  860. lCurMonth = 12; // 11 is December.
  861. }
  862. }
  863. //
  864. // adjust current date to at most max of destination month
  865. //
  866. if ( llDays > 0 && st.wDay > DaysInMonth(yr, lCurMonth-1) )
  867. llDays += st.wDay - DaysInMonth(yr, lCurMonth-1);
  868. hIncr.QuadPart = hDay.QuadPart * llDays;
  869. fHandleMonth = true;
  870. }
  871. else if (0 == (_wcsicmp(L"MI", $3->value.pwszValue) & _wcsicmp(L"MINUTE", $3->value.pwszValue)))
  872. hIncr = hMinute;
  873. break;
  874. case L'W':
  875. case L'w':
  876. if (0 == (_wcsicmp(L"WK", $3->value.pwszValue) & _wcsicmp(L"WEEK", $3->value.pwszValue)))
  877. hIncr = hWeek;
  878. break;
  879. case L'D':
  880. case L'd':
  881. if (0 == (_wcsicmp(L"DD", $3->value.pwszValue) & _wcsicmp(L"DAY", $3->value.pwszValue)))
  882. hIncr = hDay;
  883. break;
  884. case L'H':
  885. case L'h':
  886. if (0 == (_wcsicmp(L"HH", $3->value.pwszValue) & _wcsicmp(L"HOUR", $3->value.pwszValue)))
  887. hIncr = hHour;
  888. break;
  889. case L'S':
  890. case L's':
  891. if (0 == (_wcsicmp(L"SS", $3->value.pwszValue) & _wcsicmp(L"SECOND", $3->value.pwszValue)))
  892. hIncr = hSecond;
  893. break;
  894. default:
  895. break;
  896. }
  897. if (0 == hIncr.LowPart && 0 == hIncr.HighPart)
  898. {
  899. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  900. m_pIPTProperties->SetErrorToken($3->value.pwszValue);
  901. m_pIPTProperties->SetErrorToken(
  902. L"YEAR, QUARTER, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND");
  903. YYABORT(DB_E_ERRORSINCOMMAND);
  904. }
  905. if ( fHandleMonth )
  906. {
  907. ((PROPVARIANT*)$7->value.pvValue)->hVal.QuadPart -= hIncr.QuadPart;
  908. #ifdef DEBUG
  909. SYSTEMTIME st1 = { 0, 0, 0, 0, 0, 0, 0, 0 };
  910. FileTimeToSystemTime( &((PROPVARIANT*)$7->value.pvValue)->filetime, &st1 );
  911. #endif
  912. }
  913. else
  914. {
  915. for (int i = 0; i < -((PROPVARIANT*)$5->value.pvValue)->iVal; i++)
  916. ((PROPVARIANT*)$7->value.pvValue)->hVal.QuadPart -= hIncr.QuadPart;
  917. }
  918. $$ = $7;
  919. DeleteDBQT($1);
  920. DeleteDBQT($3);
  921. DeleteDBQT($5);
  922. }
  923. | identifier '(' ')'
  924. {
  925. // should be getgmdate()
  926. AssertReq($1);
  927. if (0 != _wcsicmp(L"GetGMTDate", $1->value.pwszValue))
  928. {
  929. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  930. m_pIPTProperties->SetErrorToken($1->value.pwszValue);
  931. m_pIPTProperties->SetErrorToken(L"GetGMTDate");
  932. YYABORT(DB_E_ERRORSINCOMMAND);
  933. }
  934. DeleteDBQT($1);
  935. $1 = 0;
  936. $$ = PctAllocNode(DBVALUEKIND_VARIANT, DBOP_scalar_constant);
  937. if (NULL == $$)
  938. {
  939. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  940. YYABORT(E_OUTOFMEMORY);
  941. }
  942. HRESULT hr = CoFileTimeNow(&(((PROPVARIANT*)$$->value.pvValue)->filetime));
  943. ((PROPVARIANT*)$$->value.pvValue)->vt = VT_FILETIME;
  944. }
  945. ;
  946. boolean_literal:
  947. _TRUE
  948. {
  949. $$ = PctAllocNode(DBVALUEKIND_VARIANT, DBOP_scalar_constant);
  950. if (NULL == $$)
  951. {
  952. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  953. YYABORT(E_OUTOFMEMORY);
  954. }
  955. ((PROPVARIANT*)$$->value.pvValue)->vt = VT_BOOL;
  956. ((PROPVARIANT*)$$->value.pvValue)->boolVal = VARIANT_TRUE;
  957. }
  958. | _FALSE
  959. {
  960. $$ = PctAllocNode(DBVALUEKIND_VARIANT, DBOP_scalar_constant);
  961. if (NULL == $$)
  962. {
  963. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  964. YYABORT(E_OUTOFMEMORY);
  965. }
  966. ((PROPVARIANT*)$$->value.pvValue)->vt = VT_BOOL;
  967. ((PROPVARIANT*)$$->value.pvValue)->boolVal = VARIANT_FALSE;
  968. }
  969. ;
  970. identifier:
  971. _ID
  972. ;
  973. correlation_name:
  974. identifier
  975. ;
  976. /* 4.1 Query Specification */
  977. ordered_query_specification:
  978. query_specification opt_order_by_clause
  979. {
  980. AssertReq($1); // need a query specification tree
  981. if (NULL != $2) // add optional ORDER BY nodes
  982. {
  983. // Is project list built correctly?
  984. AssertReq($1->pctFirstChild);
  985. AssertReq($1->pctFirstChild->pctNextSibling);
  986. AssertReq($1->pctFirstChild->pctNextSibling->pctFirstChild);
  987. Assert(($1->op == DBOP_project) &&
  988. ($1->pctFirstChild->pctNextSibling->op == DBOP_project_list_anchor));
  989. DBCOMMANDTREE* pctSortList = $2->pctFirstChild;
  990. AssertReq(pctSortList);
  991. while (pctSortList)
  992. {
  993. // Is sort list built correctly?
  994. Assert(pctSortList->op == DBOP_sort_list_element);
  995. AssertReq(pctSortList->pctFirstChild);
  996. Assert((pctSortList->pctFirstChild->op == DBOP_column_name) ||
  997. (pctSortList->pctFirstChild->op == DBOP_scalar_constant));
  998. if (pctSortList->pctFirstChild->op == DBOP_scalar_constant)
  999. {
  1000. // we've got an ordinal rather than a column number, so we've got to
  1001. // walk through the project list to find the corresponding column
  1002. Assert(DBVALUEKIND_VARIANT == pctSortList->pctFirstChild->wKind);
  1003. Assert(VT_I4 == pctSortList->pctFirstChild->value.pvarValue->vt);
  1004. DBCOMMANDTREE* pctProjectList = $1->pctFirstChild->pctNextSibling->pctFirstChild;
  1005. AssertReq(pctProjectList);
  1006. LONG cProjectListElements = GetNumberOfSiblings(pctProjectList);
  1007. if ((cProjectListElements < pctSortList->pctFirstChild->value.pvarValue->lVal) ||
  1008. (0 >= pctSortList->pctFirstChild->value.pvarValue->lVal))
  1009. {
  1010. // ordinal is larger than number of elements in project list
  1011. WCHAR wchError[30];
  1012. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_ORDINAL_OUT_OF_RANGE);
  1013. swprintf(wchError, L"%d", pctSortList->pctFirstChild->value.pvarValue->lVal);
  1014. m_pIPTProperties->SetErrorToken(wchError);
  1015. swprintf(wchError, L"%d", cProjectListElements);
  1016. m_pIPTProperties->SetErrorToken(wchError);
  1017. YYABORT(DB_E_ERRORSINCOMMAND);
  1018. }
  1019. else
  1020. {
  1021. LONG lColumnNumber = 1;
  1022. while (pctProjectList &&
  1023. (lColumnNumber < pctSortList->pctFirstChild->value.pvarValue->lVal))
  1024. {
  1025. // find the ulVal'th column in the project list
  1026. Assert(pctProjectList->op == DBOP_project_list_element);
  1027. pctProjectList = pctProjectList->pctNextSibling;
  1028. lColumnNumber++;
  1029. }
  1030. DeleteDBQT(pctSortList->pctFirstChild);
  1031. HRESULT hr = HrQeTreeCopy(&pctSortList->pctFirstChild,
  1032. pctProjectList->pctFirstChild);
  1033. if (FAILED(hr))
  1034. {
  1035. m_pIPTProperties->SetErrorHResult(hr, MONSQL_OUT_OF_MEMORY);
  1036. YYABORT(hr);
  1037. }
  1038. }
  1039. }
  1040. pctSortList = pctSortList->pctNextSibling;
  1041. }
  1042. m_pIPTProperties->SetSortDesc(QUERY_SORTASCEND); // reset "stick" sort direction
  1043. $$ = PctCreateNode(DBOP_sort, $1, $2, NULL);
  1044. if ( NULL == $$ )
  1045. {
  1046. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1047. YYABORT( E_OUTOFMEMORY );
  1048. }
  1049. }
  1050. else
  1051. {
  1052. $$ = $1;
  1053. }
  1054. AssertReq($$);
  1055. }
  1056. ;
  1057. query_specification:
  1058. _SELECT opt_set_quantifier select_list from_clause opt_where_clause
  1059. {
  1060. AssertReq($3); // need a select list
  1061. AssertReq($4); // need a from clause
  1062. if (NULL != $4->pctNextSibling)
  1063. { // the from clause is a from view
  1064. if (DBOP_outall_name == $3->op)
  1065. {
  1066. DeleteDBQT( $3 );
  1067. $3 = $4;
  1068. $4 = $3->pctNextSibling;
  1069. $3->pctNextSibling = NULL;
  1070. AssertReq( $3->pctFirstChild ); // first project list element
  1071. DBCOMMANDTREE* pct = $3->pctFirstChild;
  1072. while ( pct )
  1073. { // recheck the properties to get current definitions
  1074. DeleteDBQT( pct->pctFirstChild );
  1075. pct->pctFirstChild =
  1076. PctMkColNodeFromStr( pct->value.pwszValue, m_pIPSession, m_pIPTProperties );
  1077. if ( 0 == pct->pctFirstChild )
  1078. YYABORT( DB_E_ERRORSINCOMMAND );
  1079. pct = pct->pctNextSibling;
  1080. }
  1081. }
  1082. else
  1083. {
  1084. $1 = $4;
  1085. $4 = $1->pctNextSibling;
  1086. $1->pctNextSibling = NULL;
  1087. AssertReq($3); // project list anchor
  1088. AssertReq($3->pctFirstChild); // first project list element
  1089. DBCOMMANDTREE* pctNewPrjLst = $3->pctFirstChild;
  1090. AssertReq($1); // project list anchor
  1091. AssertReq($1->pctFirstChild); // first project list element
  1092. DBCOMMANDTREE* pctViewPrjLst = NULL; // initialized within loop
  1093. while (pctNewPrjLst)
  1094. {
  1095. pctViewPrjLst = $1->pctFirstChild;
  1096. Assert( DBOP_project_list_element == pctNewPrjLst->op );
  1097. Assert( DBVALUEKIND_WSTR == pctNewPrjLst->wKind );
  1098. while ( pctViewPrjLst )
  1099. {
  1100. Assert( DBOP_project_list_element == pctViewPrjLst->op );
  1101. Assert( DBVALUEKIND_WSTR == pctViewPrjLst->wKind );
  1102. if ( 0 == _wcsicmp(pctNewPrjLst->value.pwszValue, pctViewPrjLst->value.pwszValue) )
  1103. break;
  1104. pctViewPrjLst = pctViewPrjLst->pctNextSibling;
  1105. if ( !pctViewPrjLst )
  1106. {
  1107. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_NOT_COLUMN_OF_VIEW );
  1108. m_pIPTProperties->SetErrorToken( pctNewPrjLst->value.pwszValue );
  1109. // UNDONE: Might want to include a view name on error message
  1110. YYABORT( DB_E_ERRORSINCOMMAND );
  1111. }
  1112. }
  1113. pctNewPrjLst = pctNewPrjLst->pctNextSibling;
  1114. }
  1115. DeleteDBQT( $1 );
  1116. $1 = 0;
  1117. }
  1118. }
  1119. else
  1120. {
  1121. // "standard" from clause
  1122. if ( DBOP_outall_name == $3->op )
  1123. if ( DBDIALECT_MSSQLJAWS != m_pIPSession->GetSQLDialect() )
  1124. {
  1125. // SELECT * only allowed in JAWS
  1126. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_SELECT_STAR );
  1127. YYABORT( DB_E_ERRORSINCOMMAND );
  1128. }
  1129. else
  1130. {
  1131. $3 = PctCreateNode( DBOP_project_list_element, $3, NULL );
  1132. if ( NULL == $3 )
  1133. {
  1134. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1135. YYABORT( E_OUTOFMEMORY );
  1136. }
  1137. $3 = PctCreateNode( DBOP_project_list_anchor, $3, NULL );
  1138. if ( NULL == $3 )
  1139. {
  1140. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1141. YYABORT( E_OUTOFMEMORY );
  1142. }
  1143. }
  1144. }
  1145. if ( NULL != $5 )
  1146. {
  1147. $1 = PctCreateNode( DBOP_select, $4, $5, NULL );
  1148. if ( NULL == $1 )
  1149. {
  1150. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1151. YYABORT( E_OUTOFMEMORY );
  1152. }
  1153. }
  1154. else
  1155. $1 = $4;
  1156. $$ = PctCreateNode( DBOP_project, $1, $3, NULL );
  1157. if ( NULL == $$ )
  1158. {
  1159. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1160. YYABORT( E_OUTOFMEMORY );
  1161. }
  1162. }
  1163. ;
  1164. opt_set_quantifier:
  1165. /* empty */
  1166. {
  1167. $$ = NULL;
  1168. }
  1169. | _ALL
  1170. {
  1171. // ignore ALL keyword, its just noise
  1172. $$ = NULL;
  1173. }
  1174. ;
  1175. select_list:
  1176. select_sublist
  1177. {
  1178. AssertReq($1);
  1179. $1 = PctReverse($1);
  1180. $$ = PctCreateNode(DBOP_project_list_anchor, $1, NULL);
  1181. if (NULL == $$)
  1182. {
  1183. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  1184. YYABORT(E_OUTOFMEMORY);
  1185. }
  1186. }
  1187. | '*'
  1188. {
  1189. $$ = PctCreateNode(DBOP_outall_name, NULL);
  1190. if (NULL == $$)
  1191. {
  1192. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  1193. YYABORT(E_OUTOFMEMORY);
  1194. }
  1195. }
  1196. ;
  1197. select_sublist:
  1198. select_sublist ',' derived_column
  1199. {
  1200. AssertReq($1);
  1201. AssertReq($3);
  1202. //
  1203. // chain project list elements together
  1204. //
  1205. $$ = PctLink( $3, $1 );
  1206. if ( NULL == $$ )
  1207. {
  1208. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  1209. YYABORT(E_OUTOFMEMORY);
  1210. }
  1211. }
  1212. | derived_column
  1213. ;
  1214. derived_column:
  1215. identifier
  1216. {
  1217. AssertReq($1);
  1218. $1->op = DBOP_project_list_element;
  1219. $1->pctFirstChild = PctMkColNodeFromStr($1->value.pwszValue, m_pIPSession, m_pIPTProperties);
  1220. if (NULL == $1->pctFirstChild)
  1221. YYABORT(DB_E_ERRORSINCOMMAND);
  1222. $$ = $1;
  1223. }
  1224. | correlation_name '.' identifier
  1225. {
  1226. AssertReq($1);
  1227. AssertReq($3);
  1228. DeleteDBQT($1); // UNDONE: Don't use the correlation name for now
  1229. $1 = NULL;
  1230. $3->op = DBOP_project_list_element;
  1231. $3->pctFirstChild = PctMkColNodeFromStr($3->value.pwszValue, m_pIPSession, m_pIPTProperties);
  1232. if (NULL == $3->pctFirstChild)
  1233. YYABORT(DB_E_ERRORSINCOMMAND);
  1234. $$ = $3;
  1235. }
  1236. | _CREATE
  1237. {
  1238. $$ = PctMkColNodeFromStr(L"CREATE", m_pIPSession, m_pIPTProperties);
  1239. if (NULL == $$)
  1240. YYABORT(DB_E_ERRORSINCOMMAND);
  1241. $$ = PctCreateNode(DBOP_project_list_element, DBVALUEKIND_WSTR, $$, NULL);
  1242. if ( NULL == $$ )
  1243. {
  1244. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1245. YYABORT( E_OUTOFMEMORY );
  1246. }
  1247. $$->value.pwszValue = CoTaskStrDup(L"CREATE");
  1248. }
  1249. ;
  1250. /* 4.3 FROM Clause */
  1251. from_clause:
  1252. common_from_clause
  1253. | from_view_clause
  1254. ;
  1255. common_from_clause:
  1256. _FROM scope_specification opt_AS_clause
  1257. {
  1258. AssertReq( $2 );
  1259. $$ = $2;
  1260. if ( NULL != $3 )
  1261. {
  1262. $3->pctFirstChild = $$;
  1263. $$ = $3;
  1264. }
  1265. }
  1266. ;
  1267. scope_specification:
  1268. unqualified_scope_specification
  1269. {
  1270. AssertReq( $1 );
  1271. $$ = $1;
  1272. }
  1273. | qualified_scope_specification
  1274. {
  1275. AssertReq( $1 );
  1276. $$ = $1;
  1277. }
  1278. | union_all_scope_specification
  1279. {
  1280. AssertReq( $1 );
  1281. $$ = $1;
  1282. }
  1283. ;
  1284. unqualified_scope_specification:
  1285. _SCOPE '(' scope_definition ')'
  1286. { // _SCOPE '(' scope_definition ')'
  1287. AssertReq( $3 );
  1288. //
  1289. // Set the machine and catalog to the defaults
  1290. //
  1291. ($3->value.pdbcntnttblValue)->pwszMachine = CoTaskStrDup( m_pIPSession->GetDefaultMachine() );
  1292. if ( NULL == ($3->value.pdbcntnttblValue)->pwszMachine )
  1293. {
  1294. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1295. YYABORT( E_OUTOFMEMORY );
  1296. }
  1297. ($3->value.pdbcntnttblValue)->pwszCatalog = CoTaskStrDup( m_pIPSession->GetDefaultCatalog() );
  1298. if ( NULL == ($3->value.pdbcntnttblValue)->pwszCatalog )
  1299. {
  1300. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1301. YYABORT( E_OUTOFMEMORY );
  1302. }
  1303. $$ = $3;
  1304. }
  1305. ;
  1306. qualified_scope_specification:
  1307. machine_name _DOTDOTDOT_SCOPE '(' scope_definition ')'
  1308. { // machine_name _DOTDOTDOT_SCOPE '(' scope_definition ')'
  1309. AssertReq( $1 );
  1310. AssertReq( $4 );
  1311. ($4->value.pdbcntnttblValue)->pwszMachine = CoTaskStrDup( $1->value.pwszValue );
  1312. if ( NULL == ($4->value.pdbcntnttblValue)->pwszMachine )
  1313. {
  1314. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1315. YYABORT( E_OUTOFMEMORY );
  1316. }
  1317. SCODE sc = m_pIPSession->GetIPVerifyPtr()->VerifyCatalog(
  1318. $1->value.pwszValue,
  1319. m_pIPSession->GetDefaultCatalog() );
  1320. if ( S_OK != sc )
  1321. {
  1322. m_pIPTProperties->SetErrorHResult( sc, MONSQL_INVALID_CATALOG );
  1323. m_pIPTProperties->SetErrorToken( m_pIPSession->GetDefaultCatalog() );
  1324. YYABORT( sc );
  1325. }
  1326. ($4->value.pdbcntnttblValue)->pwszCatalog = CoTaskStrDup( m_pIPSession->GetDefaultCatalog() );
  1327. if ( NULL == ($4->value.pdbcntnttblValue)->pwszCatalog )
  1328. {
  1329. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1330. YYABORT( E_OUTOFMEMORY );
  1331. }
  1332. DeleteDBQT( $1 );
  1333. $$ = $4;
  1334. }
  1335. | machine_name _DOT catalog_name _DOTDOT_SCOPE '(' scope_definition ')'
  1336. { // machine_name _DOT catalog_name _DOTDOT_SCOPE '(' scope_definition ')'
  1337. AssertReq( $1 );
  1338. AssertReq( $3 );
  1339. AssertReq( $6 );
  1340. ($6->value.pdbcntnttblValue)->pwszMachine = CoTaskStrDup( $1->value.pwszValue );
  1341. if ( NULL == ($6->value.pdbcntnttblValue)->pwszMachine )
  1342. {
  1343. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1344. YYABORT( E_OUTOFMEMORY );
  1345. }
  1346. //
  1347. // Verify catalog on machine specified
  1348. //
  1349. SCODE sc = m_pIPSession->GetIPVerifyPtr()->VerifyCatalog(
  1350. $1->value.pwszValue,
  1351. $3->value.pwszValue );
  1352. if ( S_OK != sc )
  1353. {
  1354. m_pIPTProperties->SetErrorHResult( sc, MONSQL_INVALID_CATALOG );
  1355. m_pIPTProperties->SetErrorToken( $3->value.pwszValue );
  1356. YYABORT( sc );
  1357. }
  1358. ($6->value.pdbcntnttblValue)->pwszCatalog = CoTaskStrDup( $3->value.pwszValue );
  1359. if ( NULL == ($6->value.pdbcntnttblValue)->pwszCatalog )
  1360. {
  1361. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1362. YYABORT( E_OUTOFMEMORY );
  1363. }
  1364. DeleteDBQT( $1 );
  1365. DeleteDBQT( $3 );
  1366. $$ = $6;
  1367. }
  1368. | catalog_name _DOTDOT_SCOPE '(' scope_definition ')'
  1369. { // catalog_name _DOTDOT_SCOPE '(' scope_definition ')'
  1370. AssertReq( $1 );
  1371. AssertReq( $4 );
  1372. ($4->value.pdbcntnttblValue)->pwszMachine = CoTaskStrDup( m_pIPSession->GetDefaultMachine() );
  1373. if ( NULL == ($4->value.pdbcntnttblValue)->pwszMachine )
  1374. {
  1375. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1376. YYABORT( E_OUTOFMEMORY );
  1377. }
  1378. //
  1379. // See if catalog is valid on default machine
  1380. //
  1381. SCODE sc = m_pIPSession->GetIPVerifyPtr()->VerifyCatalog(
  1382. m_pIPSession->GetDefaultMachine(),
  1383. $1->value.pwszValue );
  1384. if ( S_OK != sc )
  1385. {
  1386. m_pIPTProperties->SetErrorHResult( sc, MONSQL_INVALID_CATALOG );
  1387. m_pIPTProperties->SetErrorToken( $1->value.pwszValue );
  1388. YYABORT( sc );
  1389. }
  1390. ($4->value.pdbcntnttblValue)->pwszCatalog = CoTaskStrDup( $1->value.pwszValue );
  1391. if ( NULL == ($4->value.pdbcntnttblValue)->pwszCatalog )
  1392. {
  1393. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1394. YYABORT( E_OUTOFMEMORY );
  1395. }
  1396. DeleteDBQT( $1 );
  1397. $$ = $4;
  1398. }
  1399. ;
  1400. machine_name:
  1401. identifier
  1402. {
  1403. AssertReq( $1 );
  1404. $$ = $1;
  1405. }
  1406. ;
  1407. catalog_name:
  1408. identifier
  1409. {
  1410. AssertReq( $1 );
  1411. //
  1412. // Defer validation of the catalog to the point where we
  1413. // know the machine name. Return whatever was parsed here.
  1414. //
  1415. $$ = $1;
  1416. }
  1417. ;
  1418. scope_definition:
  1419. /* empty */
  1420. { // empty rule for scope_definition
  1421. //
  1422. // Create a DBOP_content_table node with default scope settings
  1423. //
  1424. $$ = PctAllocNode( DBVALUEKIND_CONTENTTABLE, DBOP_content_table );
  1425. if ( NULL == $$ )
  1426. {
  1427. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND,
  1428. MONSQL_OUT_OF_MEMORY );
  1429. YYABORT( E_OUTOFMEMORY );
  1430. }
  1431. }
  1432. | scope_element_list
  1433. { // scope_element_list
  1434. AssertReq($1);
  1435. $1 = PctReverse( $1 );
  1436. $$ = PctCreateNode( DBOP_scope_list_anchor, $1, NULL );
  1437. if ( NULL == $$ )
  1438. {
  1439. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1440. YYABORT( E_OUTOFMEMORY );
  1441. }
  1442. $$ = PctCreateNode( DBOP_content_table, DBVALUEKIND_CONTENTTABLE, $$, NULL );
  1443. if ( NULL == $$ )
  1444. {
  1445. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1446. YYABORT( E_OUTOFMEMORY );
  1447. }
  1448. }
  1449. ;
  1450. scope_element_list:
  1451. scope_element_list ',' scope_element
  1452. {
  1453. AssertReq( $1 );
  1454. AssertReq( $3);
  1455. //
  1456. // chain scope list elements together
  1457. //
  1458. $$ = PctLink( $3, $1 );
  1459. }
  1460. | scope_element
  1461. {
  1462. AssertReq( $1 );
  1463. $$ = $1;
  1464. }
  1465. ;
  1466. scope_element:
  1467. '\'' opt_traversal_exclusivity path_or_virtual_root_list '\''
  1468. {
  1469. AssertReq( $2 );
  1470. AssertReq( $3 );
  1471. $3 = PctReverse( $3 );
  1472. SetDepthAndInclusion( $2, $3 );
  1473. DeleteDBQT( $2 );
  1474. $$ = $3;
  1475. }
  1476. | '\'' opt_traversal_exclusivity '(' path_or_virtual_root_list ')' '\''
  1477. {
  1478. AssertReq( $2 );
  1479. AssertReq( $4 );
  1480. $4 = PctReverse( $4 );
  1481. SetDepthAndInclusion( $2, $4 );
  1482. DeleteDBQT( $2 );
  1483. $$ = $4;
  1484. }
  1485. ;
  1486. opt_traversal_exclusivity:
  1487. /* empty */
  1488. {
  1489. $$ = PctAllocNode( DBVALUEKIND_CONTENTSCOPE, DBOP_scope_list_element );
  1490. if ( NULL == $$ )
  1491. {
  1492. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1493. YYABORT( E_OUTOFMEMORY );
  1494. }
  1495. $$->value.pdbcntntscpValue->dwFlags |= SCOPE_FLAG_DEEP;
  1496. $$->value.pdbcntntscpValue->dwFlags |= SCOPE_FLAG_INCLUDE;
  1497. }
  1498. | _DEEP_TRAVERSAL _OF
  1499. {
  1500. $$ = PctAllocNode( DBVALUEKIND_CONTENTSCOPE, DBOP_scope_list_element );
  1501. if ( NULL == $$ )
  1502. {
  1503. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1504. YYABORT( E_OUTOFMEMORY );
  1505. }
  1506. $$->value.pdbcntntscpValue->dwFlags |= SCOPE_FLAG_DEEP;
  1507. $$->value.pdbcntntscpValue->dwFlags |= SCOPE_FLAG_INCLUDE;
  1508. }
  1509. | _SHALLOW_TRAVERSAL _OF
  1510. {
  1511. $$ = PctAllocNode( DBVALUEKIND_CONTENTSCOPE, DBOP_scope_list_element );
  1512. if ( NULL == $$ )
  1513. {
  1514. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1515. YYABORT( E_OUTOFMEMORY );
  1516. }
  1517. $$->value.pdbcntntscpValue->dwFlags &= ~(SCOPE_FLAG_DEEP);
  1518. $$->value.pdbcntntscpValue->dwFlags |= SCOPE_FLAG_INCLUDE;
  1519. }
  1520. /* ************* UNDONE ********************
  1521. | _EXCLUDE_SEARCH_TRAVERSAL _OF
  1522. {
  1523. // m_pIPTProperties->GetScopeDataPtr()->SetTemporaryDepth(QUERY_EXCLUDE);
  1524. $$ = PctCreateNode( DBOP_scope_list_element, NULL );
  1525. if ( NULL == $$ )
  1526. {
  1527. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1528. YYABORT( E_OUTOFMEMORY );
  1529. }
  1530. $$->value.pdbcntntscpValue->dwFlags &= ~(SCOPE_FLAG_DEEP);
  1531. $$->value.pdbcntntscpValue->dwFlags &= ~(SCOPE_FLAG_INCLUDE);
  1532. }
  1533. ************* UNDONE ******************** */
  1534. ;
  1535. path_or_virtual_root_list:
  1536. path_or_virtual_root_list ',' path_or_virtual_root
  1537. {
  1538. AssertReq( $1 );
  1539. AssertReq( $3 );
  1540. //
  1541. // chain path/vpath nodes together
  1542. //
  1543. $$ = PctLink( $3, $1 );
  1544. }
  1545. | path_or_virtual_root
  1546. {
  1547. AssertReq( $1 );
  1548. $$ = $1;
  1549. }
  1550. ;
  1551. path_or_virtual_root:
  1552. _URL
  1553. {
  1554. AssertReq( $1 );
  1555. $$ = PctAllocNode( DBVALUEKIND_CONTENTSCOPE, DBOP_scope_list_element );
  1556. if ( NULL == $$ )
  1557. {
  1558. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND,
  1559. MONSQL_OUT_OF_MEMORY );
  1560. YYABORT( E_OUTOFMEMORY );
  1561. }
  1562. $$->value.pdbcntntscpValue->pwszElementValue =
  1563. CoTaskStrDup( ($1->value.pvarValue)->bstrVal );
  1564. if ( NULL == $$->value.pdbcntntscpValue->pwszElementValue )
  1565. {
  1566. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND,
  1567. MONSQL_OUT_OF_MEMORY );
  1568. YYABORT( E_OUTOFMEMORY );
  1569. }
  1570. if ( NULL != wcschr(((PROPVARIANT*)$1->value.pvValue)->bstrVal, L'/'))
  1571. $$->value.pdbcntntscpValue->dwFlags |= SCOPE_TYPE_VPATH;
  1572. else
  1573. $$->value.pdbcntntscpValue->dwFlags |= SCOPE_TYPE_WINPATH;
  1574. //
  1575. // Path names need backlashes not forward slashes
  1576. //
  1577. for (WCHAR *wcsLetter = $$->value.pdbcntntscpValue->pwszElementValue;
  1578. *wcsLetter != L'\0';
  1579. wcsLetter++)
  1580. if (L'/' == *wcsLetter)
  1581. *wcsLetter = L'\\';
  1582. DeleteDBQT( $1 );
  1583. }
  1584. ;
  1585. opt_AS_clause:
  1586. /* empty */
  1587. {
  1588. $$ = NULL;
  1589. }
  1590. | _AS correlation_name
  1591. {
  1592. AssertReq($2);
  1593. // $2->op = DBOP_alias; // retag _ID node to be table alias
  1594. // $$ = $2; // UNDONE: This doesn't work with Index Server
  1595. DeleteDBQT($2);
  1596. $2 = NULL;
  1597. $$ = NULL;
  1598. }
  1599. ;
  1600. /* 4,3,4 View Name */
  1601. from_view_clause:
  1602. _FROM view_name
  1603. { // _FROM view_name
  1604. AssertReq( $2 );
  1605. // node telling where the view is defined
  1606. Assert( DBOP_content_table == $2->op );
  1607. // name of the view
  1608. AssertReq( $2->pctNextSibling );
  1609. $$ = m_pIPSession->GetLocalViewList()->GetViewDefinition( m_pIPTProperties,
  1610. $2->pctNextSibling->value.pwszValue,
  1611. ($2->value.pdbcntnttblValue)->pwszCatalog );
  1612. if ( 0 == $$ )
  1613. $$ = m_pIPSession->GetGlobalViewList()->GetViewDefinition( m_pIPTProperties,
  1614. $2->pctNextSibling->value.pwszValue,
  1615. ($2->value.pdbcntnttblValue)->pwszCatalog );
  1616. if ( 0 == $$ )
  1617. { // If this isn't JAWS, this is an undefined view
  1618. if (DBDIALECT_MSSQLJAWS != m_pIPSession->GetSQLDialect())
  1619. {
  1620. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_VIEW_NOT_DEFINED );
  1621. m_pIPTProperties->SetErrorToken( $2->pctNextSibling->value.pwszValue );
  1622. m_pIPTProperties->SetErrorToken( ($2->value.pdbcntnttblValue)->pwszCatalog );
  1623. YYABORT( DB_E_ERRORSINCOMMAND );
  1624. }
  1625. // setting the default scope for JAWS
  1626. CScopeData* pScopeData = m_pIPTProperties->GetScopeDataPtr();
  1627. pScopeData->SetTemporaryDepth(QUERY_DEEP);
  1628. pScopeData->MaskTemporaryDepth(QUERY_VIRTUAL_PATH);
  1629. pScopeData->SetTemporaryScope(VAL_AND_CCH_MINUS_NULL(L"/"));
  1630. pScopeData->SetTemporaryCatalog($2->value.pwszValue, wcslen($2->value.pwszValue));
  1631. pScopeData->IncrementScopeCount();
  1632. $$ = $2->pctNextSibling;
  1633. $2->pctNextSibling = NULL;
  1634. DeleteDBQT($2);
  1635. }
  1636. else // actually a view name
  1637. {
  1638. // If we didn't store scope information (global views), set up the scope now
  1639. if ( 0 == $$->pctNextSibling )
  1640. {
  1641. // name of the view
  1642. DeleteDBQT( $2->pctNextSibling );
  1643. $2->pctNextSibling = 0;
  1644. $$->pctNextSibling = $2;
  1645. }
  1646. else
  1647. {
  1648. AssertReq( DBOP_content_table == $$->pctNextSibling->op );
  1649. DeleteDBQT( $2 ); // throw away the view name
  1650. }
  1651. }
  1652. }
  1653. ;
  1654. view_name:
  1655. _TEMPVIEW
  1656. { // _TEMPVIEW
  1657. AssertReq( $1 );
  1658. $$ = PctAllocNode( DBVALUEKIND_CONTENTTABLE, DBOP_content_table );
  1659. if ( 0 == $$ )
  1660. {
  1661. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1662. YYABORT( E_OUTOFMEMORY );
  1663. }
  1664. ($$->value.pdbcntnttblValue)->pwszMachine = CoTaskStrDup( m_pIPSession->GetDefaultMachine() );
  1665. if ( 0 == ($$->value.pdbcntnttblValue)->pwszMachine )
  1666. {
  1667. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1668. YYABORT( E_OUTOFMEMORY );
  1669. }
  1670. ($$->value.pdbcntnttblValue)->pwszCatalog = CoTaskStrDup( m_pIPSession->GetDefaultCatalog() );
  1671. if ( 0 == ($$->value.pdbcntnttblValue)->pwszCatalog )
  1672. {
  1673. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1674. YYABORT( E_OUTOFMEMORY );
  1675. }
  1676. $$->pctNextSibling = $1;
  1677. }
  1678. | identifier
  1679. { // identifier
  1680. AssertReq( $1 );
  1681. $$ = PctAllocNode( DBVALUEKIND_CONTENTTABLE, DBOP_content_table );
  1682. if ( 0 == $$ )
  1683. {
  1684. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1685. YYABORT( E_OUTOFMEMORY );
  1686. }
  1687. ($$->value.pdbcntnttblValue)->pwszMachine = CoTaskStrDup( m_pIPSession->GetDefaultMachine() );
  1688. if ( 0 == ($$->value.pdbcntnttblValue)->pwszMachine )
  1689. {
  1690. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1691. YYABORT( E_OUTOFMEMORY );
  1692. }
  1693. ($$->value.pdbcntnttblValue)->pwszCatalog = CoTaskStrDup( m_pIPSession->GetDefaultCatalog() );
  1694. if ( 0 == ($$->value.pdbcntnttblValue)->pwszCatalog )
  1695. {
  1696. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1697. YYABORT( E_OUTOFMEMORY );
  1698. }
  1699. $$->pctNextSibling = $1;
  1700. }
  1701. | catalog_name _DOTDOT _TEMPVIEW
  1702. { // catalog_name _DOTDOT _TEMPVIEW
  1703. AssertReq($1);
  1704. AssertReq($3);
  1705. $$ = PctAllocNode( DBVALUEKIND_CONTENTTABLE, DBOP_content_table );
  1706. if ( 0 == $$ )
  1707. {
  1708. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1709. YYABORT( E_OUTOFMEMORY );
  1710. }
  1711. ($$->value.pdbcntnttblValue)->pwszMachine = CoTaskStrDup( m_pIPSession->GetDefaultMachine() );
  1712. if ( 0 == ($$->value.pdbcntnttblValue)->pwszMachine )
  1713. {
  1714. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1715. YYABORT( E_OUTOFMEMORY );
  1716. }
  1717. ($$->value.pdbcntnttblValue)->pwszCatalog = CoTaskStrDup( $1->value.pwszValue );
  1718. if ( 0 == ($$->value.pdbcntnttblValue)->pwszCatalog )
  1719. {
  1720. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1721. YYABORT( E_OUTOFMEMORY );
  1722. }
  1723. DeleteDBQT( $1 );
  1724. $$->pctNextSibling = $3;
  1725. }
  1726. | catalog_name _DOTDOT identifier
  1727. { // catalog_name _DOTDOT identifier
  1728. AssertReq($1);
  1729. AssertReq($3);
  1730. $$ = PctAllocNode( DBVALUEKIND_CONTENTTABLE, DBOP_content_table );
  1731. if ( 0 == $$ )
  1732. {
  1733. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1734. YYABORT( E_OUTOFMEMORY );
  1735. }
  1736. ($$->value.pdbcntnttblValue)->pwszMachine = CoTaskStrDup( m_pIPSession->GetDefaultMachine() );
  1737. if ( 0 == ($$->value.pdbcntnttblValue)->pwszMachine )
  1738. {
  1739. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1740. YYABORT( E_OUTOFMEMORY );
  1741. }
  1742. ($$->value.pdbcntnttblValue)->pwszCatalog = CoTaskStrDup( $1->value.pwszValue );
  1743. if ( 0 == ($$->value.pdbcntnttblValue)->pwszCatalog )
  1744. {
  1745. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1746. YYABORT( E_OUTOFMEMORY );
  1747. }
  1748. DeleteDBQT( $1 );
  1749. $$->pctNextSibling = $3;
  1750. }
  1751. | machine_name _DOT catalog_name _DOTDOT _TEMPVIEW
  1752. { // machine_name _DOT catalog_name _DOTDOT _TEMPVIEW
  1753. AssertReq( $1 );
  1754. AssertReq( $3 );
  1755. AssertReq( $5 );
  1756. $$ = PctAllocNode( DBVALUEKIND_CONTENTTABLE, DBOP_content_table );
  1757. if ( 0 == $$ )
  1758. {
  1759. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1760. YYABORT( E_OUTOFMEMORY );
  1761. }
  1762. ($$->value.pdbcntnttblValue)->pwszMachine = CoTaskStrDup( $1->value.pwszValue );
  1763. if ( 0 == ($$->value.pdbcntnttblValue)->pwszMachine )
  1764. {
  1765. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1766. YYABORT( E_OUTOFMEMORY );
  1767. }
  1768. ($$->value.pdbcntnttblValue)->pwszCatalog = CoTaskStrDup( $3->value.pwszValue );
  1769. if ( 0 == ($$->value.pdbcntnttblValue)->pwszCatalog )
  1770. {
  1771. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1772. YYABORT( E_OUTOFMEMORY );
  1773. }
  1774. DeleteDBQT( $1 );
  1775. DeleteDBQT( $3 );
  1776. $$->pctNextSibling = $5;
  1777. }
  1778. | machine_name _DOT catalog_name _DOTDOT identifier
  1779. { // machine_name _DOT catalog_name _DOTDOT identifier
  1780. AssertReq( $1 );
  1781. AssertReq( $3 );
  1782. AssertReq( $5 );
  1783. $$ = PctAllocNode( DBVALUEKIND_CONTENTTABLE, DBOP_content_table );
  1784. if ( 0 == $$ )
  1785. {
  1786. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1787. YYABORT( E_OUTOFMEMORY );
  1788. }
  1789. ($$->value.pdbcntnttblValue)->pwszMachine = CoTaskStrDup( $1->value.pwszValue );
  1790. if ( 0 == ($$->value.pdbcntnttblValue)->pwszMachine )
  1791. {
  1792. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1793. YYABORT( E_OUTOFMEMORY );
  1794. }
  1795. ($$->value.pdbcntnttblValue)->pwszCatalog = CoTaskStrDup( $3->value.pwszValue );
  1796. if ( 0 == ($$->value.pdbcntnttblValue)->pwszCatalog )
  1797. {
  1798. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1799. YYABORT( E_OUTOFMEMORY );
  1800. }
  1801. DeleteDBQT( $1 );
  1802. DeleteDBQT( $3 );
  1803. $$->pctNextSibling = $5;
  1804. }
  1805. | machine_name _DOTDOTDOT identifier
  1806. { // machine_name _DOTDOTDOT identifier
  1807. AssertReq( $1 );
  1808. AssertReq( $3 );
  1809. $$ = PctAllocNode( DBVALUEKIND_CONTENTTABLE, DBOP_content_table );
  1810. if ( 0 == $$ )
  1811. {
  1812. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1813. YYABORT( E_OUTOFMEMORY );
  1814. }
  1815. ($$->value.pdbcntnttblValue)->pwszMachine = CoTaskStrDup( $1->value.pwszValue );
  1816. if ( 0 == ($$->value.pdbcntnttblValue)->pwszMachine )
  1817. {
  1818. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1819. YYABORT( E_OUTOFMEMORY );
  1820. }
  1821. ($$->value.pdbcntnttblValue)->pwszCatalog = CoTaskStrDup( m_pIPSession->GetDefaultCatalog() );
  1822. if ( 0 == ($$->value.pdbcntnttblValue)->pwszCatalog )
  1823. {
  1824. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1825. YYABORT( E_OUTOFMEMORY );
  1826. }
  1827. DeleteDBQT( $1 );
  1828. $$->pctNextSibling = $3;
  1829. }
  1830. | machine_name _DOTDOTDOT _TEMPVIEW
  1831. { // machine_name _DOTDOTDOT _TEMPVIEW
  1832. AssertReq( $1 );
  1833. AssertReq( $3 );
  1834. $$ = PctAllocNode( DBVALUEKIND_CONTENTTABLE, DBOP_content_table );
  1835. if ( 0 == $$ )
  1836. {
  1837. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1838. YYABORT( E_OUTOFMEMORY );
  1839. }
  1840. ($$->value.pdbcntnttblValue)->pwszMachine = CoTaskStrDup( $1->value.pwszValue );
  1841. if ( 0 == ($$->value.pdbcntnttblValue)->pwszMachine )
  1842. {
  1843. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1844. YYABORT( E_OUTOFMEMORY );
  1845. }
  1846. ($$->value.pdbcntnttblValue)->pwszCatalog = CoTaskStrDup( m_pIPSession->GetDefaultCatalog() );
  1847. if ( 0 == ($$->value.pdbcntnttblValue)->pwszCatalog )
  1848. {
  1849. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  1850. YYABORT( E_OUTOFMEMORY );
  1851. }
  1852. DeleteDBQT( $1 );
  1853. $$->pctNextSibling = $3;
  1854. }
  1855. ;
  1856. /* 4.3.6 Olympus FROM Clause */
  1857. union_all_scope_specification:
  1858. '(' union_all_scope_element ')'
  1859. {
  1860. $$ = $2;
  1861. }
  1862. ;
  1863. union_all_scope_element:
  1864. union_all_scope_element _UNION _ALL explicit_table
  1865. {
  1866. AssertReq( $1 );
  1867. AssertReq( $4 );
  1868. $$ = PctCreateNode( DBOP_set_union, $1, $4, NULL );
  1869. if ( NULL == $$ )
  1870. {
  1871. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND,
  1872. MONSQL_OUT_OF_MEMORY );
  1873. YYABORT( E_OUTOFMEMORY );
  1874. }
  1875. }
  1876. | explicit_table _UNION _ALL explicit_table
  1877. {
  1878. AssertReq( $1 );
  1879. AssertReq( $4 );
  1880. $$ = PctCreateNode( DBOP_set_union, $1, $4, NULL );
  1881. if ( NULL == $$ )
  1882. {
  1883. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND,
  1884. MONSQL_OUT_OF_MEMORY );
  1885. YYABORT( E_OUTOFMEMORY );
  1886. }
  1887. }
  1888. ;
  1889. explicit_table:
  1890. _TABLE qualified_scope_specification
  1891. {
  1892. AssertReq( $2 );
  1893. $$ = $2;
  1894. }
  1895. ;
  1896. /* 4.4 WHERE Clause */
  1897. opt_where_clause:
  1898. /* empty */
  1899. {
  1900. $$ = NULL;
  1901. }
  1902. | where_clause
  1903. ;
  1904. where_clause:
  1905. _WHERE search_condition
  1906. {
  1907. AssertReq($2);
  1908. $$ = $2;
  1909. }
  1910. | _WHERE _PASSTHROUGH '(' _STRING ')'
  1911. {
  1912. AssertReq($4);
  1913. if (wcslen(((PROPVARIANT*)$4->value.pvValue)->bstrVal))
  1914. m_pIPTProperties->AppendCiRestriction(((PROPVARIANT*)$4->value.pvValue)->bstrVal,
  1915. wcslen(((PROPVARIANT*)$4->value.pvValue)->bstrVal));
  1916. UINT cSize = 0;
  1917. CIPROPERTYDEF* pPropTable = m_pIPSession->m_pCPropertyList->GetPropertyTable(&cSize);
  1918. if (!pPropTable)
  1919. {
  1920. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  1921. YYABORT(E_OUTOFMEMORY);
  1922. }
  1923. if (FAILED(CITextToSelectTreeEx(((PROPVARIANT*)$4->value.pvValue)->bstrVal,
  1924. ISQLANG_V2,
  1925. &yyval,
  1926. cSize,
  1927. pPropTable,
  1928. m_pIPSession->GetLCID())))
  1929. {
  1930. m_pIPSession->m_pCPropertyList->DeletePropertyTable(pPropTable, cSize);
  1931. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_CITEXTTOSELECTTREE_FAILED);
  1932. m_pIPTProperties->SetErrorToken(((PROPVARIANT*)$4->value.pvValue)->bstrVal);
  1933. YYABORT(DB_E_ERRORSINCOMMAND);
  1934. }
  1935. DeleteDBQT($4);
  1936. $4 = NULL;
  1937. m_pIPSession->m_pCPropertyList->DeletePropertyTable(pPropTable, cSize);
  1938. }
  1939. ;
  1940. predicate:
  1941. comparison_predicate
  1942. | contains_predicate
  1943. | freetext_predicate
  1944. | like_predicate
  1945. | matches_predicate
  1946. | vector_comparison_predicate
  1947. | null_predicate
  1948. ;
  1949. /* 4.4.3 Comparison Predicate */
  1950. comparison_predicate:
  1951. column_reference_or_cast comp_op typed_literal
  1952. {
  1953. AssertReq($1);
  1954. AssertReq($2);
  1955. if (m_pIPTProperties->GetDBType() & DBTYPE_VECTOR)
  1956. {
  1957. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  1958. m_pIPTProperties->SetErrorToken(L"<literal>");
  1959. m_pIPTProperties->SetErrorToken(L"ARRAY");
  1960. YYABORT(DB_E_ERRORSINCOMMAND);
  1961. }
  1962. $1->pctNextSibling = $3;
  1963. $2->pctFirstChild = $1;
  1964. $$ = $2;
  1965. }
  1966. ;
  1967. column_reference_or_cast:
  1968. column_reference
  1969. {
  1970. AssertReq($1);
  1971. m_pIPTProperties->UseCiColumn(L'@');
  1972. $$ = $1;
  1973. }
  1974. | _CAST '(' column_reference _AS dbtype ')'
  1975. {
  1976. AssertReq($3);
  1977. AssertReq($5);
  1978. if (DBDIALECT_MSSQLJAWS != m_pIPSession->GetSQLDialect())
  1979. {
  1980. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  1981. m_pIPTProperties->SetErrorToken(L"CAST");
  1982. m_pIPTProperties->SetErrorToken(L"column_reference");
  1983. YYABORT(DB_E_ERRORSINCOMMAND);
  1984. }
  1985. m_pIPTProperties->UseCiColumn(L'@');
  1986. m_pIPTProperties->SetDBType($5->value.usValue);
  1987. DeleteDBQT($5);
  1988. $$ = $3;
  1989. }
  1990. ;
  1991. column_reference:
  1992. identifier
  1993. {
  1994. AssertReq($1);
  1995. $$ = PctMkColNodeFromStr($1->value.pwszValue, m_pIPSession, m_pIPTProperties);
  1996. if (NULL == $$)
  1997. YYABORT(DB_E_ERRORSINCOMMAND);
  1998. m_pIPTProperties->SetCiColumn($1->value.pwszValue);
  1999. DeleteDBQT($1);
  2000. $1 = NULL;
  2001. }
  2002. | correlation_name '.' identifier
  2003. {
  2004. AssertReq($1);
  2005. AssertReq($3);
  2006. $$ = PctMkColNodeFromStr($3->value.pwszValue, m_pIPSession, m_pIPTProperties);
  2007. if (NULL == $$)
  2008. YYABORT(DB_E_ERRORSINCOMMAND);
  2009. m_pIPTProperties->SetCiColumn($3->value.pwszValue);
  2010. DeleteDBQT($3);
  2011. $3 = NULL;
  2012. DeleteDBQT($1); // UNDONE: Don't use the correlation name for now
  2013. $1 = NULL;
  2014. }
  2015. | _CREATE
  2016. {
  2017. m_pIPTProperties->SetCiColumn(L"CREATE");
  2018. $$ = PctMkColNodeFromStr(L"CREATE", m_pIPSession, m_pIPTProperties);
  2019. if (NULL == $$)
  2020. YYABORT(DB_E_ERRORSINCOMMAND);
  2021. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"CREATE "));
  2022. }
  2023. ;
  2024. comp_op:
  2025. '='
  2026. {
  2027. $$ = PctCreateRelationalNode(DBOP_equal, DEFAULTWEIGHT);
  2028. if (NULL == $$)
  2029. {
  2030. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2031. YYABORT(E_OUTOFMEMORY);
  2032. }
  2033. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"="));
  2034. }
  2035. | _NE
  2036. {
  2037. $$ = PctCreateRelationalNode(DBOP_not_equal, DEFAULTWEIGHT);
  2038. if (NULL == $$)
  2039. {
  2040. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2041. YYABORT(E_OUTOFMEMORY);
  2042. }
  2043. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"!="));
  2044. }
  2045. | '<'
  2046. {
  2047. $$ = PctCreateRelationalNode(DBOP_less, DEFAULTWEIGHT);
  2048. if (NULL == $$)
  2049. {
  2050. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2051. YYABORT(E_OUTOFMEMORY);
  2052. }
  2053. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"<"));
  2054. }
  2055. | '>'
  2056. {
  2057. $$ = PctCreateRelationalNode(DBOP_greater, DEFAULTWEIGHT);
  2058. if (NULL == $$)
  2059. {
  2060. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2061. YYABORT(E_OUTOFMEMORY);
  2062. }
  2063. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L">"));
  2064. }
  2065. | _LE
  2066. {
  2067. $$ = PctCreateRelationalNode(DBOP_less_equal, DEFAULTWEIGHT);
  2068. if (NULL == $$)
  2069. {
  2070. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2071. YYABORT(E_OUTOFMEMORY);
  2072. }
  2073. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"<="));
  2074. }
  2075. | _GE
  2076. {
  2077. $$ = PctCreateRelationalNode(DBOP_greater_equal, DEFAULTWEIGHT);
  2078. if (NULL == $$)
  2079. {
  2080. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2081. YYABORT(E_OUTOFMEMORY);
  2082. }
  2083. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L">="));
  2084. }
  2085. ;
  2086. /* 4.4.4 Contains Predicate */
  2087. contains_predicate:
  2088. _CONTAINS '(' opt_contents_column_reference '\'' content_search_condition '\'' ')' opt_greater_than_zero
  2089. {
  2090. AssertReq(!$3); // should have been NULLed out in opt_contents_column_reference
  2091. AssertReq($5);
  2092. $$ = $5;
  2093. DeleteDBQT(m_pIPTProperties->GetContainsColumn());
  2094. m_pIPTProperties->SetContainsColumn(NULL);
  2095. }
  2096. ;
  2097. opt_contents_column_reference:
  2098. /* empty */
  2099. { // opt_contents_column_reference empty rule
  2100. $$ = PctMkColNodeFromStr(L"CONTENTS", m_pIPSession, m_pIPTProperties);
  2101. if (NULL == $$)
  2102. YYABORT(DB_E_ERRORSINCOMMAND);
  2103. m_pIPTProperties->SetCiColumn(L"CONTENTS");
  2104. m_pIPTProperties->SetContainsColumn($$);
  2105. $$ = NULL;
  2106. }
  2107. | column_reference ','
  2108. { // column_reference ','
  2109. m_pIPTProperties->SetContainsColumn($1);
  2110. $$ = NULL;
  2111. }
  2112. ;
  2113. content_search_condition:
  2114. /* empty */
  2115. {
  2116. // This forces a left parentheses before the content search condition
  2117. // The matching right paren will be added below.
  2118. m_pIPTProperties->CiNeedLeftParen();
  2119. $$ = NULL;
  2120. }
  2121. content_search_cond
  2122. {
  2123. AssertReq($2);
  2124. $$ = $2;
  2125. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L")"));
  2126. }
  2127. ;
  2128. content_search_cond:
  2129. content_boolean_term
  2130. | content_search_cond or_operator content_boolean_term
  2131. {
  2132. if (DBOP_not == $3->op)
  2133. {
  2134. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OR_NOT);
  2135. YYABORT(DB_E_ERRORSINCOMMAND);
  2136. }
  2137. $$ = PctCreateBooleanNode(DBOP_or, DEFAULTWEIGHT, $1, $3);
  2138. if (NULL == $$)
  2139. {
  2140. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2141. YYABORT(E_OUTOFMEMORY);
  2142. }
  2143. }
  2144. ;
  2145. content_boolean_term:
  2146. content_boolean_factor
  2147. | content_boolean_term and_operator content_boolean_factor
  2148. {
  2149. $$ = PctCreateBooleanNode(DBOP_and, DEFAULTWEIGHT, $1, $3);
  2150. if (NULL == $$)
  2151. {
  2152. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2153. YYABORT(E_OUTOFMEMORY);
  2154. }
  2155. }
  2156. ;
  2157. content_boolean_factor:
  2158. content_boolean_primary
  2159. | not_operator content_boolean_primary
  2160. {
  2161. $$ = PctCreateNotNode(DEFAULTWEIGHT, $2);
  2162. if (NULL == $$)
  2163. {
  2164. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2165. YYABORT(E_OUTOFMEMORY);
  2166. }
  2167. }
  2168. ;
  2169. content_boolean_primary:
  2170. content_search_term
  2171. | '('
  2172. {
  2173. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"("));
  2174. }
  2175. content_search_cond ')'
  2176. {
  2177. AssertReq($3);
  2178. $$ = $3;
  2179. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L")"));
  2180. }
  2181. ;
  2182. content_search_term:
  2183. simple_term
  2184. | prefix_term
  2185. | proximity_term
  2186. | stemming_term
  2187. | isabout_term
  2188. ;
  2189. or_operator:
  2190. _OR
  2191. {
  2192. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" | "));
  2193. }
  2194. | '|'
  2195. {
  2196. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" | "));
  2197. }
  2198. ;
  2199. and_operator:
  2200. _AND
  2201. {
  2202. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" & "));
  2203. }
  2204. | '&'
  2205. {
  2206. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" & "));
  2207. }
  2208. ;
  2209. not_operator:
  2210. _NOT
  2211. {
  2212. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" ! "));
  2213. }
  2214. | '!'
  2215. {
  2216. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" ! "));
  2217. }
  2218. ;
  2219. simple_term:
  2220. _STRING
  2221. {
  2222. AssertReq($1);
  2223. HRESULT hr = HrQeTreeCopy(&$$, m_pIPTProperties->GetContainsColumn());
  2224. if (FAILED(hr))
  2225. {
  2226. m_pIPTProperties->SetErrorHResult(hr, MONSQL_OUT_OF_MEMORY);
  2227. YYABORT(hr);
  2228. }
  2229. m_pIPTProperties->UseCiColumn(L'@');
  2230. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"\""));
  2231. m_pIPTProperties->AppendCiRestriction(((PROPVARIANT*)$1->value.pvValue)->bstrVal,
  2232. wcslen(((PROPVARIANT*)$1->value.pvValue)->bstrVal));
  2233. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"\""));
  2234. $$ = PctCreateContentNode(((PROPVARIANT*)$1->value.pvValue)->bstrVal, GENERATE_METHOD_EXACT,
  2235. DEFAULTWEIGHT, m_pIPSession->GetLCID(), $$);
  2236. if (NULL == $$)
  2237. {
  2238. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2239. YYABORT(E_OUTOFMEMORY);
  2240. }
  2241. DeleteDBQT($1);
  2242. $1 = NULL;
  2243. }
  2244. ;
  2245. prefix_term:
  2246. _PREFIX_STRING
  2247. {
  2248. AssertReq($1);
  2249. Assert(((PROPVARIANT*)$1->value.pvValue)->bstrVal[wcslen(
  2250. ((PROPVARIANT*)$1->value.pvValue)->bstrVal)-1] == L'*');
  2251. m_pIPTProperties->UseCiColumn(L'@');
  2252. m_pIPTProperties->AppendCiRestriction(((PROPVARIANT*)$1->value.pvValue)->bstrVal,
  2253. wcslen(((PROPVARIANT*)$1->value.pvValue)->bstrVal));
  2254. ((PROPVARIANT*)$1->value.pvValue)->bstrVal[wcslen(
  2255. ((PROPVARIANT*)$1->value.pvValue)->bstrVal)-1] = L'\0';
  2256. HRESULT hr = HrQeTreeCopy(&$$, m_pIPTProperties->GetContainsColumn());
  2257. if (FAILED(hr))
  2258. {
  2259. m_pIPTProperties->SetErrorHResult(hr, MONSQL_OUT_OF_MEMORY);
  2260. YYABORT(hr);
  2261. }
  2262. $$ = PctCreateContentNode(((PROPVARIANT*)$1->value.pvValue)->bstrVal, GENERATE_METHOD_PREFIX,
  2263. DEFAULTWEIGHT, m_pIPSession->GetLCID(), $$);
  2264. if (NULL == $$)
  2265. {
  2266. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2267. YYABORT(E_OUTOFMEMORY);
  2268. }
  2269. DeleteDBQT($1);
  2270. $1 = NULL;
  2271. }
  2272. proximity_term:
  2273. proximity_operand proximity_expression_list
  2274. {
  2275. AssertReq($1);
  2276. AssertReq($2);
  2277. $2 = PctReverse($2);
  2278. $$ = PctCreateNode(DBOP_content_proximity, DBVALUEKIND_CONTENTPROXIMITY, $1, $2, NULL);
  2279. if (NULL == $$)
  2280. {
  2281. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2282. YYABORT(E_OUTOFMEMORY);
  2283. }
  2284. $$->value.pdbcntntproxValue->dwProximityUnit = PROXIMITY_UNIT_WORD;
  2285. $$->value.pdbcntntproxValue->ulProximityDistance = 50;
  2286. $$->value.pdbcntntproxValue->lWeight = DEFAULTWEIGHT;
  2287. }
  2288. ;
  2289. proximity_expression_list:
  2290. proximity_expression_list proximity_expression
  2291. {
  2292. AssertReq($1);
  2293. AssertReq($2);
  2294. $$ = PctLink($2, $1);
  2295. if (NULL == $$)
  2296. {
  2297. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2298. YYABORT(E_OUTOFMEMORY);
  2299. }
  2300. }
  2301. | proximity_expression
  2302. ;
  2303. proximity_expression:
  2304. proximity_specification proximity_operand
  2305. {
  2306. AssertReq($2);
  2307. $$ = $2; // UNDONE: What is proximity_specification good for?
  2308. }
  2309. ;
  2310. proximity_operand:
  2311. simple_term
  2312. | prefix_term
  2313. ;
  2314. proximity_specification:
  2315. _NEAR
  2316. {
  2317. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" ~ "));
  2318. }
  2319. | _NEAR '(' ')'
  2320. {
  2321. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" ~ "));
  2322. }
  2323. /* ************* Not for BETA3 ********************
  2324. | _NEAR '(' distance_type ',' distance_value ')'
  2325. {
  2326. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"~"));
  2327. }
  2328. ************* Not for BETA3 ********************/
  2329. | '~'
  2330. {
  2331. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" ~ "));
  2332. }
  2333. ;
  2334. /* ************* Not for BETA2 ********************
  2335. distance_type:
  2336. identifier
  2337. {
  2338. This should be WORD, SENTENCE, or PARAGRAPH
  2339. if (0==_wcsicmp($1->value.pwszValue, L"Jaccard")) ...
  2340. }
  2341. ;
  2342. distance_value:
  2343. _INTNUM NOTE: Lexer doesn't allower INTNUM in this context
  2344. so you'll have to convert a string to an integer
  2345. ;
  2346. ************* Not for BETA2 ********************/
  2347. stemming_term:
  2348. _FORMSOF '(' stem_type ',' stemmed_simple_term_list ')'
  2349. {
  2350. AssertReq($5);
  2351. // UNDONE: Should make use of $3 somewhere in here
  2352. $$ = $5;
  2353. }
  2354. ;
  2355. stem_type:
  2356. _STRING
  2357. {
  2358. if (0 == _wcsicmp(((PROPVARIANT*)$1->value.pvValue)->bstrVal, L"INFLECTIONAL"))
  2359. {
  2360. DeleteDBQT($1);
  2361. $1 = NULL;
  2362. $$ = NULL;
  2363. }
  2364. /* *************************************NOT IMPLEMENTED BY INDEX SERVER **************************************
  2365. else if (0 == _wcsicmp(((PROPVARIANT*)$1->value.pvValue)->bstrVal, L"DERIVATIONAL"))
  2366. {
  2367. m_pIPTProperties->SetErrorHResult(E_NOTIMPL, MONSQL_PARSE_ERROR);
  2368. m_pIPTProperties->SetErrorToken(L"DERIVATIONAL");
  2369. YYABORT(E_NOTIMPL);
  2370. }
  2371. else if (0 == _wcsicmp(((PROPVARIANT*)$1->value.pvValue)->bstrVal, L"SOUNDEX"))
  2372. {
  2373. m_pIPTProperties->SetErrorHResult(E_NOTIMPL, MONSQL_PARSE_ERROR);
  2374. m_pIPTProperties->SetErrorToken(L"DERIVATIONAL");
  2375. YYABORT(E_NOTIMPL);
  2376. }
  2377. else if (0 == _wcsicmp(((PROPVARIANT*)$1->value.pvValue)->bstrVal, L"THESAURUS"))
  2378. {
  2379. m_pIPTProperties->SetErrorHResult(E_NOTIMPL, MONSQL_PARSE_ERROR);
  2380. m_pIPTProperties->SetErrorToken(L"THESAURUS");
  2381. YYABORT(E_NOTIMPL);
  2382. }
  2383. *************************************NOT IMPLEMENTED BY INDEX SERVER ************************************** */
  2384. else
  2385. {
  2386. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  2387. m_pIPTProperties->SetErrorToken(((PROPVARIANT*)$1->value.pvValue)->bstrVal);
  2388. m_pIPTProperties->SetErrorToken(L"INFLECTIONAL");
  2389. YYABORT(E_NOTIMPL);
  2390. }
  2391. }
  2392. ;
  2393. stemmed_simple_term_list:
  2394. stemmed_simple_term_list ',' simple_term
  2395. {
  2396. AssertReq($1);
  2397. AssertReq($3);
  2398. Assert(DBOP_content == $3->op);
  2399. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"**"));
  2400. $3->value.pdbcntntValue->dwGenerateMethod = GENERATE_METHOD_INFLECT;
  2401. $$ = PctCreateBooleanNode(DBOP_or, DEFAULTWEIGHT, $1, $3);
  2402. if (NULL == $$)
  2403. {
  2404. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2405. YYABORT(E_OUTOFMEMORY);
  2406. }
  2407. }
  2408. | simple_term
  2409. {
  2410. AssertReq($1);
  2411. Assert(DBOP_content == $1->op);
  2412. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"**"));
  2413. $1->value.pdbcntntValue->dwGenerateMethod = GENERATE_METHOD_INFLECT;
  2414. $$ = $1;
  2415. }
  2416. ;
  2417. isabout_term:
  2418. _ISABOUT '(' vector_component_list ')'
  2419. {
  2420. AssertReq($3);
  2421. $3 = PctReverse($3);
  2422. $$ = PctCreateNode(DBOP_content_vector_or, DBVALUEKIND_CONTENTVECTOR, $3, NULL);
  2423. if (NULL == $$)
  2424. {
  2425. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2426. YYABORT(E_OUTOFMEMORY);
  2427. }
  2428. $$->value.pdbcntntvcValue->dwRankingMethod = m_pIPSession->GetRankingMethod();
  2429. $$->value.pdbcntntvcValue->lWeight = DEFAULTWEIGHT;
  2430. }
  2431. /* *************************************NOT IMPLEMENTED BY INDEX SERVER **************************************
  2432. | _COERCE '(' vector_term ')'
  2433. {
  2434. m_pIPTProperties->SetErrorHResult(E_NOTIMPL, MONSQL_PARSE_ERROR);
  2435. m_pIPTProperties->SetErrorToken(L"COERCE");
  2436. YYABORT(E_NOTIMPL);
  2437. }
  2438. *************************************NOT IMPLEMENTED BY INDEX SERVER ************************************** */
  2439. ;
  2440. vector_component_list:
  2441. vector_component_list ',' vector_component
  2442. {
  2443. AssertReq($1);
  2444. AssertReq($3);
  2445. Assert((DBOP_content == $3->op) || (DBOP_or == $3->op) || (DBOP_content_proximity == $3->op));
  2446. $$ = PctLink($3, $1);
  2447. if (NULL == $$)
  2448. {
  2449. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2450. YYABORT(E_OUTOFMEMORY);
  2451. }
  2452. }
  2453. | vector_component
  2454. {
  2455. AssertReq($1);
  2456. Assert((DBOP_content == $1->op) || (DBOP_or == $1->op) || (DBOP_content_proximity == $1->op));
  2457. $$ = $1;
  2458. }
  2459. ;
  2460. vector_component:
  2461. vector_term _WEIGHT '(' weight_value ')'
  2462. {
  2463. AssertReq($1);
  2464. AssertReq($4);
  2465. if (($4->value.pvarValue->dblVal < 0.0) ||
  2466. ($4->value.pvarValue->dblVal > 1.0))
  2467. {
  2468. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_WEIGHT_OUT_OF_RANGE);
  2469. WCHAR wchErr[30];
  2470. swprintf(wchErr, L"%f", $4->value.pvarValue->dblVal);
  2471. m_pIPTProperties->SetErrorToken(wchErr);
  2472. YYABORT(DB_E_ERRORSINCOMMAND);
  2473. }
  2474. $$ = $1;
  2475. SetLWeight($$, (LONG) ($4->value.pvarValue->dblVal * DEFAULTWEIGHT));
  2476. WCHAR wchWeight[10];
  2477. if (swprintf(wchWeight, L"%d", (LONG) ($4->value.pvarValue->dblVal * DEFAULTWEIGHT)))
  2478. {
  2479. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"["));
  2480. m_pIPTProperties->AppendCiRestriction(wchWeight, wcslen(wchWeight));
  2481. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"] "));
  2482. }
  2483. DeleteDBQT($4);
  2484. $4 = NULL;
  2485. }
  2486. | vector_term
  2487. {
  2488. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" "));
  2489. $$ = $1;
  2490. }
  2491. ;
  2492. vector_term:
  2493. simple_term
  2494. | prefix_term
  2495. | proximity_term
  2496. | stemming_term
  2497. ;
  2498. weight_value:
  2499. _STRING
  2500. {
  2501. HRESULT hr = CoerceScalar(VT_R8, &$1);
  2502. if (S_OK != hr)
  2503. YYABORT(hr);
  2504. $$ = $1;
  2505. }
  2506. ;
  2507. opt_greater_than_zero:
  2508. /* empty */
  2509. {
  2510. $$ = NULL;
  2511. }
  2512. | '>' _INTNUM
  2513. {
  2514. HRESULT hr = CoerceScalar(VT_I4, &$2);
  2515. if (S_OK != hr)
  2516. YYABORT(hr);
  2517. if (0 != $2->value.pvarValue->lVal)
  2518. {
  2519. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  2520. WCHAR wchErr[30];
  2521. swprintf(wchErr, L"%d", $2->value.pvarValue->lVal);
  2522. m_pIPTProperties->SetErrorToken(wchErr);
  2523. m_pIPTProperties->SetErrorToken(L"0");
  2524. YYABORT(DB_E_ERRORSINCOMMAND);
  2525. }
  2526. DeleteDBQT($2);
  2527. $2 = NULL;
  2528. $$ = NULL;
  2529. }
  2530. ;
  2531. /* 4.4.5 Free-Text Predicate */
  2532. freetext_predicate:
  2533. _FREETEXT '(' opt_contents_column_reference _STRING ')' opt_greater_than_zero
  2534. {
  2535. AssertReq(!$3);
  2536. AssertReq($4);
  2537. HRESULT hr = HrQeTreeCopy(&$$, m_pIPTProperties->GetContainsColumn());
  2538. if (FAILED(hr))
  2539. {
  2540. m_pIPTProperties->SetErrorHResult(hr, MONSQL_OUT_OF_MEMORY);
  2541. YYABORT(hr);
  2542. }
  2543. m_pIPTProperties->UseCiColumn(L'$');
  2544. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"\""));
  2545. m_pIPTProperties->AppendCiRestriction(((PROPVARIANT*)$4->value.pvValue)->bstrVal,
  2546. wcslen(((PROPVARIANT*)$4->value.pvValue)->bstrVal));
  2547. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"\""));
  2548. $$ = PctCreateNode(DBOP_content_freetext, DBVALUEKIND_CONTENT, $$, NULL);
  2549. if (NULL == $$)
  2550. {
  2551. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2552. YYABORT(E_OUTOFMEMORY);
  2553. }
  2554. $$->value.pdbcntntValue->pwszPhrase = CoTaskStrDup(((PROPVARIANT*)$4->value.pvValue)->bstrVal);
  2555. $$->value.pdbcntntValue->dwGenerateMethod = GENERATE_METHOD_EXACT;
  2556. $$->value.pdbcntntValue->lWeight = DEFAULTWEIGHT;
  2557. $$->value.pdbcntntValue->lcid = m_pIPSession->GetLCID();
  2558. DeleteDBQT(m_pIPTProperties->GetContainsColumn());
  2559. m_pIPTProperties->SetContainsColumn(NULL);
  2560. DeleteDBQT($4);
  2561. $4 = NULL;
  2562. }
  2563. ;
  2564. /* 4.4.6 Like Predicate */
  2565. like_predicate:
  2566. column_reference _LIKE wildcard_search_pattern
  2567. {
  2568. AssertReq($1);
  2569. AssertReq($3);
  2570. m_pIPTProperties->UseCiColumn(L'#');
  2571. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"\""));
  2572. m_pIPTProperties->AppendCiRestriction(((PROPVARIANT*)$3->value.pvValue)->pwszVal,
  2573. wcslen(((PROPVARIANT*)$3->value.pvValue)->pwszVal));
  2574. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"\""));
  2575. $$ = PctCreateNode(DBOP_like, DBVALUEKIND_LIKE, $1, $3, NULL);
  2576. if (NULL == $$)
  2577. {
  2578. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2579. YYABORT(E_OUTOFMEMORY);
  2580. }
  2581. $$->value.pdblikeValue->guidDialect = DBGUID_LIKE_OFS;
  2582. $$->value.pdblikeValue->lWeight = DEFAULTWEIGHT;
  2583. }
  2584. | column_reference _NOT_LIKE wildcard_search_pattern
  2585. {
  2586. AssertReq($1);
  2587. AssertReq($3);
  2588. m_pIPTProperties->UseCiColumn(L'#');
  2589. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"\""));
  2590. m_pIPTProperties->AppendCiRestriction(((PROPVARIANT*)$3->value.pvValue)->pwszVal,
  2591. wcslen(((PROPVARIANT*)$3->value.pvValue)->pwszVal));
  2592. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"\""));
  2593. $2 = PctCreateNode(DBOP_like, DBVALUEKIND_LIKE, $1, $3, NULL);
  2594. if (NULL == $$)
  2595. {
  2596. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2597. YYABORT(E_OUTOFMEMORY);
  2598. }
  2599. $2->value.pdblikeValue->guidDialect = DBGUID_LIKE_OFS;
  2600. $2->value.pdblikeValue->lWeight = DEFAULTWEIGHT;
  2601. $$ = PctCreateNotNode(DEFAULTWEIGHT, $2);
  2602. }
  2603. ;
  2604. wildcard_search_pattern:
  2605. _STRING
  2606. {
  2607. UINT cLen = wcslen(((PROPVARIANT*)$1->value.pvValue)->bstrVal);
  2608. BSTR bstrCopy = SysAllocStringLen(NULL, 4 * cLen);
  2609. if ( 0 == bstrCopy )
  2610. {
  2611. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  2612. YYABORT( E_OUTOFMEMORY );
  2613. }
  2614. UINT j = 0;
  2615. for (UINT i = 0; i <= cLen; i++)
  2616. {
  2617. switch ( ((PROPVARIANT*)$1->value.pvValue)->bstrVal[i] )
  2618. {
  2619. case L'%':
  2620. bstrCopy[j++] = L'*';
  2621. break;
  2622. case L'_':
  2623. bstrCopy[j++] = L'?';
  2624. break;
  2625. case L'|':
  2626. bstrCopy[j++] = L'|';
  2627. bstrCopy[j++] = L'|';
  2628. break;
  2629. case L'*':
  2630. bstrCopy[j++] = L'|';
  2631. bstrCopy[j++] = L'[';
  2632. bstrCopy[j++] = L'*';
  2633. bstrCopy[j++] = L']';
  2634. break;
  2635. case L'?':
  2636. bstrCopy[j++] = L'|';
  2637. bstrCopy[j++] = L'[';
  2638. bstrCopy[j++] = L'?';
  2639. bstrCopy[j++] = L']';
  2640. break;
  2641. case L'[':
  2642. // UNDONE: Make sure we're not going out of range with these tests
  2643. if ((L'%' == ((PROPVARIANT*)$1->value.pvValue)->bstrVal[i+1]) &&
  2644. (L']' == ((PROPVARIANT*)$1->value.pvValue)->bstrVal[i+2]))
  2645. {
  2646. bstrCopy[j++] = L'%';
  2647. i = i + 2;
  2648. }
  2649. else if ((L'_' == ((PROPVARIANT*)$1->value.pvValue)->bstrVal[i+1]) &&
  2650. (L']' == ((PROPVARIANT*)$1->value.pvValue)->bstrVal[i+2]))
  2651. {
  2652. bstrCopy[j++] = L'_';
  2653. i = i + 2;
  2654. }
  2655. else if ((L'[' == ((PROPVARIANT*)$1->value.pvValue)->bstrVal[i+1]) &&
  2656. (L']' == ((PROPVARIANT*)$1->value.pvValue)->bstrVal[i+2]))
  2657. {
  2658. bstrCopy[j++] = L'[';
  2659. i = i + 2;
  2660. }
  2661. else if ((L'^' == ((PROPVARIANT*)$1->value.pvValue)->bstrVal[i+1]) &&
  2662. (L']' == ((PROPVARIANT*)$1->value.pvValue)->bstrVal[i+2]) &&
  2663. (wcschr((WCHAR*)&(((PROPVARIANT*)$1->value.pvValue)->bstrVal[i+3]), L']')))
  2664. {
  2665. bstrCopy[j++] = L'|';
  2666. bstrCopy[j++] = L'[';
  2667. bstrCopy[j++] = L'^';
  2668. bstrCopy[j++] = L']';
  2669. i = i + 2;
  2670. }
  2671. else
  2672. {
  2673. bstrCopy[j++] = L'|';
  2674. bstrCopy[j++] = ((PROPVARIANT*)$1->value.pvValue)->bstrVal[i++];
  2675. while ((((PROPVARIANT*)$1->value.pvValue)->bstrVal[i] != L']') && (i < cLen))
  2676. bstrCopy[j++] = ((PROPVARIANT*)$1->value.pvValue)->bstrVal[i++];
  2677. if (i < cLen)
  2678. bstrCopy[j++] = ((PROPVARIANT*)$1->value.pvValue)->bstrVal[i];
  2679. }
  2680. break;
  2681. default:
  2682. bstrCopy[j++] = ((PROPVARIANT*)$1->value.pvValue)->bstrVal[i];
  2683. break;
  2684. }
  2685. }
  2686. SysFreeString(((PROPVARIANT*)$1->value.pvValue)->bstrVal);
  2687. ((PROPVARIANT*)$1->value.pvValue)->pwszVal = CoTaskStrDup(bstrCopy);
  2688. ((PROPVARIANT*)$1->value.pvValue)->vt = VT_LPWSTR;
  2689. SysFreeString(bstrCopy);
  2690. $$ = $1;
  2691. }
  2692. ;
  2693. /* 4.4.6 Matches Predicate */
  2694. matches_predicate:
  2695. _MATCHES '(' column_reference ',' matches_string ')' opt_greater_than_zero
  2696. {
  2697. AssertReq($3);
  2698. AssertReq($5);
  2699. m_pIPTProperties->UseCiColumn(L'#');
  2700. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"\""));
  2701. m_pIPTProperties->AppendCiRestriction(((PROPVARIANT*)$5->value.pvValue)->pwszVal,
  2702. wcslen(((PROPVARIANT*)$5->value.pvValue)->pwszVal));
  2703. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"\""));
  2704. $$ = PctCreateNode(DBOP_like, DBVALUEKIND_LIKE, $3, $5, NULL);
  2705. if (NULL == $$)
  2706. {
  2707. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2708. YYABORT(E_OUTOFMEMORY);
  2709. }
  2710. $$->value.pdblikeValue->guidDialect = DBGUID_LIKE_OFS;
  2711. $$->value.pdblikeValue->lWeight = DEFAULTWEIGHT;
  2712. }
  2713. ;
  2714. matches_string:
  2715. _STRING
  2716. {
  2717. AssertReq($1);
  2718. HRESULT hr = CoerceScalar(VT_LPWSTR, &$1);
  2719. if (S_OK != hr)
  2720. YYABORT(hr);
  2721. LPWSTR pwszMatchString = ((PROPVARIANT*)$1->value.pvValue)->pwszVal;
  2722. while (*pwszMatchString)
  2723. {
  2724. // perform some soundness checking on string since Index Server won't be happy
  2725. // with an ill formed string
  2726. if (L'|' == *pwszMatchString++)
  2727. {
  2728. hr = DB_E_ERRORSINCOMMAND;
  2729. switch ( *pwszMatchString++ )
  2730. {
  2731. case L'(':
  2732. while (*pwszMatchString)
  2733. if (L'|' == *pwszMatchString++)
  2734. if (*pwszMatchString)
  2735. if (L')' == *pwszMatchString++)
  2736. {
  2737. hr = S_OK;
  2738. break;
  2739. }
  2740. break;
  2741. case L'{':
  2742. while (*pwszMatchString)
  2743. if (L'|' == *pwszMatchString++)
  2744. if (*pwszMatchString)
  2745. if (L'}' == *pwszMatchString++)
  2746. {
  2747. hr = S_OK;
  2748. break;
  2749. }
  2750. break;
  2751. default:
  2752. hr = S_OK;
  2753. }
  2754. }
  2755. }
  2756. if (S_OK != hr)
  2757. {
  2758. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_MATCH_STRING);
  2759. YYABORT(hr);
  2760. }
  2761. $$ = $1;
  2762. }
  2763. ;
  2764. /* 4.4.7 Qantified Comparison Predicate */
  2765. vector_comparison_predicate:
  2766. column_reference_or_cast vector_comp_op vector_literal
  2767. {
  2768. AssertReq($1);
  2769. AssertReq($2);
  2770. DBCOMMANDTREE * pct = 0;
  2771. if ( m_pIPTProperties->GetDBType() & DBTYPE_VECTOR )
  2772. {
  2773. pct = PctAllocNode(DBVALUEKIND_VARIANT, DBOP_scalar_constant);
  2774. if (NULL == pct)
  2775. {
  2776. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2777. YYABORT( E_OUTOFMEMORY );
  2778. }
  2779. DBCOMMANDTREE* pctList=$3;
  2780. UINT i = 0;
  2781. pct->value.pvarValue->vt = m_pIPTProperties->GetDBType();
  2782. ((PROPVARIANT*)pct->value.pvarValue)->caub.cElems = GetNumberOfSiblings($3);
  2783. if (0 == ((PROPVARIANT*)pct->value.pvarValue)->caub.cElems)
  2784. {
  2785. ((PROPVARIANT*)pct->value.pvarValue)->caub.pElems = (UCHAR*) NULL;
  2786. }
  2787. else
  2788. {
  2789. switch ( m_pIPTProperties->GetDBType() )
  2790. {
  2791. case (VT_UI1|VT_VECTOR):
  2792. ((PROPVARIANT*)pct->value.pvarValue)->caub.pElems =
  2793. (UCHAR*) CoTaskMemAlloc(sizeof(UCHAR)*((PROPVARIANT*)pct->value.pvarValue)->caub.cElems);
  2794. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->caub.pElems)
  2795. {
  2796. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2797. YYABORT( E_OUTOFMEMORY );
  2798. }
  2799. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->caub.cElems; i++)
  2800. {
  2801. ((PROPVARIANT*)pct->value.pvarValue)->caub.pElems[i] = pctList->value.pvarValue->bVal;
  2802. pctList = pctList->pctNextSibling;
  2803. }
  2804. break;
  2805. case (VT_I1|VT_VECTOR):
  2806. ((PROPVARIANT*)pct->value.pvarValue)->cac.pElems =
  2807. (CHAR*) CoTaskMemAlloc(sizeof(CHAR)*((PROPVARIANT*)pct->value.pvarValue)->cac.cElems);
  2808. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->cac.pElems)
  2809. {
  2810. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2811. YYABORT( E_OUTOFMEMORY );
  2812. }
  2813. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->cac.cElems; i++)
  2814. {
  2815. ((PROPVARIANT*)pct->value.pvarValue)->cac.pElems[i] = pctList->value.pvarValue->cVal;
  2816. pctList = pctList->pctNextSibling;
  2817. }
  2818. break;
  2819. case (VT_UI2|VT_VECTOR):
  2820. ((PROPVARIANT*)pct->value.pvarValue)->caui.pElems =
  2821. (USHORT*) CoTaskMemAlloc(sizeof(USHORT)*((PROPVARIANT*)pct->value.pvarValue)->caui.cElems);
  2822. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->caui.pElems)
  2823. {
  2824. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2825. YYABORT( E_OUTOFMEMORY );
  2826. }
  2827. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->caui.cElems; i++)
  2828. {
  2829. ((PROPVARIANT*)pct->value.pvarValue)->caui.pElems[i] = pctList->value.pvarValue->uiVal;
  2830. pctList = pctList->pctNextSibling;
  2831. }
  2832. break;
  2833. case (VT_I2|VT_VECTOR):
  2834. ((PROPVARIANT*)pct->value.pvarValue)->cai.pElems =
  2835. (SHORT*) CoTaskMemAlloc(sizeof(SHORT)*((PROPVARIANT*)pct->value.pvarValue)->cai.cElems);
  2836. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->cai.pElems)
  2837. {
  2838. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2839. YYABORT( E_OUTOFMEMORY );
  2840. }
  2841. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->cai.cElems; i++)
  2842. {
  2843. ((PROPVARIANT*)pct->value.pvarValue)->cai.pElems[i] = pctList->value.pvarValue->iVal;
  2844. pctList = pctList->pctNextSibling;
  2845. }
  2846. break;
  2847. case (VT_UI4|VT_VECTOR):
  2848. ((PROPVARIANT*)pct->value.pvarValue)->caul.pElems =
  2849. (ULONG*) CoTaskMemAlloc(sizeof(ULONG)*((PROPVARIANT*)pct->value.pvarValue)->caul.cElems);
  2850. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->caul.pElems)
  2851. {
  2852. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2853. YYABORT( E_OUTOFMEMORY );
  2854. }
  2855. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->caul.cElems; i++)
  2856. {
  2857. ((PROPVARIANT*)pct->value.pvarValue)->caul.pElems[i] = pctList->value.pvarValue->ulVal;
  2858. pctList = pctList->pctNextSibling;
  2859. }
  2860. break;
  2861. case (VT_I4|VT_VECTOR):
  2862. ((PROPVARIANT*)pct->value.pvarValue)->cal.pElems =
  2863. (LONG*) CoTaskMemAlloc(sizeof(LONG)*((PROPVARIANT*)pct->value.pvarValue)->cal.cElems);
  2864. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->cal.pElems)
  2865. {
  2866. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2867. YYABORT( E_OUTOFMEMORY );
  2868. }
  2869. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->cal.cElems; i++)
  2870. {
  2871. ((PROPVARIANT*)pct->value.pvarValue)->cal.pElems[i] = pctList->value.pvarValue->lVal;
  2872. pctList = pctList->pctNextSibling;
  2873. }
  2874. break;
  2875. case (VT_UI8|VT_VECTOR):
  2876. ((PROPVARIANT*)pct->value.pvarValue)->cauh.pElems =
  2877. (ULARGE_INTEGER*) CoTaskMemAlloc(sizeof(ULARGE_INTEGER)*((PROPVARIANT*)pct->value.pvarValue)->cauh.cElems);
  2878. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->cauh.pElems)
  2879. {
  2880. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2881. YYABORT( E_OUTOFMEMORY );
  2882. }
  2883. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->cauh.cElems; i++)
  2884. {
  2885. ((PROPVARIANT*)pct->value.pvarValue)->cauh.pElems[i] = ((PROPVARIANT*)pctList->value.pvarValue)->uhVal;
  2886. pctList = pctList->pctNextSibling;
  2887. }
  2888. break;
  2889. case (VT_I8|VT_VECTOR):
  2890. ((PROPVARIANT*)pct->value.pvarValue)->cah.pElems =
  2891. (LARGE_INTEGER*) CoTaskMemAlloc(sizeof(LARGE_INTEGER)*((PROPVARIANT*)pct->value.pvarValue)->cah.cElems);
  2892. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->cah.pElems)
  2893. {
  2894. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2895. YYABORT( E_OUTOFMEMORY );
  2896. }
  2897. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->cah.cElems; i++)
  2898. {
  2899. ((PROPVARIANT*)pct->value.pvarValue)->cah.pElems[i] = ((PROPVARIANT*)pctList->value.pvarValue)->hVal;
  2900. pctList = pctList->pctNextSibling;
  2901. }
  2902. break;
  2903. case (VT_R4|VT_VECTOR):
  2904. ((PROPVARIANT*)pct->value.pvarValue)->caflt.pElems =
  2905. (float*) CoTaskMemAlloc(sizeof(float)*((PROPVARIANT*)pct->value.pvarValue)->caflt.cElems);
  2906. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->caflt.pElems)
  2907. {
  2908. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2909. YYABORT( E_OUTOFMEMORY );
  2910. }
  2911. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->caflt.cElems; i++)
  2912. {
  2913. ((PROPVARIANT*)pct->value.pvarValue)->caflt.pElems[i] = pctList->value.pvarValue->fltVal;
  2914. pctList = pctList->pctNextSibling;
  2915. }
  2916. break;
  2917. case (VT_R8|VT_VECTOR):
  2918. ((PROPVARIANT*)pct->value.pvarValue)->cadbl.pElems =
  2919. (double*) CoTaskMemAlloc(sizeof(double)*((PROPVARIANT*)pct->value.pvarValue)->cadbl.cElems);
  2920. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->cadbl.pElems)
  2921. {
  2922. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2923. YYABORT( E_OUTOFMEMORY );
  2924. }
  2925. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->cadbl.cElems; i++)
  2926. {
  2927. ((PROPVARIANT*)pct->value.pvarValue)->cadbl.pElems[i] = pctList->value.pvarValue->dblVal;
  2928. pctList = pctList->pctNextSibling;
  2929. }
  2930. break;
  2931. case (VT_BOOL|VT_VECTOR):
  2932. ((PROPVARIANT*)pct->value.pvarValue)->cabool.pElems =
  2933. (VARIANT_BOOL*) CoTaskMemAlloc(sizeof(VARIANT_BOOL)*((PROPVARIANT*)pct->value.pvarValue)->cabool.cElems);
  2934. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->cabool.pElems)
  2935. {
  2936. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2937. YYABORT( E_OUTOFMEMORY );
  2938. }
  2939. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->cabool.cElems; i++)
  2940. {
  2941. ((PROPVARIANT*)pct->value.pvarValue)->cabool.pElems[i] = pctList->value.pvarValue->boolVal;
  2942. pctList = pctList->pctNextSibling;
  2943. }
  2944. break;
  2945. case (VT_CY|VT_VECTOR):
  2946. ((PROPVARIANT*)pct->value.pvarValue)->cacy.pElems =
  2947. (CY*) CoTaskMemAlloc(sizeof(CY)*((PROPVARIANT*)pct->value.pvarValue)->cacy.cElems);
  2948. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->cacy.pElems)
  2949. {
  2950. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2951. YYABORT( E_OUTOFMEMORY );
  2952. }
  2953. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->cacy.cElems; i++)
  2954. {
  2955. ((PROPVARIANT*)pct->value.pvarValue)->cacy.pElems[i] =
  2956. ((PROPVARIANT*)pctList->value.pvarValue)->cyVal;
  2957. pctList = pctList->pctNextSibling;
  2958. }
  2959. break;
  2960. case (VT_DATE|VT_VECTOR):
  2961. ((PROPVARIANT*)pct->value.pvarValue)->cadbl.pElems =
  2962. (double*) CoTaskMemAlloc(sizeof(double)*((PROPVARIANT*)pct->value.pvarValue)->cadbl.cElems);
  2963. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->cadbl.pElems)
  2964. {
  2965. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2966. YYABORT( E_OUTOFMEMORY );
  2967. }
  2968. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->cadbl.cElems; i++)
  2969. {
  2970. ((PROPVARIANT*)pct->value.pvarValue)->cadbl.pElems[i] =
  2971. ((PROPVARIANT*)pctList->value.pvarValue)->date;
  2972. pctList = pctList->pctNextSibling;
  2973. }
  2974. break;
  2975. case (VT_FILETIME|VT_VECTOR):
  2976. ((PROPVARIANT*)pct->value.pvarValue)->cafiletime.pElems =
  2977. (FILETIME*) CoTaskMemAlloc(sizeof(FILETIME)*((PROPVARIANT*)pct->value.pvarValue)->cafiletime.cElems);
  2978. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->cafiletime.pElems)
  2979. {
  2980. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2981. YYABORT( E_OUTOFMEMORY );
  2982. }
  2983. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->cafiletime.cElems; i++)
  2984. {
  2985. ((PROPVARIANT*)pct->value.pvarValue)->cafiletime.pElems[i] =
  2986. ((PROPVARIANT*)pctList->value.pvarValue)->filetime;
  2987. pctList = pctList->pctNextSibling;
  2988. }
  2989. break;
  2990. case (VT_BSTR|VT_VECTOR):
  2991. ((PROPVARIANT*)pct->value.pvarValue)->cabstr.pElems =
  2992. (BSTR*) CoTaskMemAlloc(sizeof(BSTR)*((PROPVARIANT*)pct->value.pvarValue)->cabstr.cElems);
  2993. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->cabstr.pElems)
  2994. {
  2995. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  2996. YYABORT( E_OUTOFMEMORY );
  2997. }
  2998. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->cabstr.cElems; i++)
  2999. {
  3000. ((PROPVARIANT*)pct->value.pvarValue)->cabstr.pElems[i] =
  3001. SysAllocString(pctList->value.pvarValue->bstrVal);
  3002. if ( 0 == ((PROPVARIANT*)pct->value.pvarValue)->cabstr.pElems[i] )
  3003. {
  3004. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  3005. YYABORT( E_OUTOFMEMORY );
  3006. }
  3007. pctList = pctList->pctNextSibling;
  3008. }
  3009. break;
  3010. case (DBTYPE_STR|VT_VECTOR):
  3011. pct->value.pvarValue->vt = VT_LPSTR | VT_VECTOR;
  3012. ((PROPVARIANT*)pct->value.pvarValue)->calpstr.pElems =
  3013. (LPSTR*) CoTaskMemAlloc(sizeof(LPSTR)*((PROPVARIANT*)pct->value.pvarValue)->calpstr.cElems);
  3014. if (NULL == ((PROPVARIANT*)pct->value.pvarValue)->calpstr.pElems)
  3015. {
  3016. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3017. YYABORT( E_OUTOFMEMORY );
  3018. }
  3019. for (i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->calpstr.cElems; i++)
  3020. {
  3021. ((PROPVARIANT*)pct->value.pvarValue)->calpstr.pElems[i] =
  3022. (LPSTR)CoTaskMemAlloc((lstrlenA(((PROPVARIANT*)pctList->value.pvarValue)->pszVal)+2)*sizeof(CHAR));
  3023. if ( 0 == ((PROPVARIANT*)pct->value.pvarValue)->calpstr.pElems[i] )
  3024. {
  3025. // free allocations made so far
  3026. for ( int j = i-1; j >= 0; j++ )
  3027. CoTaskMemFree( ((PROPVARIANT*)pct->value.pvarValue)->calpstr.pElems[i] );
  3028. CoTaskMemFree( ((PROPVARIANT*)pct->value.pvarValue)->calpstr.pElems );
  3029. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  3030. YYABORT( E_OUTOFMEMORY );
  3031. }
  3032. strcpy(((PROPVARIANT*)pct->value.pvarValue)->calpstr.pElems[i],
  3033. ((PROPVARIANT*)pctList->value.pvarValue)->pszVal);
  3034. pctList = pctList->pctNextSibling;
  3035. }
  3036. break;
  3037. case (DBTYPE_WSTR|VT_VECTOR):
  3038. pct->value.pvarValue->vt = VT_LPWSTR | VT_VECTOR;
  3039. ((PROPVARIANT*)pct->value.pvarValue)->calpwstr.pElems =
  3040. (LPWSTR*) CoTaskMemAlloc(sizeof(LPWSTR)*((PROPVARIANT*)pct->value.pvarValue)->calpwstr.cElems);
  3041. if ( 0 == ((PROPVARIANT*)pct->value.pvarValue)->calpwstr.pElems )
  3042. {
  3043. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3044. YYABORT( E_OUTOFMEMORY );
  3045. }
  3046. for ( i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->calpwstr.cElems; i++ )
  3047. {
  3048. ((PROPVARIANT*)pct->value.pvarValue)->calpwstr.pElems[i] =
  3049. CoTaskStrDup(((PROPVARIANT*)pctList->value.pvarValue)->pwszVal);
  3050. if ( 0 == ((PROPVARIANT*)pct->value.pvarValue)->calpwstr.pElems[i] )
  3051. {
  3052. // free allocations made so far
  3053. for ( int j = i-1; j >= 0; j++ )
  3054. CoTaskMemFree( ((PROPVARIANT*)pct->value.pvarValue)->calpwstr.pElems[i] );
  3055. CoTaskMemFree( ((PROPVARIANT*)pct->value.pvarValue)->calpwstr.pElems );
  3056. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  3057. YYABORT( E_OUTOFMEMORY );
  3058. }
  3059. pctList = pctList->pctNextSibling;
  3060. }
  3061. break;
  3062. case (VT_CLSID|VT_VECTOR):
  3063. pct->value.pvarValue->vt = VT_CLSID | VT_VECTOR;
  3064. ((PROPVARIANT*)pct->value.pvarValue)->cauuid.pElems =
  3065. (GUID*) CoTaskMemAlloc(sizeof(GUID)*((PROPVARIANT*)pct->value.pvarValue)->cauuid.cElems);
  3066. if ( NULL == ((PROPVARIANT*)pct->value.pvarValue)->cauuid.pElems )
  3067. {
  3068. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  3069. YYABORT( E_OUTOFMEMORY );
  3070. }
  3071. for ( i = 0; i<((PROPVARIANT*)pct->value.pvarValue)->cauuid.cElems; i++ )
  3072. {
  3073. ((PROPVARIANT*)pct->value.pvarValue)->cauuid.pElems[i] =
  3074. *((PROPVARIANT*)pctList->value.pvarValue)->puuid;
  3075. pctList = pctList->pctNextSibling;
  3076. }
  3077. break;
  3078. default:
  3079. assert(!"PctAllocNode: illegal wKind");
  3080. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  3081. m_pIPTProperties->SetErrorToken(L"ARRAY");
  3082. DeleteDBQT( pct );
  3083. YYABORT(DB_E_ERRORSINCOMMAND);
  3084. }
  3085. }
  3086. }
  3087. else
  3088. {
  3089. switch ( m_pIPTProperties->GetDBType() )
  3090. {
  3091. case VT_UI1:
  3092. case VT_UI2:
  3093. case VT_UI4:
  3094. case VT_UI8:
  3095. // Allows:
  3096. // DBOP_allbits
  3097. // DBOP_anybits
  3098. // when the LHS is a non vector.
  3099. //
  3100. // There isn't a way to say the following through SQL currently:
  3101. // DBOP_anybits_all
  3102. // DBOP_anybits_any
  3103. // DBOP_allbits_all
  3104. // DBOP_allbits_any
  3105. pct = $3;
  3106. $3 = 0;
  3107. break;
  3108. default:
  3109. assert(!"PctAllocNode: illegal wKind");
  3110. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  3111. m_pIPTProperties->SetErrorToken(L"ARRAY");
  3112. YYABORT(DB_E_ERRORSINCOMMAND);
  3113. }
  3114. }
  3115. if ($3)
  3116. {
  3117. DeleteDBQT($3);
  3118. $3 = NULL;
  3119. }
  3120. $1->pctNextSibling = pct;
  3121. $2->pctFirstChild = $1;
  3122. $$ = $2;
  3123. }
  3124. ;
  3125. all:
  3126. _ALL
  3127. ;
  3128. some:
  3129. _SOME
  3130. | _ANY
  3131. ;
  3132. vector_comp_op:
  3133. '='
  3134. {
  3135. if ( m_pIPTProperties->GetDBType() & DBTYPE_VECTOR )
  3136. $$ = PctCreateRelationalNode( DBOP_equal, DEFAULTWEIGHT );
  3137. else
  3138. $$ = PctCreateRelationalNode( DBOP_equal, DEFAULTWEIGHT );
  3139. if ( NULL == $$ )
  3140. {
  3141. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  3142. YYABORT( E_OUTOFMEMORY );
  3143. }
  3144. m_pIPTProperties->AppendCiRestriction( VAL_AND_CCH_MINUS_NULL(L" = ") );
  3145. }
  3146. | '=' all
  3147. {
  3148. if ( m_pIPTProperties->GetDBType() & DBTYPE_VECTOR )
  3149. $$ = PctCreateRelationalNode( DBOP_equal_all, DEFAULTWEIGHT );
  3150. else
  3151. $$ = PctCreateRelationalNode( DBOP_allbits, DEFAULTWEIGHT );
  3152. if ( NULL == $$ )
  3153. {
  3154. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  3155. YYABORT( E_OUTOFMEMORY );
  3156. }
  3157. if ( m_pIPTProperties->GetDBType() & DBTYPE_VECTOR )
  3158. m_pIPTProperties->AppendCiRestriction( VAL_AND_CCH_MINUS_NULL(L" = ^a ") );
  3159. else
  3160. m_pIPTProperties->AppendCiRestriction( VAL_AND_CCH_MINUS_NULL(L" ^a ") );
  3161. }
  3162. | '=' some
  3163. {
  3164. if ( m_pIPTProperties->GetDBType() & DBTYPE_VECTOR )
  3165. $$ = PctCreateRelationalNode( DBOP_equal_any, DEFAULTWEIGHT );
  3166. else
  3167. $$ = PctCreateRelationalNode( DBOP_anybits, DEFAULTWEIGHT );
  3168. if ( NULL == $$ )
  3169. {
  3170. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  3171. YYABORT( E_OUTOFMEMORY );
  3172. }
  3173. if ( m_pIPTProperties->GetDBType() & DBTYPE_VECTOR )
  3174. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" = ^s "));
  3175. else
  3176. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" ^s "));
  3177. }
  3178. | _NE
  3179. {
  3180. if ( m_pIPTProperties->GetDBType() & DBTYPE_VECTOR )
  3181. $$ = PctCreateRelationalNode( DBOP_not_equal, DEFAULTWEIGHT );
  3182. if ( NULL == $$ )
  3183. {
  3184. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  3185. YYABORT( E_OUTOFMEMORY );
  3186. }
  3187. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" != ") );
  3188. }
  3189. | _NE all
  3190. {
  3191. $$ = PctCreateRelationalNode(DBOP_not_equal_all, DEFAULTWEIGHT);
  3192. if (NULL == $$)
  3193. {
  3194. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3195. YYABORT( E_OUTOFMEMORY );
  3196. }
  3197. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" != ^a "));
  3198. }
  3199. | _NE some
  3200. {
  3201. $$ = PctCreateRelationalNode(DBOP_not_equal_any, DEFAULTWEIGHT);
  3202. if (NULL == $$)
  3203. {
  3204. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3205. YYABORT( E_OUTOFMEMORY );
  3206. }
  3207. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" != ^s "));
  3208. }
  3209. | '<'
  3210. {
  3211. $$ = PctCreateRelationalNode(DBOP_less, DEFAULTWEIGHT);
  3212. if (NULL == $$)
  3213. {
  3214. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3215. YYABORT( E_OUTOFMEMORY );
  3216. }
  3217. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" < "));
  3218. }
  3219. | '<' all
  3220. {
  3221. $$ = PctCreateRelationalNode(DBOP_less_all, DEFAULTWEIGHT);
  3222. if (NULL == $$)
  3223. {
  3224. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3225. YYABORT( E_OUTOFMEMORY );
  3226. }
  3227. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" < ^a "));
  3228. }
  3229. | '<' some
  3230. {
  3231. $$ = PctCreateRelationalNode(DBOP_less_any, DEFAULTWEIGHT);
  3232. if (NULL == $$)
  3233. {
  3234. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3235. YYABORT( E_OUTOFMEMORY );
  3236. }
  3237. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" < ^s "));
  3238. }
  3239. | '>'
  3240. {
  3241. $$ = PctCreateRelationalNode(DBOP_greater, DEFAULTWEIGHT);
  3242. if (NULL == $$)
  3243. {
  3244. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3245. YYABORT( E_OUTOFMEMORY );
  3246. }
  3247. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" > "));
  3248. }
  3249. | '>' all
  3250. {
  3251. $$ = PctCreateRelationalNode(DBOP_greater_all, DEFAULTWEIGHT);
  3252. if (NULL == $$)
  3253. {
  3254. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3255. YYABORT( E_OUTOFMEMORY );
  3256. }
  3257. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" > ^a "));
  3258. }
  3259. | '>' some
  3260. {
  3261. $$ = PctCreateRelationalNode(DBOP_greater_any, DEFAULTWEIGHT);
  3262. if (NULL == $$)
  3263. {
  3264. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3265. YYABORT( E_OUTOFMEMORY );
  3266. }
  3267. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" > ^s "));
  3268. }
  3269. | _LE
  3270. {
  3271. $$ = PctCreateRelationalNode(DBOP_less_equal, DEFAULTWEIGHT);
  3272. if (NULL == $$)
  3273. {
  3274. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3275. YYABORT( E_OUTOFMEMORY );
  3276. }
  3277. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" <= "));
  3278. }
  3279. | _LE all
  3280. {
  3281. $$ = PctCreateRelationalNode(DBOP_less_equal_all, DEFAULTWEIGHT);
  3282. if (NULL == $$)
  3283. {
  3284. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3285. YYABORT( E_OUTOFMEMORY );
  3286. }
  3287. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" <= ^a "));
  3288. }
  3289. | _LE some
  3290. {
  3291. $$ = PctCreateRelationalNode(DBOP_less_equal_any, DEFAULTWEIGHT);
  3292. if (NULL == $$)
  3293. {
  3294. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3295. YYABORT( E_OUTOFMEMORY );
  3296. }
  3297. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" <= ^s "));
  3298. }
  3299. | _GE
  3300. {
  3301. $$ = PctCreateRelationalNode(DBOP_greater_equal, DEFAULTWEIGHT);
  3302. if (NULL == $$)
  3303. {
  3304. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3305. YYABORT( E_OUTOFMEMORY );
  3306. }
  3307. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" >= "));
  3308. }
  3309. | _GE all
  3310. {
  3311. $$ = PctCreateRelationalNode(DBOP_greater_equal_all, DEFAULTWEIGHT);
  3312. if (NULL == $$)
  3313. {
  3314. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3315. YYABORT( E_OUTOFMEMORY );
  3316. }
  3317. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" >= ^a "));
  3318. }
  3319. | _GE some
  3320. {
  3321. $$ = PctCreateRelationalNode(DBOP_greater_equal_any, DEFAULTWEIGHT);
  3322. if (NULL == $$)
  3323. {
  3324. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3325. YYABORT( E_OUTOFMEMORY );
  3326. }
  3327. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" >= ^s "));
  3328. }
  3329. ;
  3330. vector_literal:
  3331. _ARRAY left_sqbrkt opt_literal_list right_sqbrkt
  3332. {
  3333. $$ = PctReverse($3);
  3334. }
  3335. ;
  3336. left_sqbrkt:
  3337. '['
  3338. {
  3339. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"{"));
  3340. }
  3341. ;
  3342. right_sqbrkt:
  3343. ']'
  3344. {
  3345. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"}"));
  3346. }
  3347. ;
  3348. opt_literal_list:
  3349. /* empty */
  3350. {
  3351. $$ = NULL;
  3352. }
  3353. | literal_list
  3354. ;
  3355. literal_list:
  3356. literal_list comma typed_literal
  3357. {
  3358. AssertReq($1);
  3359. if (NULL == $3)
  3360. YYABORT(DB_E_CANTCONVERTVALUE);
  3361. $$ = PctLink($3, $1);
  3362. if (NULL == $$)
  3363. {
  3364. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3365. YYABORT( E_OUTOFMEMORY );
  3366. }
  3367. }
  3368. | typed_literal
  3369. {
  3370. if (NULL == $1)
  3371. YYABORT(DB_E_CANTCONVERTVALUE);
  3372. $$ = $1;
  3373. }
  3374. ;
  3375. comma:
  3376. ','
  3377. {
  3378. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L","));
  3379. }
  3380. ;
  3381. /* 4.4.x NULL Predicate */
  3382. null_predicate:
  3383. column_reference _IS _NULL
  3384. {
  3385. AssertReq($1);
  3386. $2 = PctAllocNode(DBVALUEKIND_VARIANT, DBOP_scalar_constant);
  3387. if (NULL == $2)
  3388. {
  3389. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3390. YYABORT( E_OUTOFMEMORY );
  3391. }
  3392. ((PROPVARIANT*)$2->value.pvValue)->vt = VT_EMPTY;
  3393. $$ = PctCreateRelationalNode(DBOP_equal, DEFAULTWEIGHT);
  3394. if (NULL == $$)
  3395. {
  3396. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3397. YYABORT( E_OUTOFMEMORY );
  3398. }
  3399. $$->pctFirstChild = $1;
  3400. $1->pctNextSibling = $2;
  3401. }
  3402. | column_reference _IS_NOT _NULL
  3403. {
  3404. AssertReq($1);
  3405. $2 = PctAllocNode(DBVALUEKIND_VARIANT, DBOP_scalar_constant);
  3406. if (NULL == $2)
  3407. {
  3408. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3409. YYABORT( E_OUTOFMEMORY );
  3410. }
  3411. ((PROPVARIANT*)$2->value.pvValue)->vt = VT_EMPTY;
  3412. // $$ = PctCreateRelationalNode(DBOP_not_equal, DEFAULTWEIGHT);
  3413. $$ = PctCreateRelationalNode(DBOP_equal, DEFAULTWEIGHT);
  3414. if (NULL == $$)
  3415. {
  3416. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3417. YYABORT( E_OUTOFMEMORY );
  3418. }
  3419. $$->pctFirstChild = $1;
  3420. $1->pctNextSibling = $2;
  3421. $$ = PctCreateNotNode(DEFAULTWEIGHT, $$);
  3422. if (NULL == $$)
  3423. {
  3424. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3425. YYABORT( E_OUTOFMEMORY );
  3426. }
  3427. }
  3428. ;
  3429. /* 8.12 search_condition */
  3430. search_condition:
  3431. boolean_term
  3432. | search_condition or_op boolean_term
  3433. {
  3434. AssertReq($1);
  3435. AssertReq($3);
  3436. $$ = PctCreateBooleanNode(DBOP_or, DEFAULTWEIGHT, $1, $3);
  3437. if (NULL == $$)
  3438. {
  3439. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3440. YYABORT( E_OUTOFMEMORY );
  3441. }
  3442. }
  3443. ;
  3444. boolean_term:
  3445. boolean_factor
  3446. | boolean_term and_op boolean_factor
  3447. {
  3448. AssertReq($1);
  3449. AssertReq($3);
  3450. $$ = PctCreateBooleanNode(DBOP_and, DEFAULTWEIGHT, $1, $3);
  3451. if (NULL == $$)
  3452. {
  3453. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3454. YYABORT( E_OUTOFMEMORY );
  3455. }
  3456. }
  3457. ;
  3458. boolean_factor:
  3459. boolean_test
  3460. | not_op boolean_test %prec mHighest
  3461. {
  3462. AssertReq($2);
  3463. $$ = PctCreateNotNode(DEFAULTWEIGHT, $2);
  3464. if (NULL == $$)
  3465. {
  3466. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3467. YYABORT( E_OUTOFMEMORY );
  3468. }
  3469. }
  3470. ;
  3471. or_op:
  3472. _OR
  3473. {
  3474. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" OR "));
  3475. }
  3476. ;
  3477. and_op:
  3478. _AND
  3479. {
  3480. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" AND "));
  3481. }
  3482. ;
  3483. not_op:
  3484. _NOT
  3485. {
  3486. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L" NOT "));
  3487. }
  3488. ;
  3489. boolean_test:
  3490. boolean_primary
  3491. | boolean_primary _IS _TRUE
  3492. {
  3493. AssertReq($1);
  3494. $$ = PctCreateNode(DBOP_is_TRUE, $1, NULL);
  3495. if (NULL == $$)
  3496. {
  3497. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3498. YYABORT( E_OUTOFMEMORY );
  3499. }
  3500. }
  3501. | boolean_primary _IS _FALSE
  3502. {
  3503. AssertReq($1);
  3504. $$ = PctCreateNode(DBOP_is_FALSE, $1, NULL);
  3505. if (NULL == $$)
  3506. {
  3507. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3508. YYABORT( E_OUTOFMEMORY );
  3509. }
  3510. }
  3511. | boolean_primary _IS _UNKNOWN
  3512. {
  3513. AssertReq($1);
  3514. $$ = PctCreateNode(DBOP_is_INVALID, $1, NULL);
  3515. if (NULL == $$)
  3516. {
  3517. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3518. YYABORT( E_OUTOFMEMORY );
  3519. }
  3520. }
  3521. | boolean_primary _IS_NOT _TRUE
  3522. {
  3523. AssertReq($1);
  3524. $2 = PctCreateNode(DBOP_is_TRUE, $1, NULL);
  3525. if (NULL == $2)
  3526. {
  3527. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3528. YYABORT( E_OUTOFMEMORY );
  3529. }
  3530. $$ = PctCreateNotNode(DEFAULTWEIGHT, $2);
  3531. if (NULL == $$)
  3532. {
  3533. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3534. YYABORT( E_OUTOFMEMORY );
  3535. }
  3536. }
  3537. | boolean_primary _IS_NOT _FALSE
  3538. {
  3539. AssertReq($1);
  3540. $2 = PctCreateNode(DBOP_is_FALSE, $1, NULL);
  3541. if (NULL == $2)
  3542. {
  3543. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3544. YYABORT( E_OUTOFMEMORY );
  3545. }
  3546. $$ = PctCreateNotNode(DEFAULTWEIGHT, $2);
  3547. if (NULL == $$)
  3548. {
  3549. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3550. YYABORT( E_OUTOFMEMORY );
  3551. }
  3552. }
  3553. | boolean_primary _IS_NOT _UNKNOWN
  3554. {
  3555. AssertReq($1);
  3556. $2 = PctCreateNode(DBOP_is_INVALID, $1, NULL);
  3557. if (NULL == $2)
  3558. {
  3559. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3560. YYABORT( E_OUTOFMEMORY );
  3561. }
  3562. $$ = PctCreateNotNode(DEFAULTWEIGHT, $2);
  3563. if (NULL == $$)
  3564. {
  3565. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3566. YYABORT( E_OUTOFMEMORY );
  3567. }
  3568. }
  3569. ;
  3570. boolean_primary:
  3571. /* empty */
  3572. {
  3573. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L"("));
  3574. $$ = NULL;
  3575. }
  3576. predicate
  3577. {
  3578. AssertReq($2);
  3579. m_pIPTProperties->AppendCiRestriction(VAL_AND_CCH_MINUS_NULL(L")"));
  3580. $$ = $2;
  3581. }
  3582. | '(' search_condition ')'
  3583. {
  3584. AssertReq($2);
  3585. $$ = $2;
  3586. }
  3587. ;
  3588. order_by_clause:
  3589. _ORDER_BY sort_specification_list
  3590. {
  3591. AssertReq($2);
  3592. $2 = PctReverse($2);
  3593. $$ = PctCreateNode(DBOP_sort_list_anchor, $2, NULL);
  3594. if (NULL == $$)
  3595. {
  3596. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3597. YYABORT( E_OUTOFMEMORY );
  3598. }
  3599. }
  3600. ;
  3601. sort_specification_list:
  3602. sort_specification_list ',' sort_specification
  3603. {
  3604. AssertReq($1);
  3605. AssertReq($3);
  3606. $$ = PctLink($3, $1);
  3607. if (NULL == $$)
  3608. {
  3609. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3610. YYABORT( E_OUTOFMEMORY );
  3611. }
  3612. }
  3613. | sort_specification
  3614. ;
  3615. sort_specification:
  3616. sort_key opt_ordering_specification
  3617. {
  3618. AssertReq($1);
  3619. AssertReq($2);
  3620. $2->value.pdbsrtinfValue->lcid = m_pIPSession->GetLCID();
  3621. $2->pctFirstChild = $1;
  3622. $$ = $2;
  3623. }
  3624. ;
  3625. opt_ordering_specification:
  3626. /* empty */
  3627. {
  3628. $$ = PctCreateNode(DBOP_sort_list_element, DBVALUEKIND_SORTINFO, NULL);
  3629. if (NULL == $$)
  3630. {
  3631. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3632. YYABORT( E_OUTOFMEMORY );
  3633. }
  3634. $$->value.pdbsrtinfValue->fDesc = m_pIPTProperties->GetSortDesc();
  3635. }
  3636. | _ASC
  3637. {
  3638. $$ = PctCreateNode(DBOP_sort_list_element, DBVALUEKIND_SORTINFO, NULL);
  3639. if (NULL == $$)
  3640. {
  3641. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3642. YYABORT( E_OUTOFMEMORY );
  3643. }
  3644. $$->value.pdbsrtinfValue->fDesc = QUERY_SORTASCEND;
  3645. m_pIPTProperties->SetSortDesc(QUERY_SORTASCEND);
  3646. }
  3647. | _DESC
  3648. {
  3649. $$ = PctCreateNode(DBOP_sort_list_element, DBVALUEKIND_SORTINFO, NULL);
  3650. if (NULL == $$)
  3651. {
  3652. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3653. YYABORT(E_OUTOFMEMORY );
  3654. }
  3655. $$->value.pdbsrtinfValue->fDesc = QUERY_SORTDESCEND;
  3656. m_pIPTProperties->SetSortDesc(QUERY_SORTDESCEND);
  3657. }
  3658. ;
  3659. sort_key:
  3660. column_reference
  3661. {
  3662. //@SetCiColumn does the clear m_pCMonarchSessionData->ClearCiColumn();
  3663. }
  3664. | integer
  3665. ;
  3666. opt_order_by_clause:
  3667. /* empty */
  3668. {
  3669. $$ = NULL;
  3670. }
  3671. | order_by_clause
  3672. {
  3673. $$ = $1;
  3674. }
  3675. ;
  3676. /* 4.6 SET Statement */
  3677. set_statement:
  3678. set_propertyname_statement
  3679. | set_rankmethod_statement
  3680. | set_global_directive
  3681. ;
  3682. set_propertyname_statement:
  3683. _SET _PROPERTYNAME guid_format _PROPID property_id _AS column_alias opt_type_clause
  3684. {
  3685. HRESULT hr = S_OK;
  3686. $1 = PctBuiltInProperty($7->value.pwszValue, m_pIPSession, m_pIPTProperties);
  3687. if (NULL != $1)
  3688. {
  3689. // This is a built-in friendly name. Definition better match built in definition.
  3690. if (*$3->value.pGuid != $1->value.pdbidValue->uGuid.guid ||
  3691. m_pIPTProperties->GetDBType() != $8->value.usValue ||
  3692. DBKIND_GUID_PROPID != $1->value.pdbidValue->eKind ||
  3693. $5->value.pvarValue->lVal != (long)$1->value.pdbidValue->uName.ulPropid)
  3694. {
  3695. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_BUILTIN_PROPERTY);
  3696. m_pIPTProperties->SetErrorToken($7->value.pwszValue);
  3697. YYABORT(DB_E_ERRORSINCOMMAND);
  3698. }
  3699. }
  3700. else
  3701. m_pIPSession->m_pCPropertyList->SetPropertyEntry($7->value.pwszValue,
  3702. $8->value.ulValue,
  3703. *$3->value.pGuid,
  3704. DBKIND_GUID_PROPID,
  3705. (LPWSTR) LongToPtr( $5->value.pvarValue->lVal ),
  3706. m_pIPSession->GetGlobalDefinition());
  3707. if (FAILED(hr))
  3708. {
  3709. // Unable to store the property name and/or values in the symbol table
  3710. m_pIPTProperties->SetErrorHResult(hr, MONSQL_PARSE_ERROR);
  3711. m_pIPTProperties->SetErrorToken($7->value.pwszValue);
  3712. YYABORT(DB_E_ERRORSINCOMMAND);
  3713. }
  3714. if ($1)
  3715. DeleteDBQT($1);
  3716. DeleteDBQT($3);
  3717. DeleteDBQT($5);
  3718. DeleteDBQT($7);
  3719. DeleteDBQT($8);
  3720. $$ = NULL;
  3721. }
  3722. | _SET _PROPERTYNAME guid_format _PROPID property_name _AS column_alias opt_type_clause
  3723. {
  3724. HRESULT hr = S_OK;
  3725. $1 = PctBuiltInProperty($7->value.pwszValue, m_pIPSession, m_pIPTProperties);
  3726. if (NULL != $1)
  3727. {
  3728. // This is a built-in friendly name. Definition better match built in definition.
  3729. if (*$3->value.pGuid != $1->value.pdbidValue->uGuid.guid ||
  3730. m_pIPTProperties->GetDBType() != $8->value.ulValue ||
  3731. DBKIND_GUID_NAME != $1->value.pdbidValue->eKind ||
  3732. 0 != _wcsicmp(((PROPVARIANT*)$5->value.pvValue)->bstrVal, $1->value.pdbidValue->uName.pwszName))
  3733. {
  3734. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_BUILTIN_PROPERTY);
  3735. // m_pIPTProperties->SetErrorToken($1->value.pwszValue);
  3736. YYABORT(DB_E_ERRORSINCOMMAND);
  3737. }
  3738. }
  3739. else
  3740. hr = m_pIPSession->m_pCPropertyList->SetPropertyEntry($7->value.pwszValue,
  3741. $8->value.ulValue,
  3742. *$3->value.pGuid,
  3743. DBKIND_GUID_NAME,
  3744. ((PROPVARIANT*)$5->value.pvValue)->bstrVal,
  3745. m_pIPSession->GetGlobalDefinition());
  3746. if (FAILED(hr))
  3747. {
  3748. // Unable to store the property name and/or values in the symbol table
  3749. m_pIPTProperties->SetErrorHResult(hr, MONSQL_PARSE_ERROR);
  3750. m_pIPTProperties->SetErrorToken($7->value.pwszValue);
  3751. YYABORT(DB_E_ERRORSINCOMMAND);
  3752. }
  3753. if ($1)
  3754. DeleteDBQT($1);
  3755. DeleteDBQT($3);
  3756. DeleteDBQT($5);
  3757. DeleteDBQT($7);
  3758. DeleteDBQT($8);
  3759. }
  3760. ;
  3761. column_alias:
  3762. identifier
  3763. ;
  3764. opt_type_clause:
  3765. /* empty */
  3766. {
  3767. $$ = PctCreateNode(DBOP_scalar_constant, DBVALUEKIND_UI2, NULL);
  3768. if ( NULL == $$ )
  3769. {
  3770. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  3771. YYABORT( E_OUTOFMEMORY );
  3772. }
  3773. $$->value.usValue = DBTYPE_WSTR|DBTYPE_BYREF;
  3774. }
  3775. | _TYPE dbtype
  3776. {
  3777. $$ = $2;
  3778. }
  3779. ;
  3780. dbtype:
  3781. base_dbtype
  3782. {
  3783. AssertReq($1);
  3784. DBTYPE dbType = GetDBTypeFromStr($1->value.pwszValue);
  3785. if ((DBTYPE_EMPTY == dbType) ||
  3786. (DBTYPE_BYREF == dbType) ||
  3787. (DBTYPE_VECTOR == dbType))
  3788. {
  3789. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  3790. m_pIPTProperties->SetErrorToken($1->value.pwszValue);
  3791. m_pIPTProperties->SetErrorToken(L"<base Indexing Service dbtype1");
  3792. YYABORT(DB_E_ERRORSINCOMMAND);
  3793. }
  3794. DeleteDBQT($1);
  3795. $1 = NULL;
  3796. $$ = PctCreateNode(DBOP_scalar_constant, DBVALUEKIND_UI2, NULL);
  3797. if ( NULL == $$ )
  3798. {
  3799. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  3800. YYABORT( E_OUTOFMEMORY );
  3801. }
  3802. if (DBTYPE_WSTR == dbType || DBTYPE_STR == dbType)
  3803. dbType = dbType | DBTYPE_BYREF;
  3804. $$->value.usValue = dbType;
  3805. }
  3806. | base_dbtype '|' base_dbtype
  3807. {
  3808. AssertReq($1);
  3809. AssertReq($3);
  3810. DBTYPE dbType1 = GetDBTypeFromStr($1->value.pwszValue);
  3811. DBTYPE dbType2 = GetDBTypeFromStr($3->value.pwszValue);
  3812. if ((DBTYPE_BYREF == dbType1 || DBTYPE_VECTOR == dbType1) &&
  3813. (DBTYPE_BYREF == dbType2 || DBTYPE_VECTOR == dbType2))
  3814. {
  3815. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  3816. m_pIPTProperties->SetErrorToken($3->value.pwszValue);
  3817. m_pIPTProperties->SetErrorToken(
  3818. L"DBTYPE_I2, DBTYPE_I4, DBTYPE_R4, DBTYPE_R8, DBTYPE_CY, DBTYPE_DATE, DBTYPE_BSTR, DBTYPE_BOOL, DBTYPE_STR, DBTYPE_WSTR");
  3819. YYABORT(DB_E_ERRORSINCOMMAND);
  3820. }
  3821. if (DBTYPE_BYREF != dbType1 && DBTYPE_VECTOR != dbType1 &&
  3822. DBTYPE_BYREF != dbType2 && DBTYPE_VECTOR != dbType2)
  3823. {
  3824. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  3825. m_pIPTProperties->SetErrorToken($3->value.pwszValue);
  3826. m_pIPTProperties->SetErrorToken(L"DBTYPE_BYREF, DBTYPE_VECTOR");
  3827. YYABORT(DB_E_ERRORSINCOMMAND);
  3828. }
  3829. DeleteDBQT($1);
  3830. $1 = NULL;
  3831. DeleteDBQT($3);
  3832. $3 = NULL;
  3833. $$ = PctCreateNode(DBOP_scalar_constant, DBVALUEKIND_UI2, NULL);
  3834. if ( NULL == $$ )
  3835. {
  3836. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY );
  3837. YYABORT( E_OUTOFMEMORY );
  3838. }
  3839. $$->value.usValue = dbType1 | dbType2;
  3840. }
  3841. ;
  3842. base_dbtype:
  3843. identifier
  3844. ;
  3845. property_id:
  3846. unsigned_integer
  3847. ;
  3848. property_name:
  3849. _STRING
  3850. ;
  3851. guid_format:
  3852. _STRING
  3853. {
  3854. GUID* pGuid = (GUID*) CoTaskMemAlloc(sizeof GUID); // this will become part of tree
  3855. if (NULL == pGuid)
  3856. {
  3857. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  3858. YYABORT( E_OUTOFMEMORY );
  3859. }
  3860. BOOL bRet = ParseGuid(((PROPVARIANT*)$1->value.pvValue)->bstrVal, *pGuid);
  3861. if ( bRet && GUID_NULL != *pGuid)
  3862. {
  3863. SCODE sc = PropVariantClear((PROPVARIANT*)$1->value.pvValue);
  3864. Assert(SUCCEEDED(sc)); // UNDONE: meaningful error message
  3865. CoTaskMemFree($1->value.pvValue);
  3866. $1->wKind = DBVALUEKIND_GUID;
  3867. $1->value.pGuid = pGuid;
  3868. $$ = $1;
  3869. }
  3870. else
  3871. {
  3872. CoTaskMemFree(pGuid);
  3873. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  3874. m_pIPTProperties->SetErrorToken(((PROPVARIANT*)$1->value.pvValue)->bstrVal);
  3875. YYABORT(DB_E_ERRORSINCOMMAND);
  3876. }
  3877. }
  3878. ;
  3879. set_rankmethod_statement:
  3880. _SET _RANKMETHOD rankmethod
  3881. {
  3882. $$ = NULL;
  3883. }
  3884. ;
  3885. rankmethod:
  3886. _ID _ID
  3887. {
  3888. AssertReq($1);
  3889. AssertReq($2);
  3890. if ((0==_wcsicmp($1->value.pwszValue, L"Jaccard")) &&
  3891. (0==_wcsicmp($2->value.pwszValue, L"coefficient")))
  3892. m_pIPSession->SetRankingMethod(VECTOR_RANK_JACCARD);
  3893. else if ((0==_wcsicmp($1->value.pwszValue, L"dice")) &&
  3894. (0==_wcsicmp($2->value.pwszValue, L"coefficient")))
  3895. m_pIPSession->SetRankingMethod(VECTOR_RANK_DICE);
  3896. else if ((0==_wcsicmp($1->value.pwszValue, L"inner")) &&
  3897. (0==_wcsicmp($2->value.pwszValue, L"product")))
  3898. m_pIPSession->SetRankingMethod(VECTOR_RANK_INNER);
  3899. else
  3900. {
  3901. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  3902. m_pIPTProperties->SetErrorToken($1->value.pwszValue);
  3903. m_pIPTProperties->SetErrorToken(L"MINIMUM, MAXIMUM, JACCARD COEFFICIENT, DICE COEFFICIENT, INNER PRODUCT");
  3904. YYABORT(DB_E_ERRORSINCOMMAND);
  3905. }
  3906. DeleteDBQT($2);
  3907. $2 = NULL;
  3908. DeleteDBQT($1);
  3909. $1 = NULL;
  3910. $$ = NULL;
  3911. }
  3912. | _ID
  3913. {
  3914. AssertReq($1);
  3915. if (0==_wcsicmp($1->value.pwszValue, L"minimum"))
  3916. m_pIPSession->SetRankingMethod(VECTOR_RANK_MIN);
  3917. else if (0==_wcsicmp($1->value.pwszValue, L"maximum"))
  3918. m_pIPSession->SetRankingMethod(VECTOR_RANK_MAX);
  3919. else
  3920. {
  3921. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  3922. m_pIPTProperties->SetErrorToken($1->value.pwszValue);
  3923. m_pIPTProperties->SetErrorToken(L"MINIMUM, MAXIMUM, JACCARD COEFFICIENT, DICE COEFFICIENT, INNER PRODUCT");
  3924. YYABORT(DB_E_ERRORSINCOMMAND);
  3925. }
  3926. DeleteDBQT($1);
  3927. $1 = NULL;
  3928. $$ = NULL;
  3929. }
  3930. ;
  3931. set_global_directive:
  3932. _SET _ID _ID
  3933. {
  3934. if (0 != _wcsicmp($2->value.pwszValue, L"GLOBAL"))
  3935. {
  3936. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  3937. m_pIPTProperties->SetErrorToken($2->value.pwszValue);
  3938. m_pIPTProperties->SetErrorToken(L"GLOBAL");
  3939. YYABORT(DB_E_ERRORSINCOMMAND);
  3940. }
  3941. if (0 == _wcsicmp($3->value.pwszValue, L"ON"))
  3942. m_pIPSession->SetGlobalDefinition(TRUE);
  3943. else if (0 == _wcsicmp($3->value.pwszValue, L"OFF"))
  3944. m_pIPSession->SetGlobalDefinition(FALSE);
  3945. else
  3946. {
  3947. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  3948. m_pIPTProperties->SetErrorToken($3->value.pwszValue);
  3949. m_pIPTProperties->SetErrorToken(L"ON, OFF");
  3950. YYABORT(DB_E_ERRORSINCOMMAND);
  3951. }
  3952. DeleteDBQT($2);
  3953. DeleteDBQT($3);
  3954. $$ = NULL;
  3955. }
  3956. ;
  3957. /* 4.7 CREATE VIEW Statement */
  3958. create_view_statement:
  3959. _CREATE _VIEW view_name _AS _SELECT select_list from_clause
  3960. { // _CREATE _VIEW view_name _AS _SELECT select_list from_clause
  3961. AssertReq( $3 );
  3962. AssertReq( $6 );
  3963. AssertReq( $7 );
  3964. //
  3965. // Can create views only on the current catalog
  3966. //
  3967. if ( 0 != _wcsicmp(($3->value.pdbcntnttblValue)->pwszMachine, m_pIPSession->GetDefaultMachine()) &&
  3968. 0 != _wcsicmp(($3->value.pdbcntnttblValue)->pwszCatalog, m_pIPSession->GetDefaultCatalog()) )
  3969. {
  3970. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  3971. m_pIPTProperties->SetErrorToken( ($3->pctNextSibling)->value.pwszValue );
  3972. m_pIPTProperties->SetErrorToken( L"<unqualified temporary view name>" );
  3973. YYABORT( DB_E_ERRORSINCOMMAND );
  3974. }
  3975. if ( DBOP_outall_name == $6->op )
  3976. {
  3977. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR );
  3978. m_pIPTProperties->SetErrorToken( L"*" );
  3979. m_pIPTProperties->SetErrorToken( L"<select list>" );
  3980. YYABORT( DB_E_ERRORSINCOMMAND );
  3981. }
  3982. Assert( DBOP_content_table == $3->op );
  3983. AssertReq( $3->pctNextSibling ); // name of the view
  3984. SCODE sc = S_OK;
  3985. // This is the LA_proj, which doesn't have a NextSibling.
  3986. // Use the next sibling to store contenttable tree
  3987. // specified in the from_clause
  3988. Assert( 0 == $6->pctNextSibling );
  3989. if ( L'#' != $3->pctNextSibling->value.pwszValue[0] )
  3990. {
  3991. if ( m_pIPSession->GetGlobalDefinition() )
  3992. sc = m_pIPSession->GetGlobalViewList()->SetViewDefinition(
  3993. m_pIPSession,
  3994. m_pIPTProperties,
  3995. $3->pctNextSibling->value.pwszValue,
  3996. NULL, // all catalogs
  3997. $6);
  3998. else
  3999. {
  4000. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR );
  4001. m_pIPTProperties->SetErrorToken( $3->pctNextSibling->value.pwszValue );
  4002. m_pIPTProperties->SetErrorToken( L"<temporary view name>" );
  4003. YYABORT( DB_E_ERRORSINCOMMAND );
  4004. }
  4005. }
  4006. else
  4007. {
  4008. if ( 1 >= wcslen($3->pctNextSibling->value.pwszValue) )
  4009. {
  4010. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR );
  4011. m_pIPTProperties->SetErrorToken( $3->pctNextSibling->value.pwszValue );
  4012. m_pIPTProperties->SetErrorToken( L"<temporary view name>" );
  4013. YYABORT( DB_E_ERRORSINCOMMAND );
  4014. }
  4015. else if ( L'#' == $3->pctNextSibling->value.pwszValue[1] )
  4016. {
  4017. // store the scope information for the view
  4018. $6->pctNextSibling = $7;
  4019. $7 = 0;
  4020. sc = m_pIPSession->GetLocalViewList()->SetViewDefinition(
  4021. m_pIPSession,
  4022. m_pIPTProperties,
  4023. $3->pctNextSibling->value.pwszValue,
  4024. ($3->value.pdbcntnttblValue)->pwszCatalog,
  4025. $6);
  4026. }
  4027. else
  4028. {
  4029. $6->pctNextSibling = $7;
  4030. $7 = 0;
  4031. sc = m_pIPSession->GetGlobalViewList()->SetViewDefinition(
  4032. m_pIPSession,
  4033. m_pIPTProperties,
  4034. $3->pctNextSibling->value.pwszValue,
  4035. ($3->value.pdbcntnttblValue)->pwszCatalog,
  4036. $6);
  4037. }
  4038. }
  4039. if ( FAILED(sc) )
  4040. {
  4041. if ( E_INVALIDARG == sc )
  4042. {
  4043. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_VIEW_ALREADY_DEFINED );
  4044. m_pIPTProperties->SetErrorToken( $3->pctNextSibling->value.pwszValue );
  4045. m_pIPTProperties->SetErrorToken( ($3->value.pdbcntnttblValue)->pwszCatalog );
  4046. YYABORT( DB_E_ERRORSINCOMMAND );
  4047. }
  4048. else
  4049. {
  4050. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR );
  4051. m_pIPTProperties->SetErrorToken( $3->pctNextSibling->value.pwszValue );
  4052. YYABORT( DB_E_ERRORSINCOMMAND );
  4053. }
  4054. }
  4055. DeleteDBQT( $3 );
  4056. DeleteDBQT( $6 );
  4057. if ( 0 != $7 )
  4058. DeleteDBQT( $7 );
  4059. $$ = 0;
  4060. }
  4061. ;
  4062. /* 4.x DROP VIEW Statement */
  4063. drop_view_statement:
  4064. _DROP _VIEW view_name
  4065. {
  4066. AssertReq( $3 );
  4067. AssertReq( $3->pctNextSibling ); // name of the view
  4068. SCODE sc = S_OK;
  4069. if ( L'#' != $3->pctNextSibling->value.pwszValue[0] )
  4070. {
  4071. if ( m_pIPSession->GetGlobalDefinition() )
  4072. sc = m_pIPSession->GetGlobalViewList()->DropViewDefinition( $3->pctNextSibling->value.pwszValue, NULL );
  4073. else
  4074. {
  4075. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR );
  4076. m_pIPTProperties->SetErrorToken( $3->pctNextSibling->value.pwszValue );
  4077. m_pIPTProperties->SetErrorToken( L"<temporary view name>" );
  4078. YYABORT( DB_E_ERRORSINCOMMAND );
  4079. }
  4080. }
  4081. else
  4082. {
  4083. if ( 1 >= wcslen($3->pctNextSibling->value.pwszValue) )
  4084. {
  4085. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR );
  4086. m_pIPTProperties->SetErrorToken( $3->pctNextSibling->value.pwszValue );
  4087. m_pIPTProperties->SetErrorToken( L"<temporary view name>" );
  4088. YYABORT( DB_E_ERRORSINCOMMAND );
  4089. }
  4090. else if ( L'#' == $3->pctNextSibling->value.pwszValue[1] )
  4091. sc = m_pIPSession->GetLocalViewList()->DropViewDefinition( $3->pctNextSibling->value.pwszValue,
  4092. ($3->value.pdbcntnttblValue)->pwszCatalog );
  4093. else
  4094. sc = m_pIPSession->GetGlobalViewList()->DropViewDefinition( $3->pctNextSibling->value.pwszValue,
  4095. ($3->value.pdbcntnttblValue)->pwszCatalog );
  4096. }
  4097. if ( FAILED(sc) )
  4098. {
  4099. m_pIPTProperties->SetErrorHResult( DB_E_ERRORSINCOMMAND, MONSQL_VIEW_NOT_DEFINED );
  4100. m_pIPTProperties->SetErrorToken( $3->pctNextSibling->value.pwszValue );
  4101. m_pIPTProperties->SetErrorToken( ($3->value.pdbcntnttblValue)->pwszCatalog );
  4102. YYABORT( DB_E_ERRORSINCOMMAND );
  4103. }
  4104. DeleteDBQT( $3 );
  4105. $$ = 0;
  4106. }
  4107. ;