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

Suggestion: Add a table_name parameter to WHERE conditions #11

Closed
starfishpatkhoo opened this issue May 6, 2024 · 4 comments
Closed

Comments

@starfishpatkhoo
Copy link

I love the where conditions because it makes the query code so much easier to read. A single authorisation check joins 3 tables with conditions on two fields, sort order, blah blah.. Such a pain to read (and debug).

I wanted to ->eq("other_table.field", "value") but it becomes mytable.other_table.field in SQL .. So I have to write the ->where() by hand.. ha ha..

So if ->eq() and friends can either have an optional third param being the table name, or become smart enough not to insert the table name automatically when it has already been specified.. that would eliminate another big use of ->where() and ->pdo->quote() ...

Yes, I am a spoiled brat. 🤣

@n0nag0n
Copy link
Contributor

n0nag0n commented May 6, 2024

Well I'm curious....if you are specifying another table in your where statement, how are you writing your joins? I guess you would need to escape that as well if you're writing it in the join...not sure how, but I think I could scan for a . in the eq() and if it's there do not add the table name.

@starfishpatkhoo
Copy link
Author

Well I'm curious....if you are specifying another table in your where statement, how are you writing your joins? I guess you would need to escape that as well if you're writing it in the join...not sure how, but I think I could scan for a . in the eq() and if it's there do not add the table name.

Oh just normal join with ->join() ..

$db = new mytable;
$db->join("table2", "mytable.key = table2.key");
$db->join("table3", "mytable.key = table3.key");
$db->eq("table2.field", "data1");
$db->eq("table3.field", "data2");
$db->order("table3.date");
$db->find();

so if using where..

$db = new mytable;
$db->join("table2", "mytable.key = table2.key");
$db->join("table3", "mytable.key = table3.key");
$db->where("table2.field = data1 and table3.field = data2");
$db->order("table3.date");
$db->find();

Then have to escape and blah blah the data. ..

Something like that. The point is, it is much easier to read and understand now, so it really is nice.. Leave the where for the really complicated with multiple groups ( ) and such. Ha ha ..

@n0nag0n
Copy link
Contributor

n0nag0n commented May 22, 2024

I believe this PR addresses what you're after. Check the new version! #16

@n0nag0n n0nag0n closed this as completed May 22, 2024
@starfishpatkhoo
Copy link
Author

Sorry, just now managing to have a look, seems to be working great, thank you! ^_^

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

No branches or pull requests

2 participants