[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 global $where_col,$orderby,$in_started,$count; 3 $where_col = false; 4 $orderby = false; 5 $in_started = false; 6 $count = false; 7 function incrementN($lexer, $count){ 8 $i = 0; 9 for(;$i<$count;$i++){ 10 incState($lexer); 11 } 12 } 13 function incState($lexer){ 14 $lexer->current_state++; 15 if($lexer->current_state === sizeof($lexer->mandatory_states)){ 16 $lexer->mandatory = false; 17 } 18 } 19 function handleselect($lexer, $val){ 20 if($lexer->mandatory){ 21 if(strcasecmp($val, $lexer->mandatory_states[$lexer->current_state])===0){ 22 incState($lexer); 23 return VTQL_Parser::SELECT; 24 } 25 } 26 } 27 function handlecolumn_list($lexer, $val){ 28 global $count; 29 if($lexer->mandatory){ 30 if(!(strcasecmp($val, $lexer->mandatory_states[2])===0)){ 31 if(strcmp($val, "*")===0){ 32 if(!$count){ 33 incrementN($lexer, 1); 34 } 35 return VTQL_Parser::ASTERISK; 36 }else if((strcmp($val, "(")===0)){ 37 return VTQL_Parser::PARENOPEN; 38 }else if(strcmp($val, ")")===0){ 39 return VTQL_Parser::PARENCLOSE; 40 }else if((strcasecmp($val, "count")===0)){ 41 $count = true; 42 return VTQL_Parser::COUNT; 43 }else if(strcmp($val, ",")===0){ 44 return VTQL_Parser::COMMA; 45 }else{ 46 return VTQL_Parser::COLUMNNAME; 47 } 48 }else{ 49 incrementN($lexer, 2); 50 return VTQL_Parser::FRM; 51 } 52 } 53 } 54 function handlefrom($lexer, $val){ 55 if((strcasecmp($val, $lexer->mandatory_states[$lexer->current_state])===0)){ 56 incState($lexer); 57 return VTQL_Parser::FRM; 58 } 59 } 60 function handletable($lexer, $val){ 61 if($lexer->mandatory){ 62 $lexer->current_state =0; 63 $lexer->mandatory = false; 64 if(!(strcasecmp($val, $lexer->optional_states[$lexer->current_state])===0)){ 65 return VTQL_Parser::TABLENAME; 66 } 67 } 68 } 69 function handlewhere($lexer, $val){ 70 global $where_col,$in_started; 71 $val = trim($val); 72 if((strcmp($val, "=")===0)){ 73 return VTQL_Parser::EQ; 74 }else if((strcasecmp($val, $lexer->optional_states[$lexer->current_state])===0)){ 75 return VTQL_Parser::WHERE; 76 }else if((strcmp($val, "<")===0)){ 77 return VTQL_Parser::LT; 78 }else if((strcmp($val, "<=")===0)){ 79 return VTQL_Parser::LTE; 80 }else if((strcmp($val, ">=")===0)){ 81 return VTQL_Parser::GTE; 82 }else if((strcmp($val, "!=")===0)){ 83 return VTQL_Parser::NE; 84 }else if((strcmp($val, ">")===0)){ 85 return VTQL_Parser::GT; 86 }else if((strcmp($val, "(")===0)){ 87 return VTQL_Parser::PARENOPEN; 88 }else if((strcmp($val, ")")===0)){ 89 if($in_started){ 90 $in_started = false; 91 $where_col = false; 92 } 93 return VTQL_Parser::PARENCLOSE; 94 }else if((strcasecmp($val, "and")===0)){ 95 return VTQL_Parser::LOGICAL_AND; 96 }else if((strcasecmp($val, "or")===0)){ 97 return VTQL_Parser::LOGICAL_OR; 98 }else if(!$where_col){ 99 $where_col = true; 100 return VTQL_Parser::COLUMNNAME; 101 }else if((strcasecmp($val, "in")===0)){ 102 $in_started = true; 103 return VTQL_Parser::IN; 104 }else if(strcmp($val, ",")===0){ 105 return VTQL_Parser::COMMA; 106 }else if(strcasecmp($val, "like")===0){ 107 return VTQL_Parser::LIKE; 108 }else if($where_col){ 109 if(!$in_started){ 110 $where_col = false; 111 } 112 return VTQL_Parser::VALUE; 113 } 114 } 115 function handleorderby($lexer, $val){ 116 global $orderby; 117 if(!$orderby){ 118 $orderby = true; 119 return VTQL_Parser::ORDERBY; 120 } 121 if(strcmp($val, ",")===0){ 122 return VTQL_Parser::COMMA; 123 }else if(strcasecmp($val, "asc")===0){ 124 return VTQL_Parser::ASC; 125 }else if(strcasecmp($val, "desc")===0){ 126 return VTQL_Parser::DESC; 127 }else{ 128 return VTQL_Parser::COLUMNNAME; 129 } 130 } 131 function handlelimit($lexer, $val){ 132 if((strcasecmp($val, "limit")===0)){ 133 return VTQL_Parser::LIMIT; 134 }else if((strcmp($val, "(")===0)){ 135 return VTQL_Parser::PARENOPEN; 136 }else if((strcmp($val, ")")===0)){ 137 return VTQL_Parser::PARENCLOSE; 138 }else if(strcmp($val, ",")===0){ 139 return VTQL_Parser::COMMA; 140 }else{ 141 return VTQL_Parser::VALUE; 142 } 143 } 144 function handleend($lexer, $val){ 145 return VTQL_Parser::SEMICOLON; 146 } 147 class VTQL_Lexer{ 148 private $index; 149 public $token; 150 public $value; 151 public $linenum; 152 public $state = 1; 153 private $data; 154 public $mandatory_states = array('select','column_list','from','table'); 155 public $optional_states = array('where', 'orderby', 'limit'); 156 public $mandatory ; 157 public $current_state ; 158 function __construct($data) 159 { 160 $this->index = 0; 161 $this->data = $data; 162 $this->linenum = 1; 163 $this->mandatory = true; 164 $this->current_state = 0; 165 } 166 function __toString(){ 167 return $this->token.""; 168 } 169 /*!lex2php 170 %input $this->data 171 %counter $this->index 172 %token $this->token 173 %value $this->value 174 %line $this->linenum 175 query = /(\w+|'(?:[^']|'')+'|\(|\)|(\+|-)?\d+|,|\*|(?!<|>)=|<(?!=)|>(?!=)|<=|>=|!=|;)/ 176 whitespace = /[ \t\r\n]+/ 177 */ 178 /*!lex2php 179 %statename INITR 180 query { 181 global $orderby; 182 //echo "<br> ql state: ",$this->current_state," ",$this->value,"<br>"; 183 if($this->mandatory){ 184 //echo "<br> ql state: ",$this->current_state," ",$this->value,"<br>"; 185 $handler = 'handle'.$this->mandatory_states[$this->current_state]; 186 $this->token = $handler($this, $this->value); 187 }else{ 188 $str = $this->value; 189 if(strcmp($this->value, ";")===0){ 190 $this->token = handleend($this, $this->value); 191 return; 192 } 193 if(strcasecmp($this->value, "order")===0){ 194 $orderby = true; 195 return false; 196 }else if(strcasecmp($this->value, "by") ===0 && $orderby ===true){ 197 $orderby = false; 198 $this->current_state = 1; 199 } 200 $index = array_search(strtolower($str), $this->optional_states, true); 201 if($index !== false){ 202 $this->current_state = $index; 203 } 204 $handler = 'handle'.$this->optional_states[$this->current_state]; 205 $this->token = $handler($this, $this->value); 206 }//$this->yypushstate($this->value); 207 } 208 whitespace { 209 return false; 210 } 211 */ 212 } 213 214 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |