I am using Zend Framework 1.12 to access the MSSQL 2008 server. I am using FreeTDS as the database driver.
I am using Zend_Db to create the following query.
$obj_sel = $obj_db
-> select ()
-> from (array ('ps' => 'ProductStock'), array ('PLU', 'stock' => 'SUM(ps.stock)'))
-> join (array ('pc' => 'ProductCatalogue'), 'ps.PLU = pc.PLU', NULL)
-> join (array ('gl' => 'Gemini_Location'), 'ps.Location = gl.LocationID', array ('LocationID'))
-> where ('ps.status = 1')
-> where ('ps.PLU IS NOT NULL');
> where ('pc.rootPLU >= ?', $this -> int_start_rootplu);
-> group ('ps.PLU')
-> group ('gl.LocationID')
-> order (array ('ps.PLU', 'gl.LocationID'));
If I run and execute this, I get the request back, which seems to be working fine and will be correct.
SELECT "ps"."PLU", SUM(ps.stock) AS "stock", "gl"."LocationID" FROM "ProductStock" AS "ps"
INNER JOIN "ProductCatalogue" AS "pc" ON ps.PLU = pc.PLU
INNER JOIN "Gemini_Location" AS "gl" ON ps.Location = gl.LocationID WHERE (ps.status = 1) AND (ps.PLU IS NOT NULL) AND (pc.rootPLU >= 93838) GROUP BY "ps"."PLU",
"gl"."LocationID" ORDER BY "ps"."PLU" ASC, "gl"."LocationID" ASC
But when I try to add a constraint or offset to the request, for example:
$obj_sel = $obj_db
-> select ()
-> from (array ('ps' => 'ProductStock'), array ('PLU', 'stock' => 'SUM(ps.stock)'))
-> join (array ('pc' => 'ProductCatalogue'), 'ps.PLU = pc.PLU', NULL)
-> join (array ('gl' => 'Gemini_Location'), 'ps.Location = gl.LocationID', array ('LocationID'))
-> where ('ps.status = 1')
-> where ('ps.PLU IS NOT NULL');
> where ('pc.rootPLU >= ?', $this -> int_start_rootplu);
-> group ('ps.PLU')
-> group ('gl.LocationID')
-> order (array ('ps.PLU', 'gl.LocationID'))
-> limit (1000,2000);
I get the following query that the SQL server refuses to execute.
SELECT * FROM (SELECT TOP 1000 * FROM (SELECT TOP 3000 "ps"."PLU", SUM(ps.stock) AS "stock", "gl"."LocationID" FROM "ProductStock" AS "ps"
INNER JOIN "ProductCatalogue" AS "pc" ON ps.PLU = pc.PLU
INNER JOIN "Gemini_Location" AS "gl" ON ps.Location = gl.LocationID WHERE (ps.status = 1) AND (ps.PLU IS NOT NULL) AND (pc.rootPLU >= 93838) GROUP BY "ps"."PLU",
"gl"."LocationID" ORDER BY "ps"."PLU" ASC, "gl"."LocationID" ASC) AS inner_tbl ORDER BY "ps"."PLU" , "gl"."LocationID" DESC) AS outer_tbl ORDER BY "ps"."PLU" , "gl"."LocationID" asc
I get the following error:
SQLSTATE [HY000]: general error: 4104 General SQL Server error: check messages with SQL Server [4104] (severity 16) [(null)]
MSSQL, MySQL Postgres, , TOP . , , , SQL Zend DB , .
Zend DB? , ?