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


PHP Doctrine_Query::getSql方法代码示例

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


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

示例1: testQueryCopy

    public function testQueryCopy()
    {
        $q = new Doctrine_Query();

        $q->from('User u');
        
        $q2 = $q->copy();
        
        $this->assertEqual($q->getSql(), $q2->getSql());

	    $this->assertEqual($q->getSql(), 'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE (e.type = 0)');
    }
开发者ID:prismhdd,项目名称:victorioussecret,代码行数:12,代码来源:CopyTestCase.php

示例2: testSelectDistinctIsSupported2

    public function testSelectDistinctIsSupported2()
    {
        $q = new Doctrine_Query();
        
        $q->select('DISTINCT u.name')->from('User u');

        $this->assertEqual($q->getSql(), "SELECT DISTINCT e.id AS e__id, e.name AS e__name FROM entity e WHERE (e.type = 0)");
    }
开发者ID:prismhdd,项目名称:victorioussecret,代码行数:8,代码来源:SelectTestCase.php

示例3: testApplyInheritance

 public function testApplyInheritance()
 {
     $query = new Doctrine_Query();
     $query->from('InheritanceDeal d, d.Users u');
     $query->where('u.id = 1');
     $sql = 'SELECT i.id AS i__id, i.name AS i__name, i2.id AS i2__id, i2.username AS i2__username FROM inheritance_deal i LEFT JOIN inheritance_entity_user i3 ON (i.id = i3.entity_id) AND i3.type = 1 LEFT JOIN inheritance_user i2 ON i2.id = i3.user_id WHERE i2.id = 1';
     $this->assertEqual($sql, $query->getSql());
 }
开发者ID:ninjapenguin,项目名称:kohana-Doctrine-module,代码行数:8,代码来源:ApplyInheritanceTestCase.php

示例4: __construct

 /**
  * constructor
  *
  * @param Doctrine_Query $query
  */
 public function __construct(Doctrine_Query $query, $viewName)
 {
     $this->_name = $viewName;
     $this->_query = $query;
     $this->_query->setView($this);
     $this->_conn = $query->getConnection();
     $this->_dql = $query->getDql();
     $this->_sql = $query->getSql();
 }
开发者ID:stelaireri,项目名称:Hive,代码行数:14,代码来源:View.php

示例5: search

 /**
  * Searchable keyword search
  * 
  * @param string $string Keyword string to search for
  * @param Doctrine_Query $query Query object to alter. Adds where condition to limit the results using the search index
  * @return mixed The Doctrine_Collection or array of ids and relevancy
  */
 public function search($string, $query = null)
 {
     $q = new Doctrine_Search_Query($this->_table);
     if ($query instanceof Doctrine_Query) {
         $q->query($string, false);
         $newQuery = $query->copy();
         $query->getSql();
         $newQuery->addWhere($query->getRootAlias() . '.id IN(' . $q->getSql() . ')', $q->getParams());
         return $newQuery;
     } else {
         $q->query($string);
         return $this->_options['connection']->fetchAll($q->getSql(), $q->getParams());
     }
 }
开发者ID:JimmyVB,项目名称:Symfony-v1.2,代码行数:21,代码来源:Search.php

示例6: search

 /**
  * Searchable keyword search
  * 
  * @param string $string Keyword string to search for
  * @param Doctrine_Query $query Query object to alter. Adds where condition to limit the results using the search index
  * @return mixed The Doctrine_Collection or array of ids and relevancy
  */
 public function search($string, $query = null)
 {
     $q = new Doctrine_Search_Query($this->_table);
     if ($query instanceof Doctrine_Query) {
         $q->query($string, false);
         $newQuery = $query->copy();
         $query->getSql();
         $key = (array) $this->getOption('table')->getIdentifier();
         $newQuery->addWhere($query->getRootAlias() . '.' . current($key) . ' IN (SQL:' . $q->getSql() . ')', $q->getParams());
         return $newQuery;
     } else {
         $q->query($string);
         return $this->_options['connection']->fetchAll($q->getSql(), $q->getParams());
     }
 }
开发者ID:yasirgit,项目名称:afids,代码行数:22,代码来源:Search.php

示例7: testGetLimitSubqueryOrderBy2

 public function testGetLimitSubqueryOrderBy2()
 {
     $q = new Doctrine_Query();
     $q->select('u.name, COUNT(DISTINCT a.id) num_albums');
     $q->from('User u, u.Album a');
     $q->orderby('num_albums');
     $q->groupby('u.id');
     try {
         // this causes getLimitSubquery() to be used, and it fails
         $q->limit(5);
         $users = $q->execute();
         $count = $users->count();
     } catch (Doctrine_Exception $e) {
         $this->fail();
     }
     $this->assertEqual($q->getSql(), 'SELECT e.id AS e__id, e.name AS e__name, COUNT(DISTINCT a.id) AS a__0 FROM entity e LEFT JOIN album a ON e.id = a.user_id WHERE e.id IN (SELECT DISTINCT e2.id FROM entity e2 LEFT JOIN album a2 ON e2.id = a2.user_id WHERE (e2.type = 0) GROUP BY e2.id ORDER BY a__0 LIMIT 5) AND (e.type = 0) GROUP BY e.id ORDER BY a__0');
 }
