当前位置: 首页>>代码示例>>PHP>>正文


PHP Query::sql方法代码示例

本文整理汇总了PHP中Cake\Database\Query::sql方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::sql方法的具体用法?PHP Query::sql怎么用?PHP Query::sql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Database\Query的用法示例。


在下文中一共展示了Query::sql方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: prepare

 /**
  * Prepares a sql statement to be executed
  *
  * @param string|\Cake\Database\Query $query The query to prepare.
  * @return \Cake\Database\StatementInterface
  */
 public function prepare($query)
 {
     $this->connect();
     $options = [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL];
     $isObject = $query instanceof Query;
     if ($isObject && $query->bufferResults() === false) {
         $options = [];
     }
     $statement = $this->_connection->prepare($isObject ? $query->sql() : $query, $options);
     return new SqlserverStatement($statement, $this);
 }
开发者ID:CakeDC,项目名称:cakephp,代码行数:17,代码来源:Sqlserver.php

示例2: prepare

 /**
  * Prepares a sql statement to be executed
  *
  * @param string|\Cake\Database\Query $query The query to turn into a prepared statement.
  * @return \Cake\Database\StatementInterface
  */
 public function prepare($query)
 {
     $this->connect();
     $isObject = $query instanceof Query;
     $statement = $this->_connection->prepare($isObject ? $query->sql() : $query);
     return new PDOStatement($statement, $this);
 }
开发者ID:malhan23,项目名称:assignment-3,代码行数:13,代码来源:PDODriverTrait.php

示例3: prepare

 /**
  * Prepares a sql statement to be executed
  *
  * @param string|\Cake\Database\Query $query The query to prepare.
  * @return \Cake\Database\StatementInterface
  */
 public function prepare($query)
 {
     $this->connect();
     $isObject = $query instanceof Query;
     $statement = $this->_connection->prepare($isObject ? $query->sql() : $query);
     $result = new SqliteStatement(new PDOStatement($statement, $this), $this);
     if ($isObject && $query->bufferResults() === false) {
         $result->bufferResults(false);
     }
     return $result;
 }
开发者ID:CakeDC,项目名称:cakephp,代码行数:17,代码来源:Sqlite.php

示例4: prepare

 /**
  * Prepares a sql statement to be executed
  *
  * @param string|\Cake\Database\Query $query The query to prepare.
  * @return \Cake\Database\StatementInterface
  */
 public function prepare($query)
 {
     $this->connect();
     $options = [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY];
     $isObject = $query instanceof Query;
     if ($isObject && $query->bufferResults() === false) {
         $options = [];
     }
     $statement = $this->_connection->prepare($isObject ? $query->sql() : $query, $options);
     $result = new CustomSqlserverStatement(new SqlserverStatement($statement, $this), $this);
     if ($isObject && $query->bufferResults() === false) {
         $result->bufferResults(false);
     }
     return $result;
 }
开发者ID:dominic-horbas,项目名称:cakephp-remote-sql-server-driver,代码行数:21,代码来源:CustomSqlserver.php

示例5: sql

 /**
  * {@inheritDoc}
  */
 public function sql(ValueBinder $binder = null)
 {
     $this->triggerBeforeFind();
     $this->_transformQuery();
     $sql = parent::sql($binder);
     return $sql;
 }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:10,代码来源:Query.php

示例6: testIsNullAutoQuoting

 /**
  * Tests that strings passed to isNull and isNotNull will be treated as identifiers
  * when using autoQuoting
  *
  * @return void
  */
 public function testIsNullAutoQuoting()
 {
     $this->connection->driver()->autoQuoting(true);
     $query = new Query($this->connection);
     $query->select('*')->from('things')->where(function ($exp) {
         return $exp->isNull('field');
     });
     $this->assertQuotedQuery('WHERE \\(<field>\\) IS NULL', $query->sql());
     $query = new Query($this->connection);
     $query->select('*')->from('things')->where(function ($exp) {
         return $exp->isNotNull('field');
     });
     $this->assertQuotedQuery('WHERE \\(<field>\\) IS NOT NULL', $query->sql());
 }
开发者ID:KarimaLadhani,项目名称:cakephp,代码行数:20,代码来源:QueryTest.php

示例7: testInsertUsesOutput

 /**
  * Test that insert queries have results available to them.
  *
  * @return void
  */
 public function testInsertUsesOutput()
 {
     $driver = $this->getMock('Cake\\Database\\Driver\\Sqlserver', ['_connect', 'connection'], [[]]);
     $connection = $this->getMock('\\Cake\\Database\\Connection', ['connect', 'driver'], [['log' => false]]);
     $connection->expects($this->any())->method('driver')->will($this->returnValue($driver));
     $query = new \Cake\Database\Query($connection);
     $query->insert(['title'])->into('articles')->values(['title' => 'A new article']);
     $expected = 'INSERT INTO articles (title) OUTPUT INSERTED.* VALUES (:c0)';
     $this->assertEquals($expected, $query->sql());
 }
开发者ID:jdaosavanh,项目名称:clickerwebapp,代码行数:15,代码来源:SqlserverTest.php

