Exemple #1
0
 /**
  * Tries to convert columns to MySQL specific types like:
  * datetime, ENUM etc. This method is called automatically for you and
  * works completely in the background. You can however if you like trigger
  * this method by invoking it directly.
  * @param string $table
  * @param string $column
  * @param string $columnType
  * @param string $value
  */
 public function MySQLSpecificColumns($table, $column, $columnType, $value)
 {
     //$this->adapter->getDatabase()->setDebugMode(1);
     $table = $this->adapter->escape($table);
     $column = $this->adapter->escape($column);
     //Is column already datetime?
     if ($columnType != "datetime") {
         $pattern = "/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?\$/";
         if (preg_match($pattern, $value)) {
             //Ok, value is datetime, can we convert the column to support this?
             $cnt = (int) $this->adapter->getCell("select count(*) as n from {$table} where\n\t\t\t\t\t{$column} regexp '[0-9]{4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]'\n\t\t\t\t");
             $total = (int) $this->adapter->getCell("SELECT count(*) FROM " . $this->writer->noKW($table));
             //Is it safe to convert: ie are all values compatible?
             if ($total === $cnt) {
                 //yes
                 $this->adapter->exec("ALTER TABLE " . $this->writer->noKW($table) . " change " . $this->writer->noKW($column) . " " . $this->writer->noKW($column) . " datetime ");
             }
         }
     }
 }
Exemple #2
0
 /**
  * Tries to convert columns to MySQL specific types like:
  * datetime, ENUM etc. This method is called automatically for you and
  * works completely in the background. You can however if you like trigger
  * this method by invoking it directly.
  * @param string $table
  * @param string $column
  * @param string $columnType
  * @param string $value
  */
 public function MySQLSpecificColumns($table, $column, $columnType, $value)
 {
     $table = $this->adapter->escape($table);
     $column = $this->adapter->escape($column);
     if ($columnType != "datetime") {
         $pattern = "/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?\$/";
         if (preg_match($pattern, $value)) {
             $cnt = (int) $this->adapter->getCell("select count(*) as n from {$table} where\n\t\t\t\t\t\t  {$column} regexp '[0-9]{4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]'\n\t\t\t\t\t\t  ");
             $total = (int) $this->adapter->getCell("SELECT count(*) FROM " . $this->writer->noKW($table));
             if ($total === $cnt) {
                 $this->adapter->exec("ALTER TABLE " . $this->writer->noKW($table) . " change " . $this->writer->noKW($column) . " " . $this->writer->noKW($column) . " datetime ");
             }
         }
     }
 }