Skip to content

Proposal: Designated Placeholder Parameters for Prepared Statements #1450

@zhuangyan-stone

Description

@zhuangyan-stone

I have written a line of code as follows:

auto s = storage.prepare(select(columns(&User::id, &User::create_time) , where(substr(&O::create_time, -8) >= "12:00:00")));

the second parameter of substr, -8, is also a parameter. However, in practical scenarios, it rarely needs to be modified. As a result, I subconsciously perceive it as not being a parameter, which makes it easy to later write code like:

get<0>(s) = "18:00:00"; // The index of get<> should be 1.

Especially when there are multiple functions and parameters in the statement, it becomes even easier to use the wrong parameter index.

Is it possible to add another method, such as another_prepare (this is just an example; the actual name may vary), that allows users to specify which parameters should actually be replaced with question marks? The usage might look something like this:

auto s = storage.another_prepare(select(columns(&User::id, &User::create_time) , where(substr(&User::create_time, -8) >= Q("12:00:00"))));

The main change is the addition of a sqlite_orm::Q() function. Then, when generating the SQL statement, sqlite_orm would only convert the necessary parameters into question marks:

select id, create_time from user where substr(create_time, 8) >= ?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions