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

Backslash on table name breaks it #106

Closed
TCB13 opened this issue Mar 12, 2015 · 3 comments
Closed

Backslash on table name breaks it #106

TCB13 opened this issue Mar 12, 2015 · 3 comments
Assignees
Labels

Comments

@TCB13
Copy link

TCB13 commented Mar 12, 2015

Hello,

I was trying to get records out of a table called CMS\Page, yes there's a backslash on the table name. Unfortunately the backslash seems to result in a strange JOIN behavior.

Query without backslash:

$fpdo = new \FluentPDO($pdo);

$query = $fpdo->from("Page")
->select(array('title', 'date'))
->limit(5);

print $query->getQuery();

=> SELECT Page.*, title FROM Page LIMIT 5

Query with backslash on table name:

$fpdo = new \FluentPDO($pdo);

$query = $fpdo->from("CMS\\Page")
->select(array('title', 'date'))
->limit(5);

print $query->getQuery();

=> SELECT CMS\Page.*, title, date FROM CMS\Page LEFT JOIN Page ON Page.id = CMS\Page.Page_id LIMIT 5

Why do this happen? There's no reason why we shouldn't have backslashed on table names. At least not on the most recent MySQL/MariaDB versions.

Side Note: There's also the old annoying issue where using ->select(...) doesn't matter because ->from(...) will always add a select all on the table like Page.*.

Thank you.

@cbornhoft cbornhoft added the Bug label Mar 10, 2016
@cbornhoft cbornhoft self-assigned this Mar 10, 2016
@cbornhoft
Copy link
Member

For your second issue, use $fpdo->from()->select(null)->select('column1','column2');

This is because the smart join builder thinks you're performing a join with select.

@maldoinc
Copy link
Contributor

maldoinc commented Jul 7, 2016

Hello, thanks for taking the time to report this. Escaping table and column names is a common request but for this current release we're not automatically escaping them due to backwards compatibility.

@maldoinc maldoinc closed this as completed Jul 7, 2016
@cbornhoft
Copy link
Member

Fixed in #209

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

3 participants