Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set parameters from within SQLite?

I've been unable to figure out how to set parameters from within SQLite. I'm mainly using it for testing, and am designing my code so that it can be ported as easily as possible to another, yet to be determined, version of SQL. Normally, I use named parameters, and when testing queries internally, I will use the syantax @varname="value". I'll provide two examples below, showing how I would like to use parameters when testing.

This first example just sets and displays a variable.

@string="Example String";
SELECT @string;

This should return the contents of the variable, in this case: example string.

In the second example, the parameter is being used as part of a condition:

@param=Dark;
SELECT Title from table;
WHERE Title= '%' || @param || '%';

This should return results like the following:

Afterdark    
Alone in the Dark
The Darkness

etc.

like image 568
grandta13 Avatar asked Jul 20 '26 02:07

grandta13


1 Answers

SQLite is an embedded database, and designed to be used together with a 'real' programming language.

The only way to set parameter values is from outside SQL.

like image 178
CL. Avatar answered Jul 22 '26 16:07

CL.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!