B4J Question About parameterized queries

vfafou

Well-Known Member
Licensed User
Longtime User
Hello!
I'm using parameterised queries since I've started writing with B4X.
These days I'm writing an expansion to one of my projects and I have been fallen to the following case:

B4X:
SQLQuery = "SELECT * FROM sometable "
SQLQuery = SQLQuery & "WHERE field1 = ? "
SQLQuery = SQLQuery & "AND field2 = ? "

if vSomeVariable = "X" then
    SQLQuery1 = " AND field3 in (SELECT f3 FROM sometable2 WHERE f1 = ? AND f2 = ?)"
end if

SQLQuery = SQLQuery & SQLQuery1

...

How to manipulate the ??s of the subquery since it is not always necessary?
I have to mention that I'm talking for a far more complex query structure than my example!

Would you think that it will be better if I write it as a stored function to the database?

Thank you in advance!
 
Last edited:

KMatle

Expert
Licensed User
Longtime User
What kind of db do you use? MySql? Normally you design a db and tables to fit your needs not "playing" with x kinds of different queries (which is a design mistake). Additionally: the performance can't be good, often with a slight change in the table structure you can reach it very easy.

Could you post the table structure and what you are trying to do wth it?
 
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
Store the queries in a map (key-value) .

B4X:
' RDC frame work config.properties
sql.insert_animal=INSERT INTO animals ( name ,doub)  VALUES (? , ? )
sql.select_animal=SELECT name, doub FROM animals WHERE name = ?
 
Upvote 0
Top