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

Relax the requirement for SQL to be a string #2969

Closed
JanZelenka opened this issue May 10, 2020 · 4 comments
Closed

Relax the requirement for SQL to be a string #2969

JanZelenka opened this issue May 10, 2020 · 4 comments
Labels
database Issues or pull requests that affect the database layer enhancement PRs that improve existing functionalities

Comments

@JanZelenka
Copy link

Hi!
I'm building a Database driver. The difficulty is that the database engine is queried using an API, not SQL. As a consequence the table (FROM clause) is a part of the API URL, not the query itself. I would find it helpful if the DB methods that work with the $sql parameter could be relaxed not to require strictly the string data type and allow an array as well.
Thanks for considering

CodeIgniter 4 version
4.0.3

Affected module(s)
Database

@JanZelenka JanZelenka added the bug Verified issues on the current code behavior or pull requests that will fix them label May 10, 2020
@MGatner
Copy link
Member

MGatner commented Aug 25, 2020

Could you provide an example of what you're talking about it?

@MGatner MGatner added enhancement PRs that improve existing functionalities database Issues or pull requests that affect the database layer waiting for info Issues or pull requests that need further clarification from the author and removed bug Verified issues on the current code behavior or pull requests that will fix them labels Aug 25, 2020
@JanZelenka
Copy link
Author

It goes like this:
I have a Builder class that creates the queries for me - which need to be in a JSON format. Also, since it is API based, the table name is a part of the URL but the where clause is in the body.
To properly use the Connection class I need to pass these array based queries as string, in my override of the execute() method convert them back to arrays, extract the different pieces of information and then convert back to string to use in the API call.

It's lot of converting back and forth that could be skipped if methods like simpleQuery(), execute() and so would allow for arrays to passed in.

@paulbalandan paulbalandan removed the waiting for info Issues or pull requests that need further clarification from the author label Oct 30, 2020
@lonnieezell
Copy link
Member

Unfortunately I don't think we can do that unless it is in the next major release. All of the current drivers have type-hinting of string. If anyone is using that to cast variables into a string for them it would be completely broken.

@MGatner
Copy link
Member

MGatner commented May 10, 2021

Stringables are accepted for string typehints, so you can accomplish this by passing a class with __toString() and you could use your arrays as an Iterable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Issues or pull requests that affect the database layer enhancement PRs that improve existing functionalities
Projects
None yet
Development

No branches or pull requests

4 participants