See also: Factory::sql()
Inheritance: extends Piwik\Updater\Migration\Db
Example #1
0
 public function __toString()
 {
     $sql = parent::__toString();
     foreach ($this->bind as $value) {
         if (!is_int($value) && !is_float($value)) {
             $value = "'" . addcslashes($value, "\n\r\\'\"") . "'";
         }
         $sql = substr_replace($sql, $value, $pos = strpos($sql, '?'), $len = 1);
     }
     return $sql;
 }
Example #2
0
 /**
  * Constructor.
  * @param Db\Settings $dbSettings
  * @param string $table Prefixed table name
  * @param string|string[] $columnNames array(columnName => columnValue)
  * @param string|string[] $primaryKey one or multiple columns that define the primary key
  */
 public function __construct(Db\Settings $dbSettings, $table, $columnNames, $primaryKey)
 {
     $columns = array();
     foreach ($columnNames as $column => $type) {
         $columns[] = sprintf('`%s` %s', $column, $type);
     }
     if (!empty($primaryKey)) {
         $columns[] = sprintf('PRIMARY KEY ( `%s` )', implode('`, `', $primaryKey));
     }
     $sql = sprintf('CREATE TABLE `%s` (%s) ENGINE=%s DEFAULT CHARSET=utf8', $table, implode(', ', $columns), $dbSettings->getEngine());
     parent::__construct($sql, static::ERROR_CODE_TABLE_EXISTS);
 }
Example #3
0
 /**
  * @param string $table Prefixed table name
  * @param string $indexName name of the index
  */
 public function __construct($table, $indexName)
 {
     $sql = sprintf('ALTER TABLE `%s` DROP INDEX `%s`', $table, $indexName);
     parent::__construct($sql, array(static::ERROR_CODE_COLUMN_NOT_EXISTS));
 }
Example #4
0
 /**
  * @param string $table Prefixed table name
  */
 public function __construct($table)
 {
     $sql = sprintf('DROP TABLE IF EXISTS `%s`', $table);
     parent::__construct($sql, array(static::ERROR_CODE_TABLE_NOT_EXISTS, static::ERROR_CODE_UNKNOWN_TABLE));
 }