Exemple #1
0
 function to_sql()
 {
     $sql = "";
     if ($dir != "IN") {
         $sql .= "{$dir} ";
     }
     $sql .= Modyllic_SQL::quote_ident($name) . " ";
     $sql .= $type->to_sql();
     return $sql;
 }
Exemple #2
0
 function begin_sql_func($name)
 {
     $this->add(Modyllic_SQL::quote_ident($name) . '(');
     return $this;
 }
Exemple #3
0
 protected function _format_replace($matches)
 {
     switch ($matches[1]) {
         case 'id':
             $result = Modyllic_SQL::quote_ident(array_shift($this->_format_args));
             break;
         case 'str':
             $result = Modyllic_SQL::quote_str(array_shift($this->_format_args));
             break;
         case 'lit':
             $result = array_shift($this->_format_args);
             break;
         default:
             $result = '%' . $matches[1];
     }
     return $result;
     return $this;
 }
Exemple #4
0
 /**
  * @returns Modyllic_Schema
  */
 static function load(PDO $dbh, $dbname, $schema)
 {
     $dbh->exec("USE information_schema");
     $dbschema = self::selectrow($dbh, "SELECT SCHEMA_NAME, DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM SCHEMATA WHERE SCHEMA_NAME=?", array($dbname));
     if (!$dbschema) {
         throw new Exception("Database {$dbname} does not exist");
     }
     $parser = new Modyllic_Parser();
     if ($schema->name_is_default) {
         $schema->set_name($dbschema['SCHEMA_NAME']);
         $schema->charset = $dbschema['DEFAULT_CHARACTER_SET_NAME'];
         $schema->collate = $dbschema['DEFAULT_COLLATION_NAME'];
     }
     $table_sth = self::query($dbh, "SELECT TABLE_NAME FROM TABLES WHERE TABLE_SCHEMA=? AND TABLE_TYPE='BASE TABLE'", array($dbname));
     $tables = array();
     while ($table_row = $table_sth->fetch(PDO::FETCH_ASSOC)) {
         Modyllic_Status::$source_count++;
         $table = self::selectrow($dbh, "SHOW CREATE TABLE " . Modyllic_SQL::quote_ident($dbname) . "." . Modyllic_SQL::quote_ident($table_row['TABLE_NAME']));
         $tables[$table_row['TABLE_NAME']] = $table['Create Table'];
     }
     $routine_sth = self::query($dbh, "SELECT ROUTINE_TYPE, ROUTINE_NAME FROM ROUTINES WHERE ROUTINE_SCHEMA=?", array($dbname));
     $routines = array();
     while ($routine = $routine_sth->fetch(PDO::FETCH_ASSOC)) {
         Modyllic_Status::$source_count++;
         if ($routine['ROUTINE_TYPE'] == 'PROCEDURE') {
             $proc = self::selectrow($dbh, "SHOW CREATE PROCEDURE " . Modyllic_SQL::quote_ident($dbname) . "." . Modyllic_SQL::quote_ident($routine['ROUTINE_NAME']));
             $routines[$routine['ROUTINE_NAME']] = $proc['Create Procedure'];
         } else {
             if ($routine['ROUTINE_TYPE'] == 'FUNCTION') {
                 $func = self::selectrow($dbh, "SHOW CREATE FUNCTION " . Modyllic_SQL::quote_ident($dbname) . "." . Modyllic_SQL::quote_ident($routine['ROUTINE_NAME']));
                 $routines[$routine['ROUTINE_NAME']] = $func['Create Function'];
             } else {
                 throw new Exception("Unknown routine type " . $routine['ROUTINE_TYPE'] . " for " . $routine['ROUTINE_NAME']);
             }
         }
     }
     foreach ($tables as $table_name => $table_sql) {
         Modyllic_Status::$source_name = "{$dbname}." . $table_name;
         $parser->partial($schema, $table_sql, "{$dbname}.{$table_name}");
         Modyllic_Status::$source_index++;
     }
     ksort($schema->tables);
     foreach ($routines as $routine_name => $routine_sql) {
         Modyllic_Status::$source_name = "{$dbname}.{$routine_name}";
         $parser->partial($schema, $routine_sql, "{$dbname}.{$routine_name}");
         Modyllic_Status::$source_index++;
     }
     ksort($schema->routines);
     if (isset($schema->tables['SQLMETA'])) {
         $table = $schema->tables['SQLMETA'];
         $meta_sth = self::query($dbh, "SELECT kind,which,value FROM " . Modyllic_SQL::quote_ident($dbname) . ".SQLMETA");
         while ($meta = $meta_sth->fetch(PDO::FETCH_ASSOC)) {
             $table->add_row($meta);
         }
     }
     $schema->load_sqlmeta();
     // Look for data to load...
     foreach ($schema->tables as $name => $table) {
         if ($table->static) {
             $data_sth = self::query($dbh, "SELECT * FROM " . Modyllic_SQL::quote_ident($dbname) . "." . Modyllic_SQL::quote_ident($name));
             while ($data_row = $data_sth->fetch(PDO::FETCH_ASSOC)) {
                 $table->add_row($data_row);
             }
         }
     }
 }