Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Introduce Enclose names feature. #27

Merged
merged 2 commits into from
Aug 10, 2015
Merged

Conversation

Metalaka
Copy link
Member

Based on #7 (New feature : enclose names)

This PR will allow use of keywords and resolve some case sensitivity problems for table, column and alias names in the query builder.
The PR don't enclose columns names in WHERE and HAVING clause.
The feature is disabled by default.

The Dml interface have 3 new methods: enable/disable feature and set symbol.
A new EncolseNames abstract class is used by Where and Insert classes to provide the code of this 3 methods.


I did this PR because PostgreSQL need enclosed columns names to be case sensitive.
PS: maybe a method isEnabled is missing ?

@Hywan
Copy link
Member

Hywan commented Jun 22, 2015

@osaris Feel free to choose anoter assignee if you can't follow and review this PR.

@osaris
Copy link
Member

osaris commented Jun 22, 2015

Hello,

Good idea but why don't you enclose names in WHERE / HAVING ? The problem is the same no ?

@Metalaka
Copy link
Member Author

HI,
Simply because where and having method take in parameter expressions and not columns name.
To support WHERE and HAVING we need to find the column(s) in each expression.

@osaris
Copy link
Member

osaris commented Jun 22, 2015

@Metalaka sure, my bad. Can you add a basic test for your feature ?

@Metalaka Metalaka force-pushed the encloseNames branch 2 times, most recently from 3ff7f56 to 46d2c64 Compare June 22, 2015 16:46
@Metalaka
Copy link
Member Author

Done.

@osaris
Copy link
Member

osaris commented Jun 23, 2015

Thanks, everything looks good to me. Thoughts @hoaproject/hoackers ?

@Jir4
Copy link

Jir4 commented Jun 24, 2015

👍 Looks good to me too

@jubianchi
Copy link
Member

👍

@@ -75,6 +75,7 @@ public function from($source)
*/
public function __toString()
{
return 'DELETE FROM ' . $this->_from . parent::__toString();
return 'DELETE FROM ' . $this->enclose($this->_from) .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CS:

return
    'DELETE FROM ' .
    $this->_from .
    parent::__toString();

When we have multiple concatenation, we prefer this syntax now :-). Had to be formalized though…

@Hywan
Copy link
Member

Hywan commented Jun 25, 2015

Please, add tests when disabling encoding :-).

Good job!

@Hywan
Copy link
Member

Hywan commented Jun 26, 2015

Also, I was thinking, what about renaming “name” into “symbol”? I reckon it's more abstract and then it might be better because more reusable. Thoughts?

@Metalaka
Copy link
Member Author

The problem with "enclose symbol" naming is:
we'll enclose symbols(ex-names) with symbols...

@Metalaka
Copy link
Member Author

CS & naming fixed.
More tests added and moved to a specific file.

@Hywan
Copy link
Member

Hywan commented Jun 29, 2015

Will review as soon as possible.

->isEqualTo(
'SELECT a, b FROM foo'
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default case is missing?

@Hywan
Copy link
Member

Hywan commented Aug 4, 2015

Look really good @Metalaka. I have a last question. Why not having EncloseNames as a trait instead of a class? It makes more sense, isn't it?

@Metalaka Metalaka force-pushed the encloseNames branch 3 times, most recently from 12a4d26 to 282a727 Compare August 4, 2015 12:55
@Metalaka
Copy link
Member Author

Metalaka commented Aug 4, 2015

yes, and it's done :)

*/
protected function _enclose($name)
{
if (0 === preg_match('#\s|\(#', $name)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 !== preg nop?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nop, we enclose the symbol only if there is NO space (alias) or parentheses (function).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok got it.

@Hywan
Copy link
Member

Hywan commented Aug 5, 2015

@Metalaka Seems excellent. Maybe a rebase would be welcome (not necessarily one commit). Waiting the go of @osaris, he's the peer-reviewer on this one.

@Metalaka
Copy link
Member Author

Metalaka commented Aug 5, 2015

Also, I was thinking, what about renaming “name” into “symbol”? I reckon it's more abstract and then it might be better because more reusable. Thoughts?

The problem with "enclose symbol" naming is:
we'll enclose symbols(ex-names) with symbols...

We can also rename name into identifier ?

@Hywan
Copy link
Member

Hywan commented Aug 5, 2015

@Metalaka: An identifier is most of the time unique. Name is not all the time correct. Symbol is good nop?

@Hywan
Copy link
Member

Hywan commented Aug 5, 2015

@Metalaka git commit --amend: “Add tests for EncolseNames feature.”, Enclose, not Encolse 😉.

@Metalaka
Copy link
Member Author

Metalaka commented Aug 5, 2015

Thanks for the typo :)
A table, column, alias name is unique in his query.
IMO symbol is too abstract and is not used for the same things in sql1992.

@Hywan
Copy link
Member

Hywan commented Aug 5, 2015

So let's go for identifier?

@Metalaka
Copy link
Member Author

Metalaka commented Aug 5, 2015

If you're ok ;)

@Metalaka
Copy link
Member Author

Metalaka commented Aug 5, 2015

Done, tests are green.

@Hywan
Copy link
Member

Hywan commented Aug 5, 2015

@Metalaka Waiting the peer-review of @osaris 😃.

@osaris
Copy link
Member

osaris commented Aug 6, 2015

Looks very good. Thanks @Metalaka very good job !

$this->_closingSymbol =
(null === $closingSymbol)
? $openingSymbol
: $closingSymbol;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->_closingSymbol = $closingSymbol ?: $openingSymbol;

may be better. Going to do it by myself.

@Bhoat Bhoat merged commit 9376a28 into hoaproject:master Aug 10, 2015
@Hywan Hywan removed the in progress label Aug 10, 2015
@Hywan
Copy link
Member

Hywan commented Aug 10, 2015

Awesome new feature, thank you very much!

@Hywan Hywan mentioned this pull request Aug 10, 2015
@Metalaka Metalaka deleted the encloseNames branch August 10, 2015 09:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

6 participants