Skip to content

add named parameter#43

Open
voku wants to merge 4 commits into
friends-of-reactphp:0.7.xfrom
voku:master
Open

add named parameter#43
voku wants to merge 4 commits into
friends-of-reactphp:0.7.xfrom
voku:master

Conversation

@voku

@voku voku commented Apr 28, 2018

Copy link
Copy Markdown

#41

voku added 2 commits April 28, 2018 02:04
... and TODO comment in "Binary" -> because of missing class

@clue clue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you very much for providing this PR!

I wonder if it makes sense to accept multiple arguments with an array each or maybe limit this to a single argument array à la bindParamsFromArray()? Also, the method definition being public and returning an array looks a bit odd to me. What do you think about this? 👍

voku added 2 commits April 29, 2018 00:05
e.g. composer -> "could not be downloaded (HTTP/1.1 404 Not Found)
@voku

voku commented Apr 28, 2018

Copy link
Copy Markdown
Author

Hi, method definition is private and will return only the new parsed sql-query as "string". The feature is now also working with bindParamsFromArray() and bindParams(), tested added.

@Sarke

Sarke commented Jul 1, 2019

Copy link
Copy Markdown

Hi @voku and @clue, can I ask why this is stagnant?

If you don't mind, I have some thoughts on the suggested implementation.

It doesn't allow multiple uses of a token.

$query = new Query('select * from test where name = :id or id = :id');
$sql = $query->bindParamsFromArray([':id' => 2])->getSql();
$this->assertEquals("select * from test where name = 2 or id = 2", $sql);

This will only replace the first token, not the subsequent ones.

-'select * from test where name = 2 or id = 2'
+'select * from test where name = 2 or id = :id'

It is not string aware.

$query = new Query('select * from test where name = ? or id = :id');
$sql = $query->bindParamsFromArray(["I'm a code sample like self::identify()", ':id' => 2])->getSql();
$this->assertEquals("select * from test where name = 'I'm a code sample self::identify()' or id = 2", $sql);
-'select * from test where name = 'I'm a code sample self::identify()' or id = 2'
+'select * from test where name = 'I\'m a code sample like self:2entify()' or id = :id'

That said, I would like to see this implemented, and could help out.

One thought is to use a SQL lexer like https://packagist.org/packages/phpmyadmin/sql-parser#4.3.2 to tokenize the SQL to make it easier to replace on only the token parts and/or validate the SQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants