Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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