PageRenderTime 62ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/rucrm/include/Webservices/VTQL_Parser.php

https://code.google.com/p/vtiger-ru-fork/
PHP | 1656 lines | 1122 code | 48 blank | 486 comment | 174 complexity | 4eac2b9786e0740c10c8a668341e8174 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-2.0, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* Driver template for the PHP_VTQL_ParserrGenerator parser generator. (PHP port of LEMON)
  3. */
  4. /**
  5. * This can be used to store both the string representation of
  6. * a token, and any useful meta-data associated with the token.
  7. *
  8. * meta-data should be stored as an array
  9. */
  10. class VTQL_ParseryyToken implements ArrayAccess
  11. {
  12. public $string = '';
  13. public $metadata = array();
  14. function __construct($s, $m = array())
  15. {
  16. if ($s instanceof VTQL_ParseryyToken) {
  17. $this->string = $s->string;
  18. $this->metadata = $s->metadata;
  19. } else {
  20. $this->string = (string) $s;
  21. if ($m instanceof VTQL_ParseryyToken) {
  22. $this->metadata = $m->metadata;
  23. } elseif (is_array($m)) {
  24. $this->metadata = $m;
  25. }
  26. }
  27. }
  28. function __toString()
  29. {
  30. return $this->_string;
  31. }
  32. function offsetExists($offset)
  33. {
  34. return isset($this->metadata[$offset]);
  35. }
  36. function offsetGet($offset)
  37. {
  38. return $this->metadata[$offset];
  39. }
  40. function offsetSet($offset, $value)
  41. {
  42. if ($offset === null) {
  43. if (isset($value[0])) {
  44. $x = ($value instanceof VTQL_ParseryyToken) ?
  45. $value->metadata : $value;
  46. $this->metadata = array_merge($this->metadata, $x);
  47. return;
  48. }
  49. $offset = count($this->metadata);
  50. }
  51. if ($value === null) {
  52. return;
  53. }
  54. if ($value instanceof VTQL_ParseryyToken) {
  55. if ($value->metadata) {
  56. $this->metadata[$offset] = $value->metadata;
  57. }
  58. } elseif ($value) {
  59. $this->metadata[$offset] = $value;
  60. }
  61. }
  62. function offsetUnset($offset)
  63. {
  64. unset($this->metadata[$offset]);
  65. }
  66. }
  67. /** The following structure represents a single element of the
  68. * parser's stack. Information stored includes:
  69. *
  70. * + The state number for the parser at this level of the stack.
  71. *
  72. * + The value of the token stored at this level of the stack.
  73. * (In other words, the "major" token.)
  74. *
  75. * + The semantic value stored at this level of the stack. This is
  76. * the information used by the action routines in the grammar.
  77. * It is sometimes called the "minor" token.
  78. */
  79. class VTQL_ParseryyStackEntry
  80. {
  81. public $stateno; /* The state-number */
  82. public $major; /* The major token value. This is the code
  83. ** number for the token at this stack level */
  84. public $minor; /* The user-supplied minor token value. This
  85. ** is the value of the token */
  86. };
  87. // code external to the class is included here
  88. // declare_class is output here
  89. #line 451 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  90. class VTQL_Parser#line 102 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  91. {
  92. /* First off, code is included which follows the "include_class" declaration
  93. ** in the input file. */
  94. #line 199 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  95. /*
  96. add this rule to add parenthesis support.
  97. condition ::= PARENOPEN expr_set expr(E) PARENCLOSE.
  98. sample format(for contacts) for generated sql object
  99. Array (
  100. [column_list] => c4,c3,c2,c1
  101. [tableName] => vtiger_crmentity,vtiger_contactdetails,vtiger_contactaddress,vtiger_contactsubdetails,vtiger_contactscf,vtiger_customerdetails
  102. [where_condition] => Array (
  103. [column_operators] => Array (
  104. [0] => =
  105. [1] => =
  106. [2] => =
  107. )
  108. [column_names] => Array (
  109. [0] => c1
  110. [1] => c2
  111. [2] => c3
  112. )
  113. [column_values] => Array (
  114. [0] => 'llet me'
  115. [1] => 45
  116. [2] => -1
  117. )
  118. //TO BE DONE
  119. [grouping] => Array (
  120. [0] => Array (
  121. [0] => 1
  122. [1] => 2
  123. )
  124. )
  125. [operators] => Array (
  126. [0] => and
  127. [1] => or
  128. )
  129. )
  130. [orderby] => Array (
  131. [0] => c4
  132. [1] => c5
  133. )
  134. [select] => SELECT
  135. [from] => from
  136. [semi_colon] => ;
  137. )*/
  138. private $out;
  139. public $lex;
  140. private $success ;
  141. private $query ;
  142. private $error_msg;
  143. private $syntax_error;
  144. private $user;
  145. function __construct($user, $lex,$out){
  146. if(!is_array($out)){
  147. $out = array();
  148. }
  149. $this->out = &$out;
  150. $this->lex = $lex;
  151. $this->success = false;
  152. $this->error_msg ='';
  153. $this->query = '';
  154. $this->syntax_error = false;
  155. $this->user = $user;
  156. }
  157. function __toString(){
  158. return $this->value."";
  159. }
  160. function buildSelectStmt($sqlDump){
  161. $meta = $sqlDump['meta'];
  162. $fieldcol = $meta->getFieldColumnMapping();
  163. $columnTable = $meta->getColumnTableMapping();
  164. $this->query = 'SELECT ';
  165. if(in_array('*', $sqlDump['column_list'])){
  166. $i=0;
  167. foreach($fieldcol as $field=>$col){
  168. if($i===0){
  169. $this->query = $this->query.$columnTable[$col].'.'.$col;
  170. $i++;
  171. }else{
  172. $this->query = $this->query.','.$columnTable[$col].'.'.$col;
  173. }
  174. }
  175. }else if(in_array('count(*)', $sqlDump['column_list'])){
  176. $this->query = $this->query." COUNT(*)";
  177. }else{
  178. $i=0;
  179. foreach($sqlDump['column_list'] as $ind=>$field){
  180. if(!$fieldcol[$field]){
  181. throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to access '.$field.' attribute denied.");
  182. }
  183. if($i===0){
  184. $this->query = $this->query.$columnTable[$fieldcol[$field]].'.'.$fieldcol[$field];
  185. $i++;
  186. }else{
  187. $this->query = $this->query.','.$columnTable[$fieldcol[$field]].'.'.$fieldcol[$field];
  188. }
  189. }
  190. }
  191. $this->query = $this->query.' FROM '.$sqlDump['tableName'].$sqlDump['defaultJoinConditions'];
  192. $deletedQuery = $meta->getEntityDeletedQuery();
  193. $accessControlQuery = $meta->getEntityAccessControlQuery();
  194. $this->query = $this->query.' '.$accessControlQuery;
  195. if($sqlDump['where_condition']){
  196. if((sizeof($sqlDump['where_condition']['column_names']) ==
  197. sizeof($sqlDump['where_condition']['column_values'])) &&
  198. (sizeof($sqlDump['where_condition']['column_operators']) == sizeof($sqlDump['where_condition']['operators'])+1)){
  199. $this->query = $this->query.' WHERE (';
  200. $i=0;
  201. $referenceFields = $meta->getReferenceFieldDetails();
  202. $ownerFields = $meta->getOwnerFields();
  203. for(;$i<sizeof($sqlDump['where_condition']['column_values']);++$i){
  204. if(!$fieldcol[$sqlDump['where_condition']['column_names'][$i]]){
  205. throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to access ".$sqlDump['where_condition']['column_names'][$i]." attribute denied.");
  206. }
  207. $whereField = $sqlDump['where_condition']['column_names'][$i];
  208. $whereOperator = $sqlDump['where_condition']['column_operators'][$i];
  209. $whereValue = $sqlDump['where_condition']['column_values'][$i];
  210. if(in_array($whereField,array_keys($referenceFields))){
  211. if(is_array($whereValue)){
  212. foreach($whereValue as $index=>$value){
  213. if(strpos($value,'x')===false){
  214. throw new WebServiceException(WebServiceErrorCode::$INVALIDID,"Id specified is incorrect");
  215. }
  216. }
  217. $whereValue = array_map(array($this, 'getReferenceValue'),$whereValue);
  218. }else if(strpos($whereValue,'x')!==false){
  219. $whereValue = $this->getReferenceValue($whereValue);
  220. if(strcasecmp($whereOperator,'like')===0){
  221. $whereValue = "'".$whereValue."'";
  222. }
  223. }else{
  224. throw new WebServiceException(WebServiceErrorCode::$INVALIDID,"Id specified is incorrect");
  225. }
  226. }else if(in_array($whereField,$ownerFields)){
  227. if(is_array($whereValue)){
  228. $groupId = array_map(array($this, 'getOwner'),$whereValue);
  229. }else{
  230. $groupId = $this->getOwner($whereValue);
  231. if(strcasecmp($whereOperator,'like')===0){
  232. $groupId = "'$groupId'";
  233. }
  234. }
  235. $whereValue = $groupId;
  236. }
  237. if(is_array($whereValue)){
  238. $whereValue = "(".implode(',',$whereValue).")";
  239. }elseif(strcasecmp($whereOperator, 'in') === 0){
  240. $whereValue = "($whereValue)";
  241. }
  242. $this->query = $this->query.$columnTable[$fieldcol[$whereField]].'.'.
  243. $fieldcol[$whereField]." ".$whereOperator." ".$whereValue;
  244. if($i <sizeof($sqlDump['where_condition']['column_values'])-1){
  245. $this->query = $this->query.' ';
  246. $this->query = $this->query.$sqlDump['where_condition']['operators'][$i].' ';
  247. }
  248. }
  249. }else{
  250. throw new WebServiceException(WebServiceErrorCode::$QUERYSYNTAX, "columns data inappropriate");
  251. }
  252. $this->query = $this->query.")";
  253. $nextToken = ' AND ';
  254. }else{
  255. if(!empty($deletedQuery)){
  256. $nextToken = " WHERE ";
  257. }
  258. }
  259. if(strcasecmp('calendar',$this->out['moduleName'])===0){
  260. $this->query = $this->query." $nextToken activitytype='Task' AND ";
  261. }elseif(strcasecmp('events',$this->out['moduleName'])===0){
  262. $this->query = $this->query."$nextToken activitytype!='Emails' AND activitytype!='Task' AND ";
  263. }else if(strcasecmp('emails',$this->out['moduleName'])===0){
  264. $this->query = $this->query."$nextToken activitytype='Emails' AND ";
  265. }elseif(!empty($deletedQuery)){
  266. $this->query = $this->query.$nextToken;
  267. }
  268. $this->query = $this->query.' '.$deletedQuery;
  269. if($sqlDump['orderby']){
  270. $i=0;
  271. $this->query = $this->query.' ORDER BY ';
  272. foreach($sqlDump['orderby'] as $ind=>$field){
  273. if($i===0){
  274. $this->query = $this->query.$columnTable[$fieldcol[$field]].".".$fieldcol[$field];
  275. $i++;
  276. }else{
  277. $this->query = $this->query.','.$columnTable[$fieldcol[$field]].".".$fieldcol[$field];
  278. }
  279. }
  280. if($sqlDump['sortOrder']) {
  281. $this->query .= ' '.$sqlDump['sortOrder'];
  282. }
  283. }
  284. if($sqlDump['limit']){
  285. $i=0;
  286. $offset =false;
  287. if(sizeof($sqlDump['limit'])>1){
  288. $offset = true;
  289. }
  290. $this->query = $this->query.' LIMIT ';
  291. foreach($sqlDump['limit'] as $ind=>$field){
  292. if(!$offset){
  293. $field = ($field>100)? 100: $field;
  294. }
  295. if($i===0){
  296. $this->query = $this->query.$field;
  297. $i++;
  298. $offset = false;
  299. }else{
  300. $this->query = $this->query.','.$field;
  301. }
  302. }
  303. }else{
  304. $this->query = $this->query.' LIMIT 100';
  305. }
  306. $this->query = $this->query.';';
  307. }
  308. function getTables($sqlDump,$columns){
  309. $meta = $sqlDump['meta'];
  310. $coltable = $meta->getColumnTableMapping();
  311. $tables = array();
  312. foreach($columns as $ind=>$col){
  313. $tables[$coltable[$col]] = $coltable[$col];
  314. }
  315. $tables = array_keys($tables);
  316. return ($tables);
  317. }
  318. function getReferenceValue($whereValue){
  319. $whereValue = trim($whereValue,'\'"');
  320. $whereValue = vtws_getIdComponents($whereValue);
  321. $whereValue = $whereValue[1];
  322. return $whereValue;
  323. }
  324. function getOwner($whereValue){
  325. $whereValue = trim($whereValue,'\'"');
  326. $whereValue = vtws_getIdComponents($whereValue);
  327. $whereValue = $whereValue[1];
  328. return $whereValue;
  329. }
  330. function isSuccess(){
  331. return $this->success;
  332. }
  333. function getErrorMsg(){
  334. return $this->error_msg;
  335. }
  336. function getQuery(){
  337. return $this->query;
  338. }
  339. function getObjectMetaData(){
  340. return $this->out['meta'];
  341. }
  342. #line 359 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  343. /* Next is all token values, as class constants
  344. */
  345. /*
  346. ** These constants (all generated automatically by the parser generator)
  347. ** specify the various kinds of tokens (terminals) that the parser
  348. ** understands.
  349. **
  350. ** Each symbol here is a terminal symbol in the grammar.
  351. */
  352. const SELECT = 1;
  353. const FRM = 2;
  354. const COLUMNNAME = 3;
  355. const ASTERISK = 4;
  356. const COUNT = 5;
  357. const PARENOPEN = 6;
  358. const PARENCLOSE = 7;
  359. const COMMA = 8;
  360. const TABLENAME = 9;
  361. const WHERE = 10;
  362. const LOGICAL_AND = 11;
  363. const LOGICAL_OR = 12;
  364. const VALUE = 13;
  365. const EQ = 14;
  366. const LT = 15;
  367. const GT = 16;
  368. const LTE = 17;
  369. const GTE = 18;
  370. const NE = 19;
  371. const IN = 20;
  372. const LIKE = 21;
  373. const ORDERBY = 22;
  374. const ASC = 23;
  375. const DESC = 24;
  376. const LIMIT = 25;
  377. const SEMICOLON = 26;
  378. const YY_NO_ACTION = 102;
  379. const YY_ACCEPT_ACTION = 101;
  380. const YY_ERROR_ACTION = 100;
  381. /* Next are that tables used to determine what action to take based on the
  382. ** current state and lookahead token. These tables are used to implement
  383. ** functions that take a state number and lookahead value and return an
  384. ** action integer.
  385. **
  386. ** Suppose the action integer is N. Then the action is determined as
  387. ** follows
  388. **
  389. ** 0 <= N < self::YYNSTATE Shift N. That is,
  390. ** push the lookahead
  391. ** token onto the stack
  392. ** and goto state N.
  393. **
  394. ** self::YYNSTATE <= N < self::YYNSTATE+self::YYNRULE Reduce by rule N-YYNSTATE.
  395. **
  396. ** N == self::YYNSTATE+self::YYNRULE A syntax error has occurred.
  397. **
  398. ** N == self::YYNSTATE+self::YYNRULE+1 The parser accepts its
  399. ** input. (and concludes parsing)
  400. **
  401. ** N == self::YYNSTATE+self::YYNRULE+2 No such action. Denotes unused
  402. ** slots in the yy_action[] table.
  403. **
  404. ** The action table is constructed as a single large static array $yy_action.
  405. ** Given state S and lookahead X, the action is computed as
  406. **
  407. ** self::$yy_action[self::$yy_shift_ofst[S] + X ]
  408. **
  409. ** If the index value self::$yy_shift_ofst[S]+X is out of range or if the value
  410. ** self::$yy_lookahead[self::$yy_shift_ofst[S]+X] is not equal to X or if
  411. ** self::$yy_shift_ofst[S] is equal to self::YY_SHIFT_USE_DFLT, it means that
  412. ** the action is not in the table and that self::$yy_default[S] should be used instead.
  413. **
  414. ** The formula above is for computing the action when the lookahead is
  415. ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
  416. ** a reduce action) then the static $yy_reduce_ofst array is used in place of
  417. ** the static $yy_shift_ofst array and self::YY_REDUCE_USE_DFLT is used in place of
  418. ** self::YY_SHIFT_USE_DFLT.
  419. **
  420. ** The following are the tables generated in this section:
  421. **
  422. ** self::$yy_action A single table containing all actions.
  423. ** self::$yy_lookahead A table containing the lookahead for each entry in
  424. ** yy_action. Used to detect hash collisions.
  425. ** self::$yy_shift_ofst For each state, the offset into self::$yy_action for
  426. ** shifting terminals.
  427. ** self::$yy_reduce_ofst For each state, the offset into self::$yy_action for
  428. ** shifting non-terminals after a reduce.
  429. ** self::$yy_default Default action for each state.
  430. */
  431. const YY_SZ_ACTTAB = 60;
  432. static public $yy_action = array(
  433. /* 0 */ 36, 29, 28, 30, 31, 38, 39, 37, 41, 26,
  434. /* 10 */ 18, 57, 7, 10, 27, 22, 50, 55, 17, 18,
  435. /* 20 */ 15, 9, 12, 42, 43, 35, 25, 16, 33, 51,
  436. /* 30 */ 52, 101, 56, 21, 47, 2, 19, 46, 52, 44,
  437. /* 40 */ 3, 20, 53, 49, 24, 34, 23, 6, 40, 45,
  438. /* 50 */ 1, 4, 13, 54, 11, 48, 5, 14, 32, 8,
  439. );
  440. static public $yy_lookahead = array(
  441. /* 0 */ 14, 15, 16, 17, 18, 19, 20, 21, 41, 42,
  442. /* 10 */ 43, 13, 44, 33, 46, 47, 11, 12, 42, 43,
  443. /* 20 */ 37, 38, 2, 23, 24, 4, 5, 30, 8, 7,
  444. /* 30 */ 8, 28, 29, 36, 35, 22, 4, 13, 8, 8,
  445. /* 40 */ 1, 6, 26, 3, 8, 3, 13, 3, 7, 45,
  446. /* 50 */ 40, 6, 34, 39, 31, 48, 10, 32, 9, 25,
  447. );
  448. const YY_SHIFT_USE_DFLT = -15;
  449. const YY_SHIFT_MAX = 27;
  450. static public $yy_shift_ofst = array(
  451. /* 0 */ 39, 45, -15, 21, -15, -15, -14, 0, 33, 44,
  452. /* 10 */ 34, 46, 49, 16, 13, 5, 20, 22, -2, 41,
  453. /* 20 */ 32, 42, 40, 36, 24, 35, 30, 31,
  454. );
  455. const YY_REDUCE_USE_DFLT = -34;
  456. const YY_REDUCE_MAX = 14;
  457. static public $yy_reduce_ofst = array(
  458. /* 0 */ 3, -33, -32, -3, -24, -17, 10, 4, 7, 14,
  459. /* 10 */ 18, 25, 23, -1, -20,
  460. );
  461. static public $yyExpectedTokens = array(
  462. /* 0 */ array(1, ),
  463. /* 1 */ array(6, ),
  464. /* 2 */ array(),
  465. /* 3 */ array(4, 5, ),
  466. /* 4 */ array(),
  467. /* 5 */ array(),
  468. /* 6 */ array(14, 15, 16, 17, 18, 19, 20, 21, ),
  469. /* 7 */ array(23, 24, ),
  470. /* 8 */ array(13, ),
  471. /* 9 */ array(3, ),
  472. /* 10 */ array(25, ),
  473. /* 11 */ array(10, ),
  474. /* 12 */ array(9, ),
  475. /* 13 */ array(26, ),
  476. /* 14 */ array(22, ),
  477. /* 15 */ array(11, 12, ),
  478. /* 16 */ array(2, 8, ),
  479. /* 17 */ array(7, 8, ),
  480. /* 18 */ array(13, ),
  481. /* 19 */ array(7, ),
  482. /* 20 */ array(4, ),
  483. /* 21 */ array(3, ),
  484. /* 22 */ array(3, ),
  485. /* 23 */ array(8, ),
  486. /* 24 */ array(13, ),
  487. /* 25 */ array(6, ),
  488. /* 26 */ array(8, ),
  489. /* 27 */ array(8, ),
  490. /* 28 */ array(),
  491. /* 29 */ array(),
  492. /* 30 */ array(),
  493. /* 31 */ array(),
  494. /* 32 */ array(),
  495. /* 33 */ array(),
  496. /* 34 */ array(),
  497. /* 35 */ array(),
  498. /* 36 */ array(),
  499. /* 37 */ array(),
  500. /* 38 */ array(),
  501. /* 39 */ array(),
  502. /* 40 */ array(),
  503. /* 41 */ array(),
  504. /* 42 */ array(),
  505. /* 43 */ array(),
  506. /* 44 */ array(),
  507. /* 45 */ array(),
  508. /* 46 */ array(),
  509. /* 47 */ array(),
  510. /* 48 */ array(),
  511. /* 49 */ array(),
  512. /* 50 */ array(),
  513. /* 51 */ array(),
  514. /* 52 */ array(),
  515. /* 53 */ array(),
  516. /* 54 */ array(),
  517. /* 55 */ array(),
  518. /* 56 */ array(),
  519. /* 57 */ array(),
  520. );
  521. static public $yy_default = array(
  522. /* 0 */ 100, 77, 91, 64, 77, 71, 100, 94, 100, 100,
  523. /* 10 */ 96, 67, 100, 100, 87, 66, 100, 100, 100, 100,
  524. /* 20 */ 100, 100, 100, 97, 100, 100, 74, 88, 80, 79,
  525. /* 30 */ 81, 82, 65, 63, 60, 61, 78, 85, 83, 84,
  526. /* 40 */ 62, 72, 92, 93, 90, 86, 98, 59, 95, 89,
  527. /* 50 */ 69, 73, 76, 99, 68, 70, 58, 75,
  528. );
  529. /* The next thing included is series of defines which control
  530. ** various aspects of the generated parser.
  531. ** self::YYNOCODE is a number which corresponds
  532. ** to no legal terminal or nonterminal number. This
  533. ** number is used to fill in empty slots of the hash
  534. ** table.
  535. ** self::YYFALLBACK If defined, this indicates that one or more tokens
  536. ** have fall-back values which should be used if the
  537. ** original value of the token will not parse.
  538. ** self::YYSTACKDEPTH is the maximum depth of the parser's stack.
  539. ** self::YYNSTATE the combined number of states.
  540. ** self::YYNRULE the number of rules in the grammar
  541. ** self::YYERRORSYMBOL is the code number of the error symbol. If not
  542. ** defined, then do no error processing.
  543. */
  544. const YYNOCODE = 50;
  545. const YYSTACKDEPTH = 100;
  546. const YYNSTATE = 58;
  547. const YYNRULE = 42;
  548. const YYERRORSYMBOL = 27;
  549. const YYERRSYMDT = 'yy0';
  550. const YYFALLBACK = 0;
  551. /** The next table maps tokens into fallback tokens. If a construct
  552. * like the following:
  553. *
  554. * %fallback ID X Y Z.
  555. *
  556. * appears in the grammer, then ID becomes a fallback token for X, Y,
  557. * and Z. Whenever one of the tokens X, Y, or Z is input to the parser
  558. * but it does not parse, the type of the token is changed to ID and
  559. * the parse is retried before an error is thrown.
  560. */
  561. static public $yyFallback = array(
  562. );
  563. /**
  564. * Turn parser tracing on by giving a stream to which to write the trace
  565. * and a prompt to preface each trace message. Tracing is turned off
  566. * by making either argument NULL
  567. *
  568. * Inputs:
  569. *
  570. * - A stream resource to which trace output should be written.
  571. * If NULL, then tracing is turned off.
  572. * - A prefix string written at the beginning of every
  573. * line of trace output. If NULL, then tracing is
  574. * turned off.
  575. *
  576. * Outputs:
  577. *
  578. * - None.
  579. * @param resource
  580. * @param string
  581. */
  582. static function Trace($TraceFILE, $zTracePrompt)
  583. {
  584. if (!$TraceFILE) {
  585. $zTracePrompt = 0;
  586. } elseif (!$zTracePrompt) {
  587. $TraceFILE = 0;
  588. }
  589. self::$yyTraceFILE = $TraceFILE;
  590. self::$yyTracePrompt = $zTracePrompt;
  591. }
  592. /**
  593. * Output debug information to output (php://output stream)
  594. */
  595. static function PrintTrace()
  596. {
  597. self::$yyTraceFILE = fopen('php://output', 'w');
  598. self::$yyTracePrompt = '';
  599. }
  600. /**
  601. * @var resource|0
  602. */
  603. static public $yyTraceFILE;
  604. /**
  605. * String to prepend to debug output
  606. * @var string|0
  607. */
  608. static public $yyTracePrompt;
  609. /**
  610. * @var int
  611. */
  612. public $yyidx; /* Index of top element in stack */
  613. /**
  614. * @var int
  615. */
  616. public $yyerrcnt; /* Shifts left before out of the error */
  617. /**
  618. * @var array
  619. */
  620. public $yystack = array(); /* The parser's stack */
  621. /**
  622. * For tracing shifts, the names of all terminals and nonterminals
  623. * are required. The following table supplies these names
  624. * @var array
  625. */
  626. static public $yyTokenName = array(
  627. '$', 'SELECT', 'FRM', 'COLUMNNAME',
  628. 'ASTERISK', 'COUNT', 'PARENOPEN', 'PARENCLOSE',
  629. 'COMMA', 'TABLENAME', 'WHERE', 'LOGICAL_AND',
  630. 'LOGICAL_OR', 'VALUE', 'EQ', 'LT',
  631. 'GT', 'LTE', 'GTE', 'NE',
  632. 'IN', 'LIKE', 'ORDERBY', 'ASC',
  633. 'DESC', 'LIMIT', 'SEMICOLON', 'error',
  634. 'sql', 'select_statement', 'selectcol_list', 'table_list',
  635. 'where_condition', 'order_clause', 'limit_clause', 'end_stmt',
  636. 'selectcolumn_exp', 'condition', 'expr_set', 'expr',
  637. 'logical_term', 'valuelist', 'valueref', 'value_exp',
  638. 'column_group', 'clause', 'column_list', 'column_exp',
  639. 'limit_set',
  640. );
  641. /**
  642. * For tracing reduce actions, the names of all rules are required.
  643. * @var array
  644. */
  645. static public $yyRuleName = array(
  646. /* 0 */ "sql ::= select_statement",
  647. /* 1 */ "select_statement ::= SELECT selectcol_list FRM table_list where_condition order_clause limit_clause end_stmt",
  648. /* 2 */ "selectcol_list ::= selectcolumn_exp COLUMNNAME",
  649. /* 3 */ "selectcol_list ::= ASTERISK",
  650. /* 4 */ "selectcol_list ::= COUNT PARENOPEN ASTERISK PARENCLOSE",
  651. /* 5 */ "selectcolumn_exp ::= selectcol_list COMMA",
  652. /* 6 */ "selectcolumn_exp ::=",
  653. /* 7 */ "table_list ::= TABLENAME",
  654. /* 8 */ "where_condition ::= WHERE condition",
  655. /* 9 */ "where_condition ::=",
  656. /* 10 */ "condition ::= expr_set expr",
  657. /* 11 */ "expr_set ::= condition LOGICAL_AND",
  658. /* 12 */ "expr_set ::= condition LOGICAL_OR",
  659. /* 13 */ "expr_set ::=",
  660. /* 14 */ "expr ::= COLUMNNAME logical_term valuelist",
  661. /* 15 */ "valuelist ::= PARENOPEN valueref PARENCLOSE",
  662. /* 16 */ "valuelist ::= valueref",
  663. /* 17 */ "valueref ::= value_exp VALUE",
  664. /* 18 */ "value_exp ::= valueref COMMA",
  665. /* 19 */ "value_exp ::=",
  666. /* 20 */ "logical_term ::= EQ",
  667. /* 21 */ "logical_term ::= LT",
  668. /* 22 */ "logical_term ::= GT",
  669. /* 23 */ "logical_term ::= LTE",
  670. /* 24 */ "logical_term ::= GTE",
  671. /* 25 */ "logical_term ::= NE",
  672. /* 26 */ "logical_term ::= IN",
  673. /* 27 */ "logical_term ::= LIKE",
  674. /* 28 */ "order_clause ::= ORDERBY column_group clause",
  675. /* 29 */ "order_clause ::=",
  676. /* 30 */ "column_group ::= column_list",
  677. /* 31 */ "column_list ::= column_exp COLUMNNAME",
  678. /* 32 */ "column_exp ::= column_list COMMA",
  679. /* 33 */ "column_exp ::=",
  680. /* 34 */ "clause ::= ASC",
  681. /* 35 */ "clause ::= DESC",
  682. /* 36 */ "clause ::=",
  683. /* 37 */ "limit_clause ::= LIMIT limit_set",
  684. /* 38 */ "limit_clause ::=",
  685. /* 39 */ "limit_set ::= VALUE",
  686. /* 40 */ "limit_set ::= VALUE COMMA VALUE",
  687. /* 41 */ "end_stmt ::= SEMICOLON",
  688. );
  689. /**
  690. * This function returns the symbolic name associated with a token
  691. * value.
  692. * @param int
  693. * @return string
  694. */
  695. function tokenName($tokenType)
  696. {
  697. if ($tokenType === 0) {
  698. return 'End of Input';
  699. }
  700. if ($tokenType > 0 && $tokenType < count(self::$yyTokenName)) {
  701. return self::$yyTokenName[$tokenType];
  702. } else {
  703. return "Unknown";
  704. }
  705. }
  706. /**
  707. * The following function deletes the value associated with a
  708. * symbol. The symbol can be either a terminal or nonterminal.
  709. * @param int the symbol code
  710. * @param mixed the symbol's value
  711. */
  712. static function yy_destructor($yymajor, $yypminor)
  713. {
  714. switch ($yymajor) {
  715. /* Here is inserted the actions which take place when a
  716. ** terminal or non-terminal is destroyed. This can happen
  717. ** when the symbol is popped from the stack during a
  718. ** reduce or during error processing or when a parser is
  719. ** being destroyed before it is finished parsing.
  720. **
  721. ** Note: during a reduce, the only symbols destroyed are those
  722. ** which appear on the RHS of the rule, but which are not used
  723. ** inside the C code.
  724. */
  725. default: break; /* If no destructor action specified: do nothing */
  726. }
  727. }
  728. /**
  729. * Pop the parser's stack once.
  730. *
  731. * If there is a destructor routine associated with the token which
  732. * is popped from the stack, then call it.
  733. *
  734. * Return the major token number for the symbol popped.
  735. * @param VTQL_ParseryyParser
  736. * @return int
  737. */
  738. function yy_pop_parser_stack()
  739. {
  740. if (!count($this->yystack)) {
  741. return;
  742. }
  743. $yytos = array_pop($this->yystack);
  744. if (self::$yyTraceFILE && $this->yyidx >= 0) {
  745. fwrite(self::$yyTraceFILE,
  746. self::$yyTracePrompt . 'Popping ' . self::$yyTokenName[$yytos->major] .
  747. "\n");
  748. }
  749. $yymajor = $yytos->major;
  750. self::yy_destructor($yymajor, $yytos->minor);
  751. $this->yyidx--;
  752. return $yymajor;
  753. }
  754. /**
  755. * Deallocate and destroy a parser. Destructors are all called for
  756. * all stack elements before shutting the parser down.
  757. */
  758. function __destruct()
  759. {
  760. while ($this->yyidx >= 0) {
  761. $this->yy_pop_parser_stack();
  762. }
  763. if (is_resource(self::$yyTraceFILE)) {
  764. fclose(self::$yyTraceFILE);
  765. }
  766. }
  767. /**
  768. * Based on the current state and parser stack, get a list of all
  769. * possible lookahead tokens
  770. * @param int
  771. * @return array
  772. */
  773. function yy_get_expected_tokens($token)
  774. {
  775. $state = $this->yystack[$this->yyidx]->stateno;
  776. $expected = self::$yyExpectedTokens[$state];
  777. if (in_array($token, self::$yyExpectedTokens[$state], true)) {
  778. return $expected;
  779. }
  780. $stack = $this->yystack;
  781. $yyidx = $this->yyidx;
  782. do {
  783. $yyact = $this->yy_find_shift_action($token);
  784. if ($yyact >= self::YYNSTATE && $yyact < self::YYNSTATE + self::YYNRULE) {
  785. // reduce action
  786. $done = 0;
  787. do {
  788. if ($done++ == 100) {
  789. $this->yyidx = $yyidx;
  790. $this->yystack = $stack;
  791. // too much recursion prevents proper detection
  792. // so give up
  793. return array_unique($expected);
  794. }
  795. $yyruleno = $yyact - self::YYNSTATE;
  796. $this->yyidx -= self::$yyRuleInfo[$yyruleno]['rhs'];
  797. $nextstate = $this->yy_find_reduce_action(
  798. $this->yystack[$this->yyidx]->stateno,
  799. self::$yyRuleInfo[$yyruleno]['lhs']);
  800. if (isset(self::$yyExpectedTokens[$nextstate])) {
  801. $expected += self::$yyExpectedTokens[$nextstate];
  802. if (in_array($token,
  803. self::$yyExpectedTokens[$nextstate], true)) {
  804. $this->yyidx = $yyidx;
  805. $this->yystack = $stack;
  806. return array_unique($expected);
  807. }
  808. }
  809. if ($nextstate < self::YYNSTATE) {
  810. // we need to shift a non-terminal
  811. $this->yyidx++;
  812. $x = new VTQL_ParseryyStackEntry;
  813. $x->stateno = $nextstate;
  814. $x->major = self::$yyRuleInfo[$yyruleno]['lhs'];
  815. $this->yystack[$this->yyidx] = $x;
  816. continue 2;
  817. } elseif ($nextstate == self::YYNSTATE + self::YYNRULE + 1) {
  818. $this->yyidx = $yyidx;
  819. $this->yystack = $stack;
  820. // the last token was just ignored, we can't accept
  821. // by ignoring input, this is in essence ignoring a
  822. // syntax error!
  823. return array_unique($expected);
  824. } elseif ($nextstate === self::YY_NO_ACTION) {
  825. $this->yyidx = $yyidx;
  826. $this->yystack = $stack;
  827. // input accepted, but not shifted (I guess)
  828. return $expected;
  829. } else {
  830. $yyact = $nextstate;
  831. }
  832. } while (true);
  833. }
  834. break;
  835. } while (true);
  836. return array_unique($expected);
  837. }
  838. /**
  839. * Based on the parser state and current parser stack, determine whether
  840. * the lookahead token is possible.
  841. *
  842. * The parser will convert the token value to an error token if not. This
  843. * catches some unusual edge cases where the parser would fail.
  844. * @param int
  845. * @return bool
  846. */
  847. function yy_is_expected_token($token)
  848. {
  849. if ($token === 0) {
  850. return true; // 0 is not part of this
  851. }
  852. $state = $this->yystack[$this->yyidx]->stateno;
  853. if (in_array($token, self::$yyExpectedTokens[$state], true)) {
  854. return true;
  855. }
  856. $stack = $this->yystack;
  857. $yyidx = $this->yyidx;
  858. do {
  859. $yyact = $this->yy_find_shift_action($token);
  860. if ($yyact >= self::YYNSTATE && $yyact < self::YYNSTATE + self::YYNRULE) {
  861. // reduce action
  862. $done = 0;
  863. do {
  864. if ($done++ == 100) {
  865. $this->yyidx = $yyidx;
  866. $this->yystack = $stack;
  867. // too much recursion prevents proper detection
  868. // so give up
  869. return true;
  870. }
  871. $yyruleno = $yyact - self::YYNSTATE;
  872. $this->yyidx -= self::$yyRuleInfo[$yyruleno]['rhs'];
  873. $nextstate = $this->yy_find_reduce_action(
  874. $this->yystack[$this->yyidx]->stateno,
  875. self::$yyRuleInfo[$yyruleno]['lhs']);
  876. if (isset(self::$yyExpectedTokens[$nextstate]) &&
  877. in_array($token, self::$yyExpectedTokens[$nextstate], true)) {
  878. $this->yyidx = $yyidx;
  879. $this->yystack = $stack;
  880. return true;
  881. }
  882. if ($nextstate < self::YYNSTATE) {
  883. // we need to shift a non-terminal
  884. $this->yyidx++;
  885. $x = new VTQL_ParseryyStackEntry;
  886. $x->stateno = $nextstate;
  887. $x->major = self::$yyRuleInfo[$yyruleno]['lhs'];
  888. $this->yystack[$this->yyidx] = $x;
  889. continue 2;
  890. } elseif ($nextstate == self::YYNSTATE + self::YYNRULE + 1) {
  891. $this->yyidx = $yyidx;
  892. $this->yystack = $stack;
  893. if (!$token) {
  894. // end of input: this is valid
  895. return true;
  896. }
  897. // the last token was just ignored, we can't accept
  898. // by ignoring input, this is in essence ignoring a
  899. // syntax error!
  900. return false;
  901. } elseif ($nextstate === self::YY_NO_ACTION) {
  902. $this->yyidx = $yyidx;
  903. $this->yystack = $stack;
  904. // input accepted, but not shifted (I guess)
  905. return true;
  906. } else {
  907. $yyact = $nextstate;
  908. }
  909. } while (true);
  910. }
  911. break;
  912. } while (true);
  913. return true;
  914. }
  915. /**
  916. * Find the appropriate action for a parser given the terminal
  917. * look-ahead token iLookAhead.
  918. *
  919. * If the look-ahead token is YYNOCODE, then check to see if the action is
  920. * independent of the look-ahead. If it is, return the action, otherwise
  921. * return YY_NO_ACTION.
  922. * @param int The look-ahead token
  923. */
  924. function yy_find_shift_action($iLookAhead)
  925. {
  926. $stateno = $this->yystack[$this->yyidx]->stateno;
  927. /* if ($this->yyidx < 0) return self::YY_NO_ACTION; */
  928. if (!isset(self::$yy_shift_ofst[$stateno])) {
  929. // no shift actions
  930. return self::$yy_default[$stateno];
  931. }
  932. $i = self::$yy_shift_ofst[$stateno];
  933. if ($i === self::YY_SHIFT_USE_DFLT) {
  934. return self::$yy_default[$stateno];
  935. }
  936. if ($iLookAhead == self::YYNOCODE) {
  937. return self::YY_NO_ACTION;
  938. }
  939. $i += $iLookAhead;
  940. if ($i < 0 || $i >= self::YY_SZ_ACTTAB ||
  941. self::$yy_lookahead[$i] != $iLookAhead) {
  942. if (count(self::$yyFallback) && $iLookAhead < count(self::$yyFallback)
  943. && ($iFallback = self::$yyFallback[$iLookAhead]) != 0) {
  944. if (self::$yyTraceFILE) {
  945. fwrite(self::$yyTraceFILE, self::$yyTracePrompt . "FALLBACK " .
  946. self::$yyTokenName[$iLookAhead] . " => " .
  947. self::$yyTokenName[$iFallback] . "\n");
  948. }
  949. return $this->yy_find_shift_action($iFallback);
  950. }
  951. return self::$yy_default[$stateno];
  952. } else {
  953. return self::$yy_action[$i];
  954. }
  955. }
  956. /**
  957. * Find the appropriate action for a parser given the non-terminal
  958. * look-ahead token $iLookAhead.
  959. *
  960. * If the look-ahead token is self::YYNOCODE, then check to see if the action is
  961. * independent of the look-ahead. If it is, return the action, otherwise
  962. * return self::YY_NO_ACTION.
  963. * @param int Current state number
  964. * @param int The look-ahead token
  965. */
  966. function yy_find_reduce_action($stateno, $iLookAhead)
  967. {
  968. /* $stateno = $this->yystack[$this->yyidx]->stateno; */
  969. if (!isset(self::$yy_reduce_ofst[$stateno])) {
  970. return self::$yy_default[$stateno];
  971. }
  972. $i = self::$yy_reduce_ofst[$stateno];
  973. if ($i == self::YY_REDUCE_USE_DFLT) {
  974. return self::$yy_default[$stateno];
  975. }
  976. if ($iLookAhead == self::YYNOCODE) {
  977. return self::YY_NO_ACTION;
  978. }
  979. $i += $iLookAhead;
  980. if ($i < 0 || $i >= self::YY_SZ_ACTTAB ||
  981. self::$yy_lookahead[$i] != $iLookAhead) {
  982. return self::$yy_default[$stateno];
  983. } else {
  984. return self::$yy_action[$i];
  985. }
  986. }
  987. /**
  988. * Perform a shift action.
  989. * @param int The new state to shift in
  990. * @param int The major token to shift in
  991. * @param mixed the minor token to shift in
  992. */
  993. function yy_shift($yyNewState, $yyMajor, $yypMinor)
  994. {
  995. $this->yyidx++;
  996. if ($this->yyidx >= self::YYSTACKDEPTH) {
  997. $this->yyidx--;
  998. if (self::$yyTraceFILE) {
  999. fprintf(self::$yyTraceFILE, "%sStack Overflow!\n", self::$yyTracePrompt);
  1000. }
  1001. while ($this->yyidx >= 0) {
  1002. $this->yy_pop_parser_stack();
  1003. }
  1004. /* Here code is inserted which will execute if the parser
  1005. ** stack ever overflows */
  1006. #line 462 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1007. throw new WebServiceException(WebServiceErrorCode::$QUERYSYNTAX, "Parser stack overflow");
  1008. #line 1046 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1009. return;
  1010. }
  1011. $yytos = new VTQL_ParseryyStackEntry;
  1012. $yytos->stateno = $yyNewState;
  1013. $yytos->major = $yyMajor;
  1014. $yytos->minor = $yypMinor;
  1015. array_push($this->yystack, $yytos);
  1016. if (self::$yyTraceFILE && $this->yyidx > 0) {
  1017. fprintf(self::$yyTraceFILE, "%sShift %d\n", self::$yyTracePrompt,
  1018. $yyNewState);
  1019. fprintf(self::$yyTraceFILE, "%sStack:", self::$yyTracePrompt);
  1020. for($i = 1; $i <= $this->yyidx; $i++) {
  1021. fprintf(self::$yyTraceFILE, " %s",
  1022. self::$yyTokenName[$this->yystack[$i]->major]);
  1023. }
  1024. fwrite(self::$yyTraceFILE,"\n");
  1025. }
  1026. }
  1027. /**
  1028. * The following table contains information about every rule that
  1029. * is used during the reduce.
  1030. *
  1031. * <pre>
  1032. * array(
  1033. * array(
  1034. * int $lhs; Symbol on the left-hand side of the rule
  1035. * int $nrhs; Number of right-hand side symbols in the rule
  1036. * ),...
  1037. * );
  1038. * </pre>
  1039. */
  1040. static public $yyRuleInfo = array(
  1041. array( 'lhs' => 28, 'rhs' => 1 ),
  1042. array( 'lhs' => 29, 'rhs' => 8 ),
  1043. array( 'lhs' => 30, 'rhs' => 2 ),
  1044. array( 'lhs' => 30, 'rhs' => 1 ),
  1045. array( 'lhs' => 30, 'rhs' => 4 ),
  1046. array( 'lhs' => 36, 'rhs' => 2 ),
  1047. array( 'lhs' => 36, 'rhs' => 0 ),
  1048. array( 'lhs' => 31, 'rhs' => 1 ),
  1049. array( 'lhs' => 32, 'rhs' => 2 ),
  1050. array( 'lhs' => 32, 'rhs' => 0 ),
  1051. array( 'lhs' => 37, 'rhs' => 2 ),
  1052. array( 'lhs' => 38, 'rhs' => 2 ),
  1053. array( 'lhs' => 38, 'rhs' => 2 ),
  1054. array( 'lhs' => 38, 'rhs' => 0 ),
  1055. array( 'lhs' => 39, 'rhs' => 3 ),
  1056. array( 'lhs' => 41, 'rhs' => 3 ),
  1057. array( 'lhs' => 41, 'rhs' => 1 ),
  1058. array( 'lhs' => 42, 'rhs' => 2 ),
  1059. array( 'lhs' => 43, 'rhs' => 2 ),
  1060. array( 'lhs' => 43, 'rhs' => 0 ),
  1061. array( 'lhs' => 40, 'rhs' => 1 ),
  1062. array( 'lhs' => 40, 'rhs' => 1 ),
  1063. array( 'lhs' => 40, 'rhs' => 1 ),
  1064. array( 'lhs' => 40, 'rhs' => 1 ),
  1065. array( 'lhs' => 40, 'rhs' => 1 ),
  1066. array( 'lhs' => 40, 'rhs' => 1 ),
  1067. array( 'lhs' => 40, 'rhs' => 1 ),
  1068. array( 'lhs' => 40, 'rhs' => 1 ),
  1069. array( 'lhs' => 33, 'rhs' => 3 ),
  1070. array( 'lhs' => 33, 'rhs' => 0 ),
  1071. array( 'lhs' => 44, 'rhs' => 1 ),
  1072. array( 'lhs' => 46, 'rhs' => 2 ),
  1073. array( 'lhs' => 47, 'rhs' => 2 ),
  1074. array( 'lhs' => 47, 'rhs' => 0 ),
  1075. array( 'lhs' => 45, 'rhs' => 1 ),
  1076. array( 'lhs' => 45, 'rhs' => 1 ),
  1077. array( 'lhs' => 45, 'rhs' => 0 ),
  1078. array( 'lhs' => 34, 'rhs' => 2 ),
  1079. array( 'lhs' => 34, 'rhs' => 0 ),
  1080. array( 'lhs' => 48, 'rhs' => 1 ),
  1081. array( 'lhs' => 48, 'rhs' => 3 ),
  1082. array( 'lhs' => 35, 'rhs' => 1 ),
  1083. );
  1084. /**
  1085. * The following table contains a mapping of reduce action to method name
  1086. * that handles the reduction.
  1087. *
  1088. * If a rule is not set, it has no handler.
  1089. */
  1090. static public $yyReduceMap = array(
  1091. 1 => 1,
  1092. 2 => 2,
  1093. 3 => 3,
  1094. 4 => 4,
  1095. 7 => 7,
  1096. 11 => 11,
  1097. 12 => 11,
  1098. 14 => 14,
  1099. 17 => 17,
  1100. 20 => 20,
  1101. 21 => 21,
  1102. 22 => 22,
  1103. 23 => 23,
  1104. 24 => 24,
  1105. 25 => 25,
  1106. 26 => 26,
  1107. 27 => 27,
  1108. 31 => 31,
  1109. 34 => 34,
  1110. 35 => 35,
  1111. 39 => 39,
  1112. 40 => 40,
  1113. 41 => 41,
  1114. );
  1115. /* Beginning here are the reduction cases. A typical example
  1116. ** follows:
  1117. ** #line <lineno> <grammarfile>
  1118. ** function yy_r0($yymsp){ ... } // User supplied code
  1119. ** #line <lineno> <thisfile>
  1120. */
  1121. #line 5 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1122. function yy_r1(){
  1123. if($this->yystack[$this->yyidx + -7]->minor){
  1124. $this->out['select'] = $this->yystack[$this->yyidx + -7]->minor;
  1125. }
  1126. if($this->yystack[$this->yyidx + -5]->minor){
  1127. $this->out['from'] = $this->yystack[$this->yyidx + -5]->minor ;
  1128. }
  1129. if(SEMI){
  1130. $this->out['semi_colon'] = SEMI;
  1131. }
  1132. if($this->out['select']){
  1133. $this->buildSelectStmt($this->out);
  1134. }
  1135. }
  1136. #line 1176 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1137. #line 19 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1138. function yy_r2(){
  1139. $this->out['column_list'][] = $this->yystack[$this->yyidx + 0]->minor;
  1140. }
  1141. #line 1181 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1142. #line 22 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1143. function yy_r3(){
  1144. $this->out['column_list'][] = $this->yystack[$this->yyidx + 0]->minor;
  1145. }
  1146. #line 1186 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1147. #line 25 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1148. function yy_r4(){
  1149. $this->out['column_list'][] = 'count(*)';
  1150. }
  1151. #line 1191 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1152. #line 30 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1153. function yy_r7(){
  1154. if(!in_array("*", $this->out["column_list"]) && !in_array("count(*)", array_map(strtolower, $this->out["column_list"]))){
  1155. if(!in_array("id",$this->out["column_list"])){
  1156. $this->out["column_list"][] = "id";
  1157. }
  1158. }
  1159. $moduleName = $this->yystack[$this->yyidx + 0]->minor;
  1160. if(!$moduleName){
  1161. $this->syntax_error = true;
  1162. throw new WebServiceException(WebServiceErrorCode::$QUERYSYNTAX, "There is an syntax error in query");
  1163. }
  1164. global $adb;
  1165. $handler = vtws_getModuleHandlerFromName($moduleName,$this->user);
  1166. $objectMeta = $handler->getMeta();
  1167. $this->out['moduleName'] = $moduleName;
  1168. $this->out['tableName'] = implode(',',$objectMeta->getEntityTableList());
  1169. }
  1170. #line 1210 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1171. #line 50 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1172. function yy_r11(){
  1173. $this->out['where_condition']['operators'][] = $this->yystack[$this->yyidx + 0]->minor;
  1174. }
  1175. #line 1215 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1176. #line 57 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1177. function yy_r14(){
  1178. $this->out['columnDone']=true;
  1179. $this->out['where_condition']['column_names'][] = $this->yystack[$this->yyidx + -2]->minor;
  1180. if(strcmp($this->yystack[$this->yyidx + -2]->minor, 'id')===0){
  1181. $prev = $this->out['where_condition']['column_values'][sizeof($this->out['where_condition']['column_values'])-1];
  1182. if(is_array($prev)){
  1183. $new = array();
  1184. foreach($prev as $ind=>$val){
  1185. $val = trim($val,'\'"');
  1186. $value = vtws_getIdComponents($val);
  1187. $new[] = $value[1];
  1188. }
  1189. $this->out['where_condition']['column_values'][sizeof($this->out['where_condition']['column_values'])-1] = $new;
  1190. }else{
  1191. $prev = trim($prev,'\'"');
  1192. $value = vtws_getIdComponents($prev);
  1193. if(strcasecmp($this->out['where_condition']['column_operators'][sizeof($this->out['where_condition']['column_operators'])-1],'like')===0){
  1194. $value[1] = "'".$value[1]."'";
  1195. }
  1196. $this->out['where_condition']['column_values'][sizeof($this->out['where_condition']['column_values'])-1] = $value[1];
  1197. }
  1198. }
  1199. }
  1200. #line 1240 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1201. #line 82 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1202. function yy_r17(){
  1203. $length = sizeof($this->out['where_condition']['column_values']);
  1204. $pos = $length - 1;
  1205. if($pos < 0){
  1206. $pos = 0;
  1207. }
  1208. if(strcasecmp($this->out['where_condition']['column_operators'][$pos],"in")===0 &&
  1209. !empty($this->out['where_condition']['column_values'][$pos]) && !$this->out['columnDone']){
  1210. if(!is_array($this->out['where_condition']['column_values'][$pos])){
  1211. $prev = $this->out['where_condition']['column_values'][$pos];
  1212. $this->out['where_condition']['column_values'][$pos] = array();
  1213. $this->out['where_condition']['column_values'][$pos][] = $prev;
  1214. }
  1215. $this->out['where_condition']['column_values'][$pos][] = $this->yystack[$this->yyidx + 0]->minor;
  1216. }else{
  1217. $this->out['columnDone'] = false;
  1218. $this->out['where_condition']['column_values'][] = $this->yystack[$this->yyidx + 0]->minor;
  1219. }
  1220. }
  1221. #line 1261 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1222. #line 103 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1223. function yy_r20(){
  1224. $this->out['where_condition']['column_operators'][] = '=';
  1225. }
  1226. #line 1266 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1227. #line 106 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1228. function yy_r21(){
  1229. $this->out['where_condition']['column_operators'][] = '<';
  1230. }
  1231. #line 1271 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1232. #line 109 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1233. function yy_r22(){
  1234. $this->out['where_condition']['column_operators'][] = '>';
  1235. }
  1236. #line 1276 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1237. #line 112 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1238. function yy_r23(){
  1239. $this->out['where_condition']['column_operators'][] = '<=';
  1240. }
  1241. #line 1281 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1242. #line 115 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1243. function yy_r24(){
  1244. $this->out['where_condition']['column_operators'][] = '>=';
  1245. }
  1246. #line 1286 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1247. #line 118 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1248. function yy_r25(){
  1249. $this->out['where_condition']['column_operators'][] = '!=';
  1250. }
  1251. #line 1291 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1252. #line 121 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1253. function yy_r26(){
  1254. $this->out['where_condition']['column_operators'][] = 'IN';
  1255. }
  1256. #line 1296 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1257. #line 124 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1258. function yy_r27(){
  1259. $this->out['where_condition']['column_operators'][] = 'LIKE';
  1260. }
  1261. #line 1301 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1262. #line 130 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1263. function yy_r31(){
  1264. $this->out['orderby'][] = $this->yystack[$this->yyidx + 0]->minor;
  1265. }
  1266. #line 1306 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1267. #line 135 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1268. function yy_r34(){
  1269. $this->out['sortOrder'] = 'ASC';
  1270. }
  1271. #line 1311 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1272. #line 138 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1273. function yy_r35(){
  1274. $this->out['sortOrder'] = 'DESC';
  1275. }
  1276. #line 1316 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1277. #line 144 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1278. function yy_r39(){
  1279. $this->out['limit'][] = $this->yystack[$this->yyidx + 0]->minor;
  1280. }
  1281. #line 1321 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1282. #line 147 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1283. function yy_r40(){
  1284. $this->out['limit'][] = $this->yystack[$this->yyidx + -2]->minor;
  1285. $this->out['limit'][] = $this->yystack[$this->yyidx + 0]->minor;
  1286. }
  1287. #line 1327 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
  1288. #line 151 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
  1289. function yy_r41(){
  1290. global $adb;
  1291. if(!$this->out['meta']){
  1292. $module = $this->out['moduleName'];
  1293. $handler = vtws_getModuleHandlerFromName($module,$this->user);
  1294. $objectMeta = $handler->getMeta();
  1295. $this->out['meta'] = $objectMeta;
  1296. $meta = $this->out['meta'];
  1297. $fieldcol = $meta->getFieldColumnMapping();
  1298. $columns = array();
  1299. if(in_array('*', $this->out['column_list'])){
  1300. $columns = array_values($fieldcol);
  1301. }elseif( !in_array('count(*)', array_map(strtolower, $this->out['column_list']))){
  1302. foreach($this->out['column_list'] as $ind=>$field){
  1303. $columns[] = $fieldcol[$field];
  1304. }
  1305. }
  1306. if($this->out['where_condition']){
  1307. foreach($this->out['where_condition']['colum…

Large files files are truncated, but you can click here to view the full file