File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed
Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,13 @@ class Sql2Scanner
4040 */
4141 protected $ tokens ;
4242
43+ /**
44+ * Delimiters between tokens
45+ *
46+ * @var array
47+ */
48+ protected $ delimiters ;
49+
4350 /**
4451 * Parsing position in the SQL string
4552 *
@@ -75,6 +82,16 @@ public function lookupNextToken($offset = 0)
7582 return '' ;
7683 }
7784
85+ /**
86+ * Get the delimiter that separated the two previous tokens
87+ *
88+ * @return string
89+ */
90+ public function getPreviousDelimiter ()
91+ {
92+ return $ this ->delimiters [$ this ->curpos - 1 ];
93+ }
94+
7895 /**
7996 * Get the next token and remove it from the queue.
8097 * Return an empty string when there are no more tokens.
@@ -156,6 +173,15 @@ protected function scan($sql2)
156173 $ token = strtok (" \n\t" );
157174 }
158175
176+ $ regexp = '' ;
177+ foreach ($ tokens as $ token ) {
178+ $ regexp [] = preg_quote ($ token , '/ ' );
179+ }
180+
181+ $ regexp = '/^ ' .implode ('([ \t\n]+) ' , $ regexp ).'$/ ' ;
182+ preg_match ($ regexp , $ sql2 , $ this ->delimiters );
183+ $ this ->delimiters [0 ] = '' ;
184+
159185 return $ tokens ;
160186 }
161187
Original file line number Diff line number Diff line change @@ -731,12 +731,8 @@ protected function parseLiteral()
731731 if ('' === $ nextToken ) {
732732 break ;
733733 }
734- // TODO: the scanner kills spaces, tabs and newlines
735- // So adding a space here is just a hack for the most common token separator we can expect.
736- // The proper way would require that the scanner tracks the token separators so that we
737- // could fetch the separator between the last fetched token and the token before that token
738- // so that we can append it instead of this hardcoded single space, ie. ' '
739- $ token .= ' ' .$ nextToken ;
734+ $ token .= $ this ->scanner ->getPreviousDelimiter ();
735+ $ token .= $ nextToken ;
740736 }
741737
742738 if (substr ($ token , -1 ) !== $ quoteString ) {
You can’t perform that action at this time.
0 commit comments