Structuring code: using standalone SET and local variables in SQLpage #411
pchemguy
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
That's a good explanation. I think we should strive to improve the learning path; https://sql.ophir.dev/your-first-sql-website/ doesn't do a great job at helping people discover more than the the basics. @pchemguy , would you be interested in contributing to the documentation ? I have seen your advanced SQLite tutorial and you seem to have a talent for explaining technical concepts in an approachable manner. I think we could make SQLPage's documentation much better together. A good place to start would be opening a pull request targeting https://github.com/lovasoa/SQLpage/blob/main/examples/official-site/your-first-sql-website/tutorial.md |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am a new user of SQLpage and am still trying to figure out optimal ways of doing things using SQLite as my primary db engine (so the examples below will need to be adjusted to different engines).
I accidentally discovered the standalone "SET" statement (not available in plain SQLite/SQL), which can be used to define local variables, for example:
sets $sqlite_version to a string containing the version of the integrated SQLite library. This variable can then be used in the code.
When the query used to set a variable returns multiple rows/columns, the variable takes the value of the first column in the first row. In such a case, JSON can help pass around non-scalar values, for example:
sets $function_list to a JSON array containing a sorted list of available SQL functions.
A more practical example is to place the following code close to the beginning of the module:
Then $curpath can be appended, for example, to relative redirect links, so that the target of redirects could redirect back after processing (I may show code examples in a separate post).
Beta Was this translation helpful? Give feedback.
All reactions