Dipen Shah
Dipen Shah

Reputation: 1919

Weird alias [0_ added by doctrine while trying to run with SQL SERVER

I'm trying to implement APYDataGridBundle on Symfony, with SQL Server. Symfony throws in this exception:

SQLSTATE[HY000]: General error: 105 General SQL Server error: Check messages from the SQL Server [105] (severity 15) [SELECT TOP 50 [0_.PI_PK AS PI_PK0, [0_.ProductName AS ProductName1, [0_.ProductDetails AS ProductDetails2 FROM [TSOFT_LEARN].[dbo].[tblProductDemo] [0_]

I tried:

$repo = $em->getRepository("ProductOrderLookupBundle:Product");
$product = $repo->findAll();

and everything worked fine, but it breaks for over 1 million records. Someone suggested to me to use APYDatagridBundle like here. I have tried ThraceDataGrid Bundle before and it gave me this same problem. If I remove the "[0_" and everything worked fine while running the query on SQL Server.

Can anybody tell me what might be the problem?

Upvotes: 1

Views: 223

Answers (2)

Dipen Shah
Dipen Shah

Reputation: 1919

**SOLVED:**The problem was with how I defined my table names in the doctrine entities. I gave the name

[TSOFT_LEARN].[dbo].[tblOrders]

and it should be

TSOFT_LEARN.dbo.tblOrders

Because of that my alias was becoming [0_ instead of t0_. I suppose its how doctrine creates its aliases by taking the first character of the table name. Since the table name was starting with "[" the alias got converted to [0_.

Upvotes: 1

Nawfal Serrar
Nawfal Serrar

Reputation: 2263

Doctrine always create alias for tables in the generated queries. I always had the same kind of queries, i don't know if it can be disabled or not but better not because i don't know how it will react for joins , what you can do is to add a function in your repository :

public function getAllProducts(){
    $qb = $this->_em->createQueryBuilder()
    ->select('partial p.{ /*add all fields needed separated by coma optimized for big queries get only whats needed */ }')
    ->from('Product', 'p');
    $results = $qb->getQuery()->getResult();
    return $results;

}

Upvotes: 1

Related Questions