|
|
| version 1.41, 2025/05/28 00:58:02 | version 1.43, 2026/04/25 13:38:46 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b array parser class. | Parser: @b array parser class. |
| Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com) | Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) |
| Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru> | Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru> |
| */ | */ |
| Line 452 static void _sql(Request& r, MethodParam | Line 452 static void _sql(Request& r, MethodParam |
| Table2hash_value_type value_type=C_HASH; | Table2hash_value_type value_type=C_HASH; |
| if(params.count()>1) | if(params.count()>1) |
| if(HashStringValue* options=params.as_hash(1, "sql options")) { | if(HashStringValue* options=params.as_hash(1, "sql options")) { |
| int valid_options=0; | |
| bool distinct_specified=false; | bool distinct_specified=false; |
| for(HashStringValue::Iterator i(*options); i; i.next() ){ | for(HashStringValue::Iterator i(*options); i; i.next() ){ |
| String::Body key=i.key(); | String::Body key=i.key(); |
| Value* value=i.value(); | Value* value=i.value(); |
| if(key == sql_bind_name) { | if(key == sql_bind_name) { |
| bind=value->get_hash(); | bind=value->get_hash(); |
| valid_options++; | |
| } else if(key == sql_limit_name) { | } else if(key == sql_limit_name) { |
| limit=(ulong)r.process(*value).as_double(); | limit=(ulong)r.process(*value).as_double(); |
| valid_options++; | |
| } else if(key == sql_offset_name) { | } else if(key == sql_offset_name) { |
| offset=(ulong)r.process(*value).as_double(); | offset=(ulong)r.process(*value).as_double(); |
| valid_options++; | |
| } else if (key == sql_distinct_name) { | } else if (key == sql_distinct_name) { |
| distinct=r.process(*value).as_bool(); | distinct=r.process(*value).as_bool(); |
| distinct_specified=true; | distinct_specified=true; |
| valid_options++; | |
| } else if (key == sql_value_type_name) { | } else if (key == sql_value_type_name) { |
| value_type=get_value_type(r.process(*value)); | value_type=get_value_type(r.process(*value)); |
| valid_options++; | |
| } else if (key == "sparse") { | } else if (key == "sparse") { |
| sparse=r.process(*value).as_bool(); | sparse=r.process(*value).as_bool(); |
| valid_options++; | } else |
| } | throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); |
| } | } |
| if(valid_options!=options->count()) | |
| throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); | |
| if(distinct_specified && !sparse) | if(distinct_specified && !sparse) |
| throw Exception(PARSER_RUNTIME, 0, "'distinct' option can only be used when $.sparse(true) is specified"); | throw Exception(PARSER_RUNTIME, 0, "'distinct' option can only be used when $.sparse(true) is specified"); |
| } | } |