Exemple #1
0
 /**
  * Convert a schema type to an SQLite type
  * @param DataType $type Type.
  * @param bool $isPrimaryKey True if primary key.
  * @return string SQLite type.
  */
 public function fromDataType(DataType $type, $isPrimaryKey = false)
 {
     $primaryKey = '';
     if ($isPrimaryKey) {
         $primaryKey = ' PRIMARY KEY';
     }
     switch ($type->type) {
         case DataType::INTEGER:
             if ($type->size == DataType::BIG) {
                 $column = 'INTEGER(8)';
             } else {
                 if ($type->size == DataType::SMALL) {
                     $column = 'INTEGER(2)';
                 } else {
                     if ($type->size == DataType::TINY) {
                         $column = 'INTEGER(1)';
                     } else {
                         $column = 'INTEGER';
                     }
                 }
             }
             if ($isPrimaryKey and $type->autoIncrement) {
                 $primaryKey .= ' AUTOINCREMENT';
             }
             break;
         case DataType::FLOAT:
             $column = 'REAL';
             break;
         case DataType::STRING:
             $column = 'TEXT(' . $type->length . ')';
             break;
         case DataType::BOOLEAN:
             $column = 'INTEGER(1)';
             break;
         case DataType::BINARY:
             $column = 'BLOB';
             break;
         case DataType::DATE:
             $column = 'INTEGER';
             break;
         case DataType::DATETIME:
             $column = 'INTEGER';
             break;
         case DataType::TEXT:
         case DataType::ENUM:
         case DataType::OBJECT:
         default:
             $column = 'TEXT';
             break;
     }
     $column .= $primaryKey;
     if ($type->notNull) {
         $column .= ' NOT';
     }
     $column .= ' NULL';
     if (isset($type->default)) {
         $column .= ConditionBuilder::interpolate(' DEFAULT %_', array($type, $type->default), $this->db);
     }
     return $column;
 }
Exemple #2
0
 /**
  * Interpolate variables. See {@see Condition::interpolate}.
  * @param string $query Query.
  * @param array $vars Variables.
  * @return string Interpolated query.
  */
 protected function escapeQuery($query, $vars = array())
 {
     if (!is_array($vars)) {
         $vars = func_get_args();
         array_shift($vars);
     }
     return ConditionBuilder::interpolate($query, $vars, $this->owner);
 }