示例8: testSelectLimitOldServer

 /**
  * Test select with limit on lte SQLServer2008
  *
  * @return void
  */
 public function testSelectLimitOldServer()
 {
     $driver = $this->getMock('Cake\\Database\\Driver\\Sqlserver', ['_connect', 'connection', '_version'], [['dsn' => 'foo']]);
     $driver->expects($this->any())->method('_version')->will($this->returnValue(8));
     $connection = $this->getMock('\\Cake\\Database\\Connection', ['connect', 'driver'], [['log' => false]]);
     $connection->expects($this->any())->method('driver')->will($this->returnValue($driver));
     $query = new \Cake\Database\Query($connection);
     $query->select(['id', 'title'])->from('articles')->limit(10);
     $expected = 'SELECT TOP 10 id, title FROM articles';
     $this->assertEquals($expected, $query->sql());
     $query = new \Cake\Database\Query($connection);
     $query->select(['id', 'title'])->from('articles')->offset(10);
     $expected = 'SELECT * FROM (SELECT id, title, (ROW_NUMBER() OVER (ORDER BY (SELECT NULL))) AS [_cake_page_rownum_] ' . 'FROM articles) AS _cake_paging_ ' . 'WHERE _cake_paging_._cake_page_rownum_ > :c0';
     $this->assertEquals($expected, $query->sql());
     $query = new \Cake\Database\Query($connection);
     $query->select(['id', 'title'])->from('articles')->order(['id'])->offset(10);
     $expected = 'SELECT * FROM (SELECT id, title, (ROW_NUMBER() OVER (ORDER BY id)) AS [_cake_page_rownum_] ' . 'FROM articles) AS _cake_paging_ ' . 'WHERE _cake_paging_._cake_page_rownum_ > :c0';
     $this->assertEquals($expected, $query->sql());
     $query = new \Cake\Database\Query($connection);
     $query->select(['id', 'title'])->from('articles')->order(['id'])->where(['title' => 'Something'])->limit(10)->offset(50);
     $expected = 'SELECT * FROM (SELECT id, title, (ROW_NUMBER() OVER (ORDER BY id)) AS [_cake_page_rownum_] ' . 'FROM articles WHERE title = :c0) AS _cake_paging_ ' . 'WHERE (_cake_paging_._cake_page_rownum_ > :c1 AND _cake_paging_._cake_page_rownum_ <= :c2)';
     $this->assertEquals($expected, $query->sql());
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:28,代码来源:SqlserverTest.php

示例9: sql

 /**
  * {@inheritDoc}
  */
 public function sql(ValueBinder $binder = null)
 {
     $this->_transformQuery();
     return parent::sql($binder);
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:8,代码来源:Query.php

示例10: prepare

 /**
  * Create a NodeStatement from query and returns it
  * 
  * @param Query $query
  * @return NodeStatement
  */
 public function prepare($query)
 {
     $this->connect();
     $isObject = $query instanceof Query;
     return new NodeStatement($isObject ? $query->sql() : $query, $this);
 }
开发者ID:Teleservice,项目名称:cakephp-mssql-linux,代码行数:12,代码来源:Node.php

示例11: testInsertFromSelect

 /**
  * Test that INSERT INTO ... SELECT works.
  *
  * @return void
  */
 public function testInsertFromSelect()
 {
     $select = (new Query($this->connection))->select(['name', "'some text'", 99])->from('authors')->where(['id' => 1]);
     $query = new Query($this->connection);
     $query->insert(['title', 'body', 'author_id'], ['title' => 'string', 'body' => 'string', 'author_id' => 'integer'])->into('articles')->values($select);
     $result = $query->sql();
     $this->assertQuotedQuery('INSERT INTO <articles> \\(<title>, <body>, <author_id>\\) SELECT', $result, true);
     $this->assertQuotedQuery('SELECT <name>, \'some text\', 99 FROM <authors>', $result, true);
     $result = $query->execute();
     $this->assertCount(1, $result);
     $result = (new Query($this->connection))->select('*')->from('articles')->where(['author_id' => 99])->execute();
     $this->assertCount(1, $result);
     $expected = ['id' => 4, 'title' => 'mariano', 'body' => 'some text', 'author_id' => 99, 'published' => 'N'];
     $this->assertEquals($expected, $result->fetch('assoc'));
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:20,代码来源:QueryTest.php

示例12: prepare

 /**
  * Prepares a sql statement to be executed
  *
  * @param string|\Cake\Database\Query $query The query to convert into a statement.
  * @return \Cake\Database\StatementInterface
  */
 public function prepare($query)
 {
     $this->connect();
     $isObject = $query instanceof \Cake\ORM\Query || $query instanceof \Cake\Database\Query;
     $queryStringRaw = $isObject ? $query->sql() : $query;
     Log::write('debug', $queryStringRaw);
     // debug($queryStringRaw);
     $queryString = $this->_fromDualIfy($queryStringRaw);
     list($queryString, $paramMap) = self::convertPositionalToNamedPlaceholders($queryString);
     $innerStatement = $this->_connection->prepare($queryString);
     $statement = $this->_wrapStatement($innerStatement);
     $statement->queryString = $queryStringRaw;
     $statement->paramMap = $paramMap;
     $disableBuffer = false;
     $normalizedQuery = substr(strtolower(trim($queryString, " \t\n\r\v(")), 0, 6);
     if ($normalizedQuery !== 'select') {
         $disableBuffer = true;
     }
     if ($isObject && $query->bufferResults() === false || $disableBuffer) {
         $statement->bufferResults(false);
     }
     return $statement;
 }
开发者ID:cakedc,项目名称:cakephp-oracle-driver,代码行数:29,代码来源:OracleBase.php


注:本文中的Cake\Database\Query::sql方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。