diff options
Diffstat (limited to 'shared/classes/0sql_row_obj.php')
-rw-r--r-- | shared/classes/0sql_row_obj.php | 118 |
1 files changed, 61 insertions, 57 deletions
diff --git a/shared/classes/0sql_row_obj.php b/shared/classes/0sql_row_obj.php index 30fe479..d625071 100644 --- a/shared/classes/0sql_row_obj.php +++ b/shared/classes/0sql_row_obj.php @@ -564,78 +564,82 @@ class sql_col { if (isset($array['refers_to'])) $this->refers_to=$array['refers_to']; } elseif (is_string($array)) { - $line=$array; - list($type, $line)=explode(' ', $line, 2); + $type=$array; + if (strpos($type, ' ')) + list($type, $opts)=explode(' ', $type, 2); if (strpos($type, '(') !== false) { + // TODO differentiate between things with length and ENUM $length=substr($type, strpos($type, '(')); $type=substr($type, 0, strlen($type)-strlen($length)); $length=substr($length, 1, strlen($length)-2); $this->length=$length; } $this->type=strtoupper($type); - $opts=explode(' ', $line); - for ($i=0; $i<count($opts); $i++) { - $word=$opts[$i]; - switch (strtoupper($word)) { - case 'NOT': - if (strtoupper($opts[++$i]) == 'NULL') { - $this->not_null=true; - } else { - $i--; // We assume it's NULL and backtrack otherwise - } - break; - case 'NULL': - $this->not_null=false; - break; - case 'UNSIGNED': - $this->unsigned=true; - break; - case 'AUTO_INCREMENT': - $this->auto_increment=true; - break; - case 'CHARACTER': - if (strtoupper($opts[$i+1]) == 'SET') { - $word.=' '.$opts[++$i]; - } else { - break; - } - case 'COLLATE': - case 'DEFAULT': - case 'COMMENT': - $string=$opts[++$i]; - if ($string == "''") { - $string=''; - } elseif (substr($string, 0, 1) == "'") { - // An odd number of ' at the end means an unquoted ' - // The $i<count($opts) is just to avoid infinite loops that shouldn't happen - //echo strtoupper($word).' '.$string; - while ( ( strlen($string) - strlen(rtrim($string, '\'')) ) % 2 == 0 && $i<count($opts)) { - $string.=' '.$opts[++$i]; - } - $string=str_replace("''", "'", $string); - $string=substr($string, 1, strlen($string)-2); - } elseif (strtoupper($string) == 'NULL') { - $string=null; - } + if (isset($opts)) { + $opts=explode(' ', $opts); + for ($i=0; $i<count($opts); $i++) { + $word=$opts[$i]; switch (strtoupper($word)) { - case 'CHARACTER SET': - $this->charset=$string; + case 'NOT': + if (strtoupper($opts[++$i]) == 'NULL') { + $this->not_null=true; + } else { + $i--; // We assume it's NULL and backtrack otherwise + } break; - case 'COLLATE': - $this->collate=$string; + case 'NULL': + $this->not_null=false; break; - case 'DEFAULT': - $this->default=$string; + case 'UNSIGNED': + $this->unsigned=true; break; - case 'COMMENT': - if (preg_match('/^refers to(?::| |: )([a-zA-Z0-9_$]+\.[a-zA-Z0-9_$]+)$/', $string, $match)) { - $this->refers_to=$match[1]; + case 'AUTO_INCREMENT': + $this->auto_increment=true; + break; + case 'CHARACTER': + if (strtoupper($opts[$i+1]) == 'SET') { + $word.=' '.$opts[++$i]; } else { - $this->comment=$string; + break; + } + case 'COLLATE': + case 'DEFAULT': + case 'COMMENT': + $string=$opts[++$i]; + if ($string == "''") { + $string=''; + } elseif (substr($string, 0, 1) == "'") { + // An odd number of ' at the end means an unquoted ' + // The $i<count($opts) is just to avoid infinite loops that shouldn't happen + //echo strtoupper($word).' '.$string; + while ( ( strlen($string) - strlen(rtrim($string, '\'')) ) % 2 == 0 && $i<count($opts)) { + $string.=' '.$opts[++$i]; + } + $string=str_replace("''", "'", $string); + $string=substr($string, 1, strlen($string)-2); + } elseif (strtoupper($string) == 'NULL') { + $string=null; + } + switch (strtoupper($word)) { + case 'CHARACTER SET': + $this->charset=$string; + break; + case 'COLLATE': + $this->collate=$string; + break; + case 'DEFAULT': + $this->default=$string; + break; + case 'COMMENT': + if (preg_match('/^refers to(?::| |: )([a-zA-Z0-9_$]+\.[a-zA-Z0-9_$]+)$/', $string, $match)) { + $this->refers_to=$match[1]; + } else { + $this->comment=$string; + } + break; } break; } - break; } } } |