Skip to content

Commit c2a258a

Browse files
committed
silence all php warnings/notices
1 parent 9084e47 commit c2a258a

1 file changed

Lines changed: 49 additions & 37 deletions

File tree

lib_sql_parser.php

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function walk($tokens, $sql, $source_map){
207207
$table['sql'] = $stmt['sql'];
208208
}
209209

210-
if ($GLOBALS['_find_single_table'] && count($tables)) return array(
210+
if (isset($GLOBALS['_find_single_table']) && $GLOBALS['_find_single_table'] && count($tables)) return array(
211211
'tables' => $tables,
212212
);
213213
}
@@ -606,24 +606,24 @@ function parse_field($tokens){
606606

607607

608608
# [NOT NULL | NULL]
609-
if (StrToUpper($tokens[0]) == 'NOT NULL'){
609+
if (count($tokens) >= 1 && StrToUpper($tokens[0]) == 'NOT NULL'){
610610
$f['null'] = false;
611611
array_shift($tokens);
612612
}
613-
if (StrToUpper($tokens[0]) == 'NULL'){
613+
if (count($tokens) >= 1 && StrToUpper($tokens[0]) == 'NULL'){
614614
$f['null'] = true;
615615
array_shift($tokens);
616616
}
617617

618618
# [DEFAULT default_value]
619-
if (StrToUpper($tokens[0]) == 'DEFAULT'){
619+
if (count($tokens) >= 1 && StrToUpper($tokens[0]) == 'DEFAULT'){
620620
$f['default'] = $this->decode_value($tokens[1]);
621621
array_shift($tokens);
622622
array_shift($tokens);
623623
}
624624

625625
# [AUTO_INCREMENT]
626-
if (StrToUpper($tokens[0]) == 'AUTO_INCREMENT'){
626+
if (count($tokens) >= 1 && StrToUpper($tokens[0]) == 'AUTO_INCREMENT'){
627627
$f['auto_increment'] = true;
628628
array_shift($tokens);
629629
}
@@ -672,19 +672,19 @@ function parse_table_props(&$tokens){
672672
case 'DATA DIRECTORY':
673673
case 'INDEX DIRECTORY':
674674
$prop = StrToUpper(array_shift($tokens));
675-
if ($tokens[0] == '=') array_shift($tokens);
675+
if (isset($tokens[0]) && $tokens[0] == '=') array_shift($tokens);
676676
$props[$prop] = array_shift($tokens);
677-
if ($tokens[0] == ',') array_shift($tokens);
677+
if (isset($tokens[0]) && $tokens[0] == ',') array_shift($tokens);
678678
break;
679679

680680
case 'CHARACTER SET':
681681
case 'DEFAULT COLLATE':
682682
case 'DEFAULT CHARACTER SET':
683683
case 'DEFAULT CHARSET':
684684
$prop = $alt_names[StrToUpper(array_shift($tokens))];
685-
if ($tokens[0] == '=') array_shift($tokens);
685+
if (isset($tokens[0]) && $tokens[0] == '=') array_shift($tokens);
686686
$props[$prop] = array_shift($tokens);
687-
if ($tokens[0] == ',') array_shift($tokens);
687+
if (isset($tokens[0]) && $tokens[0] == ',') array_shift($tokens);
688688
break;
689689

690690
default:
@@ -752,7 +752,7 @@ function _extract_tokens($sql, &$source_map){
752752
while ($i < $len){
753753
$token = substr($sql, $source_map[$i][0], $source_map[$i][1]);
754754
$tokenUpper = StrToUpper($token);
755-
if (is_array($maps[$tokenUpper])){
755+
if (isset($maps[$tokenUpper]) && is_array($maps[$tokenUpper])){
756756
$found = false;
757757
foreach ($maps[$tokenUpper] as $list){
758758
$fail = false;
@@ -778,7 +778,7 @@ function _extract_tokens($sql, &$source_map){
778778
}
779779
if ($found) continue;
780780
}
781-
if ($smap[$tokenUpper]){
781+
if (isset($smap[$tokenUpper])){
782782
$out[] = $tokenUpper;
783783
$out_map[]= $source_map[$i];
784784
$i++;
@@ -871,53 +871,65 @@ function parse_index_options(&$tokens, &$index){
871871
#
872872

873873
function parse_field_length(&$tokens, &$f){
874-
if ($tokens[0] == '(' && $tokens[2] == ')'){
875-
$f['length'] = $tokens[1];
876-
array_shift($tokens);
877-
array_shift($tokens);
874+
if (count($tokens) >= 3){
875+
if ($tokens[0] == '(' && $tokens[2] == ')'){
876+
$f['length'] = $tokens[1];
877+
array_shift($tokens);
878+
array_shift($tokens);
878879
array_shift($tokens);
879880
}
881+
}
880882
}
881883

882884
function parse_field_length_deciamsl(&$tokens, &$f){
883-
if ($tokens[0] == '(' && $tokens[2] == ',' && $tokens[4] == ')'){
884-
$f['length'] = $tokens[1];
885-
$f['decimals'] = $tokens[3];
886-
array_shift($tokens);
887-
array_shift($tokens);
888-
array_shift($tokens);
889-
array_shift($tokens);
890-
array_shift($tokens);
885+
if (count($tokens) >= 5){
886+
if ($tokens[0] == '(' && $tokens[2] == ',' && $tokens[4] == ')'){
887+
$f['length'] = $tokens[1];
888+
$f['decimals'] = $tokens[3];
889+
array_shift($tokens);
890+
array_shift($tokens);
891+
array_shift($tokens);
892+
array_shift($tokens);
893+
array_shift($tokens);
894+
}
891895
}
892896
}
893897

894898
function parse_field_unsigned(&$tokens, &$f){
895-
if (StrToUpper($tokens[0]) == 'UNSIGNED'){
896-
$f['unsigned'] = true;
897-
array_shift($tokens);
899+
if (count($tokens) >= 1){
900+
if (StrToUpper($tokens[0]) == 'UNSIGNED'){
901+
$f['unsigned'] = true;
902+
array_shift($tokens);
903+
}
898904
}
899905
}
900906

901907
function parse_field_zerofill(&$tokens, &$f){
902-
if (StrToUpper($tokens[0]) == 'ZEROFILL'){
903-
$f['zerofill'] = true;
904-
array_shift($tokens);
908+
if (count($tokens) >= 1){
909+
if (StrToUpper($tokens[0]) == 'ZEROFILL'){
910+
$f['zerofill'] = true;
911+
array_shift($tokens);
912+
}
905913
}
906914
}
907915

908916
function parse_field_charset(&$tokens, &$f){
909-
if (StrToUpper($tokens[0]) == 'CHARACTER SET'){
910-
$f['character_set'] = $tokens[1];
911-
array_shift($tokens);
912-
array_shift($tokens);
917+
if (count($tokens) >= 1){
918+
if (StrToUpper($tokens[0]) == 'CHARACTER SET'){
919+
$f['character_set'] = $tokens[1];
920+
array_shift($tokens);
921+
array_shift($tokens);
922+
}
913923
}
914924
}
915925

916926
function parse_field_collate(&$tokens, &$f){
917-
if (StrToUpper($tokens[0]) == 'COLLATE'){
918-
$f['collation'] = $tokens[1];
919-
array_shift($tokens);
920-
array_shift($tokens);
927+
if (count($tokens) >= 1){
928+
if (StrToUpper($tokens[0]) == 'COLLATE'){
929+
$f['collation'] = $tokens[1];
930+
array_shift($tokens);
931+
array_shift($tokens);
932+
}
921933
}
922934
}
923935

0 commit comments

Comments
 (0)