Example #1
0
 /**
  * @param string $sqlScript
  *
  * @return Table[]
  */
 public function parseTables($sqlScript)
 {
     preg_match_all(RegExpPattern::tables(), $sqlScript, $matches);
     $tables = [];
     for ($i = 0; $i < count($matches[0]); $i++) {
         $name = $matches['tableName'][$i];
         $ifNotExists = $matches['ifNotExists'][$i];
         $definition = $matches['tableDefinition'][$i];
         $creationScript = $matches['creationScript'][$i];
         $engine = $matches['engine'][$i];
         $autoIncrement = $matches['autoIncrement'][$i];
         $defaultCharset = $matches['defaultCharset'][$i];
         $comment = $matches['comment'][$i];
         $table = new Table($name);
         $table->setDefinition(trim($definition));
         $table->setCreationScript(trim($creationScript) . ';');
         if ($ifNotExists) {
             $table->setIfNotExists(true);
         }
         if ($engine) {
             $table->setEngine($engine);
         }
         if ($autoIncrement) {
             $table->setAutoIncrement((int) $autoIncrement);
         }
         if ($defaultCharset) {
             $table->setDefaultCharset($defaultCharset);
         }
         if ($comment) {
             $table->setComment(str_replace('\'\'', '\'', $comment));
         }
         $tables[$name] = $table;
     }
     return $tables;
 }