View Issue Details

IDProjectCategoryView StatusLast Update
0005557Composrcorepublic2024-03-27 13:51
ReporterPatrick SchmalstigAssigned ToPatrick Schmalstig 
SeverityFeature-request 
Status closedResolutionno change required 
Product Version 
Fixed in Version 
Summary0005557: Support multi-dimensional arrays in where query for _get_where_expand
DescriptionAdd support for the following in the where array passed to _get_where_expand:

* <, >, <=, >= support... via ['field_name' => ['<=' => value]]
 - WHERE (field_name <= value)

* LIKE support, via ['field_name' => ['LIKE' => 'value%']]
 - Uses db_encode_like
 - WHERE field_name LIKE 'value%'

* <> and != support via ['field_name' => ['!=' => not_value]] (SQL <> for numbers, db_string_not_equal_to for strings; != is just an alias)
 - WHERE (field_name <> not_value)

* OR conditions, via ['field_name' => ['possible_value_1', 'possible_value_2'...]]
 - WHERE (field_name IN ('possible_value_1', 'possible_value_2'))

* NOR conditions, via ['field_name' => ['!=' => ['value1', 'value2'...]]]
 - WHERE (field_name NOT IN ('value1', 'value2'))

* AND conditions with operators, via ['field_name' => ['>' => value, '<=' => value2]]
 - WHERE (field_name > value AND field_name <= value2)

* OR conditions with operators, via ['field_name' => [['>' => value], ['<=' => value2]]] (though this might be useless)
 - WHERE (field_name > value OR field_name <= value2)

Adding these supports will drastically reduce the amount of times we need to use $end or just a flat query instead of more efficient query_select / query_select_value / etc.
Additional Information* Implement support for this in v11
* Consider using this as a standard in v12

Need to carefully consider this implementation; make sure all SQL drivers will support it. Adapt accordingly. Document it. Unit test it.
TagsRisk: Changes core website behaviour, Roadmap: Over the horizon, Roadmap: v11 partial implementation
Time estimation (hours)
Sponsorship open

Activities

Patrick Schmalstig

2024-01-18 19:00

administrator   ~0008203

This could also be incorporated into our frameworks for conposr and conposr++ for nice ORM-like support

Chris Graham

2024-03-24 18:51

administrator   ~0008419

I think it'd be more flexible, a lot less new code, and perhaps easier for the developer, just to use parameterised queries for these cases. See query_parameterised.

Patrick Schmalstig

2024-03-25 16:57

administrator   ~0008437

That makes sense. I had no idea that existed as I've never used it or seen it.

Chris Graham

2024-03-27 13:35

administrator   ~0008454

It was added because at some point I realised that it was bad that there was a percentage of queries our abstractions couldn't handle cleanly, forcing people to write SQL, and I know most people do not know how to write SQL securely. So it was never used, but it was put there as an important tool for developers to be able to use.

(As an aside, I interviewed someone for my bay area employer the other day, an experienced programmer and team leader - and they didn't know how to assemble native SQL to avoid SQL injections. That kind of demonstrates why parameterised queries are important.)

Patrick Schmalstig

2024-03-27 13:51

administrator   ~0008461

I can see that. Raw SQL is a very bad idea whenever user input is involved (I wouldn't even use it for the most trusted of users because an accidental unescaped character could cause chaos). And parameterised queries help do some of the escaping for you.

Issue History

Date Modified Username Field Change
2024-01-18 02:31 Patrick Schmalstig New Issue
2024-01-18 02:31 Patrick Schmalstig Status non-assigned => assigned
2024-01-18 02:31 Patrick Schmalstig Assigned To => Patrick Schmalstig
2024-01-18 02:32 Patrick Schmalstig Tag Attached: Risk: Changes core website behaviour
2024-01-18 02:32 Patrick Schmalstig Tag Attached: Roadmap: v11 partial implementation
2024-01-18 02:32 Patrick Schmalstig Tag Attached: Roadmap: v12
2024-01-18 02:33 Patrick Schmalstig Additional Information Updated View Revisions
2024-01-18 02:34 Patrick Schmalstig Description Updated View Revisions
2024-01-18 02:36 Patrick Schmalstig Description Updated View Revisions
2024-01-18 02:37 Patrick Schmalstig Description Updated View Revisions
2024-01-18 19:00 Patrick Schmalstig Note Added: 0008203
2024-03-24 18:51 Chris Graham Note Added: 0008419
2024-03-25 16:57 Patrick Schmalstig Note Added: 0008437
2024-03-25 16:58 Patrick Schmalstig Status assigned => closed
2024-03-25 16:58 Patrick Schmalstig Resolution open => no change required
2024-03-26 00:58 Patrick Schmalstig Tag Renamed Roadmap: v12 => Roadmap: Over the horizon
2024-03-27 13:35 Chris Graham Note Added: 0008454
2024-03-27 13:51 Patrick Schmalstig Note Added: 0008461