开发者ID:ninjapenguin,项目名称:kohana-Doctrine-module,代码行数:17,代码来源:SubqueryTestCase.php

示例8: testDqlUpdate

    public function testDqlUpdate()
    {
        $query = new Doctrine_Query($this->connection);
        $query->update('EnumTest2 u')
            ->set('u.status', '?', 'verified');

        $this->assertEqual($query->getSql(), 'UPDATE enum_test2 SET status = ?');   

        $query->execute();

        try {
            $query = new Doctrine_Query($this->connection);
            $ret = $query->query("FROM EnumTest2 WHERE EnumTest2.status = 'verified'");
            $this->assertEqual(count($ret), 1);
        } catch (Exception $e) {
            $this->fail();
        }
    }
开发者ID:prismhdd,项目名称:victorioussecret,代码行数:18,代码来源:EnumTestCase.php

示例9: testTicket

 public function testTicket()
 {
     Doctrine_Manager::getInstance()->setAttribute('use_dql_callbacks', true);
     $q = new Doctrine_Query();
     $q->select('s.*')->from('Ticket_1116_User s')->where('s.username = ?', array('test'));
     // to see the error switch dbh to a real db, the next line will trigger the error
     $test = $q->fetchOne();
     //will only fail with "real" mysql
     $this->assertFalse($test);
     $sql = $q->getSql();
     // just getSql()?!?! and it works ? the params are ok after this call
     $params = $q->getFlattenedParams();
     $this->assertEqual(count($params), 1);
     // now we have array('test',null) very strange .....
     $this->assertEqual($sql, "SELECT u.id AS u__id, u.username AS u__username, u.deleted_at AS u__deleted_at FROM user u WHERE u.username = ? AND (u.deleted_at IS NULL)");
     $this->assertEqual($params, array('test'));
     //now also this works! (always works witch mock only fails with mysql)
     $test = $q->fetchOne();
     $this->assertFalse($test);
     Doctrine_Manager::getInstance()->setAttribute('use_dql_callbacks', false);
 }
开发者ID:ninjapenguin,项目名称:kohana-Doctrine-module,代码行数:21,代码来源:1116TestCase.php

示例10: testNonPortableFunctionsAreSupported

    public function testNonPortableFunctionsAreSupported()
    {
         $query = new Doctrine_Query();
         // we are using stored procedure here, so adjust portability settings
         $this->conn->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_ALL ^ Doctrine::PORTABILITY_EXPR);

         $lat = '13.23';
         $lon = '33.23';
         $radius = '33';

         $query->select("l.*, i18n.*, GeoDistKM(l.lat, l.lon, $lat, $lon) distance")
              ->from('Location l, l.LocationI18n i18n')          
              ->where('l.id <> ? AND i18n.culture = ?', array(1, 'en'))
              ->having("distance < $radius")
              ->orderby('distance ASC')
              ->groupby('l.id')
              ->limit(5);

         $this->assertEqual($query->getSql(), "SELECT l.id AS l__id, l.lat AS l__lat, l.lon AS l__lon, l2.name AS l2__name, l2.id AS l2__id, l2.culture AS l2__culture, GeoDistKM(l.lat, l.lon, 13.23, 33.23) AS l__0 FROM location l LEFT JOIN location_i18n l2 ON l.id = l2.id WHERE l.id IN (SELECT DISTINCT l3.id FROM location l3 LEFT JOIN location_i18n l4 ON l3.id = l4.id WHERE (l3.id <> ? AND l4.culture = ?) GROUP BY l3.id HAVING l__0 < 33 ORDER BY l__0 ASC LIMIT 5) AND (l.id <> ? AND l2.culture = ?) GROUP BY l.id HAVING l__0 < 33 ORDER BY l__0 ASC");

         $this->conn->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_ALL);
    }
开发者ID:prismhdd,项目名称:victorioussecret,代码行数:22,代码来源:ExpressionTestCase.php

示例11: testEqualNestRelationsQuerying

    public function testEqualNestRelationsQuerying()
    {
        $this->connection->clear();

        $q = new Doctrine_Query();

        $q->from('NestTest n')->innerJoin('n.Relatives r')->where('n.id = 1');

        $n = $q->execute();

        $this->assertEqual($q->getSql(), 'SELECT n.id AS n__id, n.name AS n__name, n2.id AS n2__id, n2.name AS n2__name FROM nest_test n INNER JOIN nest_reference n3 ON n.id = n3.child_id OR n.id = n3.parent_id INNER JOIN nest_test n2 ON (n2.id = n3.parent_id OR n2.id = n3.child_id) AND n2.id != n.id WHERE n.id = 1');

        $this->assertEqual($n[0]->Relatives->count(), 5);
    }
