I am trying to build a system where SQL parameters gets automatically bound to new queries. According to this thread:
SQL Server - Invalid characters in parameter names
The @, _ and # characters should be allowed inside identifiers. So I tried to build parameters as:
:tablename#fieldname
But when doing do I get error:
PBdatabase.select_query: [1] DB[2] prepare() SELECT * FROM creature WHERE pk = :creature#pk [near "#pk": syntax error]
It seems it does not like the # character, I tried with the underscore, it seem to work but I am already using the underscore in field names. This is why I wanted to use a different character.
Since the thread above talked about SQL server, the restricted characters could be different in SQLITE. I found the list of SQLITE restricted keywords, but not characters.
Does anybody know which other special character I could use?
Update
Somebody want to know what use I have for this. Here is an example, let say you have 2 tables with a 1 to N relationship: Fleet contains ships.
You want to display a form made of 2 blocks, where the top display 1 selected fleet at the time. Where the bottom block list all the ships in the fleet.
The first block query will be something like:
SELECT pk, number, location FROM fleet;
Then the fields of the selected entry will be put in a registry of field with the following names (Assuming the # symbol would be valid):
:fleet#pk
:fleet#number
:fleet#location
Then the second query for the second block would be ran including the registered fields above. So the query would look like:
SELECT pk, fk_fleet, name FROM ship WHERE fk_fleet = :fleet#pk
This query use a parameter from the query above. The identifier will be replaced by the value from the previous query. This allow to display only the ships linked with the selected fleet above instead of all the ships available.
Now some of you might say that I could simply save the variables I want and pass them in parameter to the next query. The problem is that all the queries are loaded from a database. I actually don't know which query I am going to run and which value I will need to save for another query. Instead I save them all in a registry and if another SQL statement ask for a parameter, the value will be available.