Skip to content

Conversation

@lovasoa
Copy link
Collaborator

@lovasoa lovasoa commented Nov 19, 2025

Problem

URL parameters and form data could be overwritten by SET statements, making it impossible to access original request values after modification.

Solution

Request parameters (URL and POST) are now immutable. SET creates user-defined variables in a separate namespace that shadow request parameters during lookup.

Changes

Data Structure:

  • RequestInfo now has three variable maps:
    • url_params (immutable, from URL query string)
    • post_variables (immutable, from form data)
    • set_variables (mutable, from SET statements) using RefCell for interior mutability

Variable Lookup:

  • $var: checks set_variables → url_params (deprecation warning for post_variables)
  • :var: checks set_variables → post_variables
  • All SET statements write to set_variables only

API Simplification:

  • stream_query_results_with_conn and related functions now take &RequestInfo instead of &mut RequestInfo

New Functionality:

  • sqlpage.variables('set') returns only user-defined variables
  • sqlpage.variables('get') returns only URL parameters (immutable)
  • sqlpage.variables('post') returns only POST parameters (immutable)
  • sqlpage.variables() merges all with SET taking precedence

Documentation:

  • Updated extensions-to-sql.md with variable types and precedence rules
  • Updated 20_variables_function.sql migration with new 'set' filter

Tests:

  • Added it_works_immutable_variables.sql test
  • All 151 tests passing (110 unit + 41 integration)

Breaking Changes

None. Existing code continues to work with identical behavior.

- URL and POST parameters are now immutable after request initialization
- SET command creates user-defined variables in separate namespace
- Variable lookup: SET variables shadow request parameters
- Added sqlpage.variables('set') to inspect user-defined variables
- Simplified API: most functions now use &RequestInfo instead of &mut
- All tests passing (151 total)
@lovasoa lovasoa force-pushed the immutable-url-params branch from 173283c to d69b1d1 Compare November 19, 2025 01:11
- Warn when both URL and POST have same variable name
- Warn when $var is used for POST-only variable (should use :var)
No need to branch on whether variables are provided since we clone in both cases anyway.
@lovasoa lovasoa merged commit b11e7bf into main Nov 19, 2025
10 checks passed
@lovasoa lovasoa deleted the immutable-url-params branch November 19, 2025 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants