Skip to content

Commit c2c1a7b

Browse files
committed
bugfixed column inline collation and character set definitions
1 parent 145e303 commit c2c1a7b

1 file changed

Lines changed: 19 additions & 45 deletions

File tree

src/PHPSQLParser/processors/ColumnDefinitionProcessor.php

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ public function process($tokens) {
219219
continue 2;
220220

221221
case 'ENUM':
222-
case 'SET':
223222
$currCategory = 'MULTIPLE_PARAM_PARENTHESIS';
224223
$prevCategory = 'TEXT';
225224
$expr[] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim, 'sub_tree' => false);
@@ -240,41 +239,24 @@ public function process($tokens) {
240239
continue 2;
241240

242241
case 'CHARACTER':
243-
if ($prevCategory === 'TEXT') {
244-
$parsed = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim);
245-
$expr[] = array('expr_type' => ExpressionType::CHARSET, 'base_expr' => substr($base_expr, 0, -1),
246-
'sub_tree' => $parsed);
247-
$base_expr = $token;
248-
$currCategory = 'CHARSET';
249-
continue 2;
250-
}
251-
// else ?
252-
break;
242+
$currCategory = 'CHARSET';
243+
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
244+
continue 2;
253245

254246
case 'SET':
255-
case 'CHARSET':
256-
if ($currCategory === 'CHARSET') {
257-
// TODO: is it necessary to set special properties like the name or collation?
258-
$parsed = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
259-
$last = array_pop($expr);
260-
$last['sub_tree'][] = $parsed;
261-
$expr[] = $last;
262-
continue 2;
263-
}
264-
// else ?
265-
break;
247+
if ($currCategory == 'CHARSET') {
248+
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
249+
} else {
250+
$currCategory = 'MULTIPLE_PARAM_PARENTHESIS';
251+
$prevCategory = 'TEXT';
252+
$expr[] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim, 'sub_tree' => false);
253+
}
254+
continue 2;
266255

267256
case 'COLLATE':
268-
if ($prevCategory === 'TEXT') {
269-
$parsed = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
270-
$expr[] = array('expr_type' => ExpressionType::COLLATE, 'base_expr' => substr($base_expr, 0, -1),
271-
'sub_tree' => $parsed);
272-
$base_expr = $token;
273-
$currCategory = 'COLLATION';
274-
continue 2;
275-
}
276-
// else ?
277-
break;
257+
$currCategory = $upper;
258+
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
259+
continue 2;
278260

279261
case 'NOT':
280262
case 'NULL':
@@ -364,25 +346,17 @@ public function process($tokens) {
364346

365347
case 'COLLATE':
366348
// this is the collation name
367-
$parsed = array('expr_type' => ExpressionType::CONSTANT, 'base_expr' => $trim);
368-
$last = array_pop($expr);
369-
$last['sub_tree'][] = $parsed;
370-
$t = $base_expr;
371-
$base_expr = $last['base_expr'] . $base_expr;
372-
$last['base_expr'] = $t;
349+
$options['sub_tree'][] = array('expr_type' => ExpressionType::COLLATE, 'base_expr' => $trim);
350+
$options['collate'] = $trim;
373351
$currCategory = $prevCategory;
374352
break;
375353

376354
case 'CHARSET':
377355
// this is the character set name
378-
$parsed = array('expr_type' => ExpressionType::CONSTANT, 'base_expr' => $trim);
379-
$last = array_pop($expr);
380-
$last['sub_tree'][] = $parsed;
381-
$t = $base_expr;
382-
$base_expr = $last['base_expr'] . $base_expr;
383-
$last['base_expr'] = $t;
356+
$options['sub_tree'][] = array('expr_type' => ExpressionType::CHARSET, 'base_expr' => $trim);
357+
$options['charset'] = $trim;
384358
$currCategory = $prevCategory;
385-
break;
359+
break;
386360

387361
case 'SINGLE_PARAM_PARENTHESIS':
388362
$parsed = $this->removeParenthesisFromStart($trim);

0 commit comments

Comments
 (0)