Example #1
0
 /**
  * Compiles the SQL representation of this query and executes it using the
  * configured connection object. Returns the resulting statement object.
  *
  * Executing a query internally executes several steps, the first one is
  * letting the connection transform this object to fit its particular dialect,
  * this might result in generating a different Query object that will be the one
  * to actually be executed. Immediately after, literal values are passed to the
  * connection so they are bound to the query in a safe way. Finally, the resulting
  * statement is decorated with custom objects to execute callbacks for each row
  * retrieved if necessary.
  *
  * Resulting statement is traversable, so it can be used in any loop as you would
  * with an array.
  *
  * This method can be overridden in query subclasses to decorate behavior
  * around query execution.
  *
  * @return \Cake\Database\StatementInterface
  */
 public function execute()
 {
     $statement = $this->_connection->run($this);
     $driver = $this->_connection->driver();
     $typeMap = $this->selectTypeMap();
     if ($typeMap->toArray()) {
         $this->decorateResults(new FieldTypeConverter($typeMap, $driver));
     }
     $this->_iterator = $this->_decorateStatement($statement);
     $this->_dirty = false;
     return $this->_iterator;
 }
Example #2
0
 /**
  * Constructor.
  *
  * @param \Cake\Datasource\ConnectionInterface $connection The connection instance.
  */
 public function __construct(ConnectionInterface $connection)
 {
     $this->_connection = $connection;
     $this->_dialect = $connection->driver()->schemaDialect();
 }
Example #3
0
 /**
  * Generate the SQL statements to drop the constraints to the table
  *
  * @param \Cake\Datasource\ConnectionInterface $connection The connection to generate SQL for.
  * @return array SQL to drop a table.
  */
 public function dropConstraintSql(ConnectionInterface $connection)
 {
     $dialect = $connection->driver()->schemaDialect();
     return $dialect->dropConstraintSql($this);
 }
Example #4
0
 /**
  * Generate the SQL statements to truncate a table
  *
  * @param \Cake\Datasource\ConnectionInterface $connection The connection to generate SQL for.
  * @return array SQL to truncate a table.
  */
 public function truncateSql(ConnectionInterface $connection)
 {
     $dialect = $connection->driver()->schemaDialect();
     return $dialect->truncateTableSql($this);
 }