开发者ID:prismhdd,项目名称:victorioussecret,代码行数:14,代码来源:NestTestCase.php

示例12: testLimitOffsetLimitSubqueriesForOracleWithGroupByOrderBy

 /**
 * Ticket #1038
  */
    public function testLimitOffsetLimitSubqueriesForOracleWithGroupByOrderBy()
    {
        $this->dbh = new Doctrine_Adapter_Mock('oracle');
        $conn = $this->manager->openConnection($this->dbh);
        $q = new Doctrine_Query($conn);
        // The orderBy(p.id) will force p.id to be added to the SELECT part of the 
        // SELECT DISTINCT subquery because that is required by oracle. This, however,
        // can result in duplicated primary keys that would cause incorrect ROWNUM calculations,
        // hence an additional subquery used to filter out the primary keys is added. 
        $q->from('User u')->innerJoin('u.Phonenumber p')
                ->groupBy('u.name') // !
                ->orderBy('p.id') // !!
                ->limit(5)->offset(2);
        $correctSql = "SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, "
                    . "e.password AS e__password, e.type AS e__type, e.created AS e__created, "
                    . "e.updated AS e__updated, e.email_id AS e__email_id, p.id AS p__id, "
                    . "p.phonenumber AS p__phonenumber, p.entity_id AS p__entity_id "
                    . "FROM entity e "
                    . "INNER JOIN phonenumber p ON e.id = p.entity_id "
                    . "WHERE e.id IN ("
                        . "SELECT b.id FROM ("
                            . "SELECT a.*, ROWNUM AS doctrine_rownum "
                                  . "FROM ("
                                      . "SELECT doctrine_subquery_alias.id FROM ("
                                          . "SELECT e2.id, p2.id "
                                          . "FROM entity e2 "
                                          . "INNER JOIN phonenumber p2 ON e2.id = p2.entity_id "
                                          . "WHERE (e2.type = 0) GROUP BY e2.name ORDER BY p2.id"
                                      . ") doctrine_subquery_alias GROUP BY doctrine_subquery_alias.id ORDER BY MIN(ROWNUM)"
                                  . ") a"
                              . " ) b "
                              . "WHERE doctrine_rownum BETWEEN 3 AND 7"
                          . ") AND (e.type = 0) GROUP BY e.name ORDER BY p.id";
                         
              $this->assertEqual($q->getSql(), $correctSql);
          }
开发者ID:prismhdd,项目名称:victorioussecret,代码行数:39,代码来源:DriverTestCase.php

示例13: testStringColumnInheritance

 public function testStringColumnInheritance()
 {
     $q = new Doctrine_Query();
     $q->select('g.name')->from('Group g');
     $this->assertEqual($q->getSql(), "SELECT e.id AS e__id, e.name AS e__name FROM entity e WHERE (e.type = 1)");
 }
开发者ID:prismhdd,项目名称:victorioussecret,代码行数:6,代码来源:ColumnAggregationInheritanceTestCase.php

示例14: testReferenfingParentColumnsUsesProperAliases

    public function testReferenfingParentColumnsUsesProperAliases()
    {
        $q = new Doctrine_Query();
        $q->from('CTITest c')->where("c.name = 'Jack'");

        $this->assertEqual($q->getSql(), "SELECT c.id AS c__id, c3.added AS c__added, c2.name AS c__name, c2.verified AS c__verified, c.age AS c__age FROM c_t_i_test_parent4 c LEFT JOIN c_t_i_test_parent2 c2 ON c.id = c2.id LEFT JOIN c_t_i_test_parent3 c3 ON c.id = c3.id WHERE c2.name = 'Jack'");

        $q = new Doctrine_Query();
        $q->from('CTITest c')->where("name = 'Jack'");

        $this->assertEqual($q->getSql(), "SELECT c.id AS c__id, c3.added AS c__added, c2.name AS c__name, c2.verified AS c__verified, c.age AS c__age FROM c_t_i_test_parent4 c LEFT JOIN c_t_i_test_parent2 c2 ON c.id = c2.id LEFT JOIN c_t_i_test_parent3 c3 ON c.id = c3.id WHERE c2.name = 'Jack'");
    }
开发者ID:prismhdd,项目名称:victorioussecret,代码行数:12,代码来源:ClassTableInheritanceTestCase.php

示例15: testAggregateFunctionParser4

    public function testAggregateFunctionParser4()
    {
        $q = new Doctrine_Query();
        $q->select('CONCAT(i.price, i.quantity)')->from('QueryTest_Item i');

        $this->assertEqual($q->getSql(), 'SELECT CONCAT(q.price, q.quantity) AS q__0 FROM query_test__item q');
    }
开发者ID:prismhdd,项目名称:victorioussecret,代码行数:7,代码来源:AggregateValueTestCase.php


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