Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in saving "order" field #6278

Closed
astefanetti opened this issue Apr 4, 2015 · 4 comments
Closed

Issue in saving "order" field #6278

astefanetti opened this issue Apr 4, 2015 · 4 comments
Labels

Comments

@astefanetti
Copy link

Hi there !
I create a mysql table with this schema:

photos

id int(11)
album_id int(11)
image varchar(255)
alt varchar(255)
title varchar(255)
description text
order int(11)
active tinyint(1)
created datetime
modified datetime

when i try to save a new record with add action baked i obtain an Exception:

Error: [PDOException] 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 'order = 1 , modified = '2015-04-05 00:14:17' WHERE id = 1' at line 1

The query log for that insert is:

Debug: BEGIN
Debug: SELECT 1 AS existing FROM albums Albums WHERE Albums.id = 1 LIMIT 1
Debug: INSERT INTO photos (album_id, image, alt, title, description, order, active, created, modified) VALUES (1, 'a', 'a', 'a', 'a', 1, 1, '2015-04-05 00:02:08', '2015-04-05 00:02:08')
Debug: ROLLBACK

I tried to solve the problem by changing the file Cake\Database\QueryCompiler.php:

protected function _buildInsertPart($parts, $query, $generator)
{
    $table = $parts[0];
    $columns = $this->_stringifyExpressions($parts[1], $generator);
    return sprintf('INSERT INTO `%s` (`%s`)', $table, implode('`, `', $columns));
} 

The same problem exists in the update.

Debug: BEGIN
Debug: UPDATE photos SET order = 1 , modified = '2015-04-05 00:14:17' WHERE id = 1
Debug: ROLLBACK

Best Regards!
Alessio

@lorenzo
Copy link
Member

lorenzo commented Apr 4, 2015

order is a reserved word in your database. Either change the column name or enable quoteIdentifiers in your database config.

@lorenzo lorenzo closed this as completed Apr 4, 2015
@lorenzo lorenzo assigned lorenzo and unassigned lorenzo Apr 4, 2015
@lorenzo lorenzo added the support label Apr 4, 2015
@astefanetti
Copy link
Author

Hi Lorenzo!
I did not know the existence of this setting and good reason behind!
Thank you so much for the quick reply!
Best Regards
Alessio

@zx4357685
Copy link

Why not add the quoteIdentifiers when making the SQL as CakePHP 2.x?

@ADmad
Copy link
Member

ADmad commented Apr 16, 2015

@zx4357685 For performance gain. You can still enable identifier quoting yourself if you want it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants