From 8dbd8bd7ea3d9aabc49adbf22cb87b6f635414cd Mon Sep 17 00:00:00 2001 From: lovasoa Date: Mon, 4 Mar 2024 16:47:25 +0100 Subject: [PATCH 01/33] WIP: sqlpage.run_sql --- src/webserver/database/sql_pseudofunctions.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/webserver/database/sql_pseudofunctions.rs b/src/webserver/database/sql_pseudofunctions.rs index bf34eca1..bf90de8b 100644 --- a/src/webserver/database/sql_pseudofunctions.rs +++ b/src/webserver/database/sql_pseudofunctions.rs @@ -38,6 +38,7 @@ pub(super) enum StmtParam { UploadedFileMimeType(String), ReadFileAsText(Box), ReadFileAsDataUrl(Box), + RunSql(Box), Path, Protocol, } @@ -107,6 +108,7 @@ pub(super) fn func_call_to_param(func_name: &str, arguments: &mut [FunctionArg]) "read_file_as_data_url" => StmtParam::ReadFileAsDataUrl(Box::new( extract_variable_argument("read_file_as_data_url", arguments), )), + "run_sql" => StmtParam::RunSql(Box::new(extract_variable_argument("run_sql", arguments))), unknown_name => StmtParam::Error(format!( "Unknown function {unknown_name}({})", FormatArguments(arguments) @@ -126,6 +128,7 @@ pub(super) async fn extract_req_param<'a>( StmtParam::UrlEncode(inner) => url_encode(inner, request)?, StmtParam::ReadFileAsText(inner) => read_file_as_text(inner, request).await?, StmtParam::ReadFileAsDataUrl(inner) => read_file_as_data_url(inner, request).await?, + StmtParam::RunSql(inner) => run_sql(inner, request).await?, _ => extract_req_param_non_nested(param, request)?, }) } @@ -248,6 +251,17 @@ async fn read_file_as_data_url<'a>( Ok(Some(Cow::Owned(data_url))) } +async fn run_sql<'a>( + param0: &StmtParam, + request: &'a RequestInfo, +) -> Result>, anyhow::Error> { + let Some(sql_file) = extract_req_param_non_nested(param0, request)? else { + log::debug!("run_sql: first argument is NULL, returning NULL"); + return Ok(None); + }; + todo!("run_sql: {sql_file:?}"); +} + fn mime_from_upload<'a>(param0: &StmtParam, request: &'a RequestInfo) -> Option<&'a Mime> { if let StmtParam::UploadedFilePath(name) | StmtParam::UploadedFileMimeType(name) = param0 { request.uploaded_files.get(name)?.content_type.as_ref() @@ -308,8 +322,9 @@ pub(super) fn extract_req_param_non_nested<'a>( .map(|x| Cow::Borrowed(x.as_ref())), StmtParam::ReadFileAsText(_) => bail!("Nested read_file_as_text() function not allowed",), StmtParam::ReadFileAsDataUrl(_) => { - bail!("Nested read_file_as_data_url() function not allowed",) + bail!("Nested read_file_as_data_url() function not allowed") } + StmtParam::RunSql(_) => bail!("Nested run_sql() function not allowed"), }) } From 75d7c460405e3e425138faa19eaa064877311990 Mon Sep 17 00:00:00 2001 From: olivierauverlot Date: Mon, 4 Mar 2024 16:08:17 +0100 Subject: [PATCH 02/33] A unique identifier for the input, which can then be used to select and manage the field with Javascript code. (#250) Co-authored-by: Olivier Auverlot --- .../sqlpage/migrations/01_documentation.sql | 3 ++- sqlpage/templates/form.handlebars | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/official-site/sqlpage/migrations/01_documentation.sql b/examples/official-site/sqlpage/migrations/01_documentation.sql index a3876da0..5ce9d6b9 100644 --- a/examples/official-site/sqlpage/migrations/01_documentation.sql +++ b/examples/official-site/sqlpage/migrations/01_documentation.sql @@ -237,7 +237,8 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S ('class', 'A CSS class to apply to the form element.', 'TEXT', FALSE, TRUE), ('prefix_icon','Icon to display on the left side of the input field, on the same line.','ICON',FALSE,TRUE), ('prefix','Text to display on the left side of the input field, on the same line.','TEXT',FALSE,TRUE), - ('suffix','Short text to display after th input, on the same line. Useful to add units or a currency symbol to an input.','TEXT',FALSE,TRUE) + ('suffix','Short text to display after th input, on the same line. Useful to add units or a currency symbol to an input.','TEXT',FALSE,TRUE), + ('id','A unique identifier for the input, which can then be used to select and manage the field with Javascript code. Usefull for advanced using as setting client side event listeners, interactive control of input field (disabled, visibility, read only, e.g.) and AJAX requests.','TEXT',FALSE,TRUE) ) x; INSERT INTO example(component, description, properties) VALUES ( diff --git a/sqlpage/templates/form.handlebars b/sqlpage/templates/form.handlebars index 74db9fd9..db1fcdf5 100644 --- a/sqlpage/templates/form.handlebars +++ b/sqlpage/templates/form.handlebars @@ -16,7 +16,7 @@ {{#if (or (eq type "radio") (eq type "checkbox"))}}