This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

MySQL Error - Missing SELECT Projection? - SOLVED

This is for discussion, mainly on 1.x but there's some 2.x topics here too.

MySQL Error - Missing SELECT Projection? - SOLVED

by zherkezhi » Fri Feb 04, 2011 9:16 pm

I'm relatively new to Symfony but I'm learning more day by day.
I want to search and find a specific product ID of a product I have, and when doing that I get a 500 error:

500 | Internal Server Error | PropelException
Unable to execute SELECT statement [SELECT FROM `product` WHERE product.SLUG=:p1 AND product.DELETED_AT IS NULL LIMIT 1] [wrapped: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `product` WHERE product.SLUG='hawaii-1' AND product.DELETED_AT IS NULL LIM' at line 1]

from the look of this error, it seems like it doesn't print out the star, I tried to write in the SQL statements manually in the SQL console, and it gave me this:

mysql> SELECT * FROM `product` WHERE product.SLUG='hawaii-1' AND product.DELETED_AT IS NULL LIMIT 1;
+----+--------+---------+-------+-----+----------+---------------------+---------------------+----------+------------+
| id | name | barcode | price | tax | is_extra | created_at | updated_at | slug | deleted_at |
+----+--------+---------+-------+-----+----------+---------------------+---------------------+----------+------------+
| 5 | Hawaii | 1 | 12.5 | 1.5 | 0 | 2011-02-04 18:36:42 | 2011-02-04 18:36:42 | hawaii-1 | NULL |
+----+--------+---------+-------+-----+----------+---------------------+---------------------+----------+------------+
1 row in set (0.00 sec)

mysql> SELECT FROM `product` WHERE product.SLUG='hawaii-1' AND product.DELETED_AT IS NULL LIMIT 1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `product` WHERE product.SLUG='hawaii-1'

I traced down the error to the fact that Symfony doesn't give any details of the projection,

as from the MySQL log:

Query SELECT FROM `product` WHERE product.SLUG='hawaii-1' AND product.DELETED_AT IS NULL LIMIT 1

note the three spaces between the "SELECT" and the "FROM", clearly this is an invalid SQL statement.

the code that writes this SQL SELECT is the following, and is a part of the model:
Code: Select all
$pid = cartProductQuery::create()->useProductQuery()->findOneBySlug($product)->getId();

where $product is the slug of the product I search for.


Does anyone know how to include the projection? (as in putting in what to select)?

Solution:

the code should be like this:

Code: Select all
$pid = productQuery::create()->findOneBySlug($product)->getId()


I don't really know why I wrote that other code first, but I guess I will learn.

I'm using:
Wamp (under Windows XP SP 3)
PHP 5.3.0
MySQL 5.1.36
Apache 2.2.11
Symfony version 1.4.8
zherkezhi
Junior Member
 
Posts: 5
Joined: Fri Feb 04, 2011 9:08 pm

Re: MySQL Error - Missing SELECT Projection? - SOLVED

by dylanhay » Tue Jul 15, 2014 10:02 am

from the look of this error, it seems like it doesn't print out the star, I tried to write in the SQL statements manually in the SQL console, and it gave me this:

mysql> SELECT * FROM `product` WHERE product.SLUG='hawaii-1' AND product.DELETED_AT IS NULL LIMIT 1;
+----+--------+---------+-------+-----+----------+---------------------+---------------------+----------+------------+
| id | name | barcode | price | tax | is_extra | created_at | updated_at | slug | deleted_at |
+----+--------+---------+-------+-----+----------+---------------------+---------------------+----------+------------+
| 5 | Hawaii | 1 | 12.5 | 1.5 | 0 | 2011-02-04 18:36:42 | 2011-02-04 18:36:42 | hawaii-1 | NULL |
+----+--------+---------+-------+-----+----------+---------------------+---------------------+----------+------------+
1 row in set (0.00 sec)


how this happen, and how to solve it?
dylanhay
Junior Member
 
Posts: 1
Joined: Tue Jul 15, 2014 9:57 am