示例#1
0
 /**
  * {@inheritdoc}
  */
 protected function visitString(StringNode $node)
 {
     if (count($this->primary) == 0) {
         return new ConditionBuilder('false');
     }
     $condition = new ConditionBuilder();
     foreach ($this->primary as $column) {
         $condition->or('%m.%c LIKE %s', $this->model, $column, '%' . ConditionBuilder::escapeLike($node->value) . '%');
     }
     return $condition;
 }
示例#2
0
文件: SqlTable.php 项目: jivoo/jivoo
 /**
  * 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);
 }
示例#3
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;
 }
示例#4
0
文件: ModelBase.php 项目: jivoo/jivoo
 /**
  * Find row number of a record in the result set of a selection. The selection
  * must be ordered.
  * @param ReadSelectionBuilder $selection A read selection.
  * @param Record $record A record.
  * @throws InvalidSelectionException If the selection is not ordered.
  * @return int Row number.
  */
 public function rowNumberSelection(ReadSelectionBuilder $selection, Record $record)
 {
     if (empty($selection->orderBy)) {
         throw new InvalidSelectionException(tr('Can\'t find row number in selection without ordering'));
     }
     $condition = new ConditionBuilder();
     foreach ($selection->orderBy as $orderBy) {
         $column = $orderBy['column'];
         $type = $this->getType($column)->placeholder;
         if ($orderBy['descending']) {
             $condition->and($column . ' > ' . $type, $record->{$column});
         } else {
             $condition->and($column . ' < ' . $type, $record->{$column});
         }
     }
     return $selection->and($condition)->count() + 1;
 }