Example #1
0
	protected function topString()
	{
		if ($this->limit !== NULL && $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME) === 'dblib') {
			return " TOP ($this->limit)"; //! offset is not supported
		}
		return '';
	}
Example #2
0
 public function __construct($tableName, Connection $connection, IReflection $reflection)
 {
     $this->tableName = $tableName;
     $this->databaseReflection = $reflection;
     $this->driver = $connection->getSupplementalDriver();
     $this->driverName = $connection->getAttribute(\PDO::ATTR_DRIVER_NAME);
     $this->delimitedTable = $this->tryDelimite($tableName);
 }
 protected function buildTopClause()
 {
     if ($this->limit !== NULL && $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME) === 'dblib') {
         return " TOP ({$this->limit})";
         //! offset is not supported
     }
     return '';
 }
 public function addWhere($condition, $parameters = array())
 {
     $args = func_get_args();
     $hash = md5(json_encode($args));
     if (isset($this->conditions[$hash])) {
         return false;
     }
     $this->conditions[$hash] = $condition;
     $condition = $this->removeExtraTables($condition);
     $condition = $this->tryDelimite($condition);
     if (count($args) !== 2 || strpbrk($condition, '?:')) {
         // where('column < ? OR column > ?', array(1, 2))
         if (count($args) !== 2 || !is_array($parameters)) {
             // where('column < ? OR column > ?', 1, 2)
             $parameters = $args;
             array_shift($parameters);
         }
         $this->parameters = array_merge($this->parameters, $parameters);
     } elseif ($parameters === null) {
         // where('column', NULL)
         $condition .= ' IS NULL';
     } elseif ($parameters instanceof Selection) {
         // where('column', $db->$table())
         $clone = clone $parameters;
         if (!$clone->getSqlBuilder()->select) {
             $clone->select($clone->primary);
         }
         if ($this->connection->getAttribute(PDO::ATTR_DRIVER_NAME) !== 'mysql') {
             $condition .= ' IN (' . $clone->getSql() . ')';
         } else {
             $in = array();
             foreach ($clone as $row) {
                 $this->parameters[] = array_values(iterator_to_array($row));
                 $in[] = count($row) === 1 ? '?' : '(?)';
             }
             $condition .= ' IN (' . ($in ? implode(', ', $in) : 'NULL') . ')';
         }
     } elseif (!is_array($parameters)) {
         // where('column', 'x')
         $condition .= ' = ?';
         $this->parameters[] = $parameters;
     } else {
         // where('column', array(1, 2))
         if ($parameters) {
             $condition .= " IN (?)";
             $this->parameters[] = $parameters;
         } else {
             $condition .= " IN (NULL)";
         }
     }
     $this->where[] = $condition;
     return true;
 }