You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'Executes another SQL file and returns its result as a JSON array.
12
+
13
+
### Example
14
+
15
+
#### Include a common header in all your pages
16
+
17
+
It is common to want to run the same SQL queries at the beginning of all your pages,
18
+
to check if an user is logged in, render a header, etc.
19
+
You can create a file called `common_header.sql`, and use the `dynamic` component with the `run_sql` function to include it in all your pages.
20
+
21
+
```sql
22
+
select ''dynamic'' as component, sqlpage.run_sql(''common_header.sql'') as contents;
23
+
```
24
+
25
+
#### Notes
26
+
27
+
- **recursion**: you can use `run_sql` to include a file that itself includes another file, and so on. However, be careful to avoid infinite loops. SQLPage will throw an error if it detects a loop.
28
+
- **security**: be careful when using `run_sql` to include files. Never use `run_sql` with a user-provided parameter. Never run a file uploaded by a user, or a file that is not under your control.
29
+
- **variables**: the included file will have access to the same variables (URL parameters, POST variables, etc.)
30
+
as the calling file. It will not have access to uploaded files.
31
+
If the included file changes the value of a variable or creates a new variable, the change will not be visible in the calling file.
32
+
'
33
+
);
34
+
INSERT INTO sqlpage_function_parameters (
35
+
"function",
36
+
"index",
37
+
"name",
38
+
"description_md",
39
+
"type"
40
+
)
41
+
VALUES (
42
+
'run_sql',
43
+
1,
44
+
'file',
45
+
'Path to the SQL file to execute, relative to the WEB ROOT (the root folder of your website).',
0 commit comments