Diff for /parser3/src/classes/array.C between versions 1.39 and 1.42

version 1.39, 2025/05/26 01:56:54 version 1.42, 2025/10/05 19:41:27
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");
                 }                  }
Line 588  static void _keys(Request& r, MethodPara Line 580  static void _keys(Request& r, MethodPara
         for(ArrayValue::Iterator i(array); i; i.next()){          for(ArrayValue::Iterator i(array); i; i.next()){
                 if(i.value()){                  if(i.value()){
                         Table::element_type row(new ArrayString(1));                          Table::element_type row(new ArrayString(1));
                         *row+=new String(i.key(), String::L_TAINTED);                          *row+=new String(pa_uitoa(i.index()));
                         *table+=row;                          *table+=row;
                 }                  }
         }          }
Line 692  static void _for(Request& r, MethodParam Line 684  static void _for(Request& r, MethodParam
         if(delim_maybe_code){ // delimiter set          if(delim_maybe_code){ // delimiter set
                 bool need_delim=false;                  bool need_delim=false;
                 for(ArrayValue::RobustIterator i(array); i; i.next()){                  for(ArrayValue::RobustIterator i(array); i; i.next()){
                         if(key_var_name){                          if(key_var_name)
                                 VString* vkey=new VString(i.key());                                  r.put_element(caller, *key_var_name, VString::uitoa(i.index()));
                                 r.put_element(caller, *key_var_name, vkey);  
                         }  
   
                         if(value_var_name)                          if(value_var_name)
                                 r.put_element(caller, *value_var_name, i.value() ? i.value() : VVoid::get());                                  r.put_element(caller, *value_var_name, i.value() ? i.value() : VVoid::get());
   
Line 718  static void _for(Request& r, MethodParam Line 707  static void _for(Request& r, MethodParam
                 }                  }
         } else {          } else {
                 for(ArrayValue::RobustIterator i(array); i; i.next()){                  for(ArrayValue::RobustIterator i(array); i; i.next()){
                         if(key_var_name){                          if(key_var_name)
                                 VString* vkey=new VString(i.key());                                  r.put_element(caller, *key_var_name, VString::uitoa(i.index()));
                                 r.put_element(caller, *key_var_name, vkey);  
                         }  
   
                         if(value_var_name)                          if(value_var_name)
                                 r.put_element(caller, *value_var_name, i.value() ? i.value() : VVoid::get());                                  r.put_element(caller, *value_var_name, i.value() ? i.value() : VVoid::get());
   
Line 752  static void _foreach(Request& r, MethodP Line 738  static void _foreach(Request& r, MethodP
                 bool need_delim=false;                  bool need_delim=false;
                 for(ArrayValue::RobustIterator i(array); i; i.next()){                  for(ArrayValue::RobustIterator i(array); i; i.next()){
                         if(i.value()){                          if(i.value()){
                                 if(key_var_name){                                  if(key_var_name)
                                         VString* vkey=new VString(i.key());                                          r.put_element(caller, *key_var_name, VString::uitoa(i.index()));
                                         r.put_element(caller, *key_var_name, vkey);  
                                 }  
   
                                 if(value_var_name)                                  if(value_var_name)
                                         r.put_element(caller, *value_var_name, i.value());                                          r.put_element(caller, *value_var_name, i.value());
   
Line 780  static void _foreach(Request& r, MethodP Line 763  static void _foreach(Request& r, MethodP
         } else {          } else {
                 for(ArrayValue::RobustIterator i(array); i; i.next()){                  for(ArrayValue::RobustIterator i(array); i; i.next()){
                         if(i.value()){                          if(i.value()){
                                 if(key_var_name){                                  if(key_var_name)
                                         VString* vkey=new VString(i.key());                                          r.put_element(caller, *key_var_name, VString::uitoa(i.index()));
                                         r.put_element(caller, *key_var_name, vkey);  
                                 }  
   
                                 if(value_var_name)                                  if(value_var_name)
                                         r.put_element(caller, *value_var_name, i.value());                                          r.put_element(caller, *value_var_name, i.value());
   
Line 845  static void _sort(Request& r, MethodPara Line 825  static void _sort(Request& r, MethodPara
         for(ArrayValue::RobustIterator i(array); i; i.next() ){          for(ArrayValue::RobustIterator i(array); i; i.next() ){
                 if(i.value()){                  if(i.value()){
                         if(key_var)                          if(key_var)
                                 r.put_element(*context, *key_var, new VString(i.key()));                                  r.put_element(*context, *key_var, VString::uitoa(i.index()));
                         if(value_var)                          if(value_var)
                                 r.put_element(*context, *value_var, i.value());                                  r.put_element(*context, *value_var, i.value());
   
Line 916  static void _at(Request& r, MethodParams Line 896  static void _at(Request& r, MethodParams
                 if(count == array.count()){                  if(count == array.count()){
 l1:                     switch(result_type) {  l1:                     switch(result_type) {
                                 case AtResultTypeKey:                                  case AtResultTypeKey:
                                         r.write(*new VString(pa_uitoa(pos)));                                          r.write(*VString::uitoa(pos));
                                         break;                                          break;
                                 case AtResultTypeValue:                                  case AtResultTypeValue:
                                         r.write(*array.get(pos));                                          r.write(*array.get(pos));
Line 933  l1:   switch(result_type) { Line 913  l1:   switch(result_type) {
                                 if(i.value() && !(pos--)){                                  if(i.value() && !(pos--)){
                                         switch(result_type) {                                          switch(result_type) {
                                                 case AtResultTypeKey:                                                  case AtResultTypeKey:
                                                         r.write(*new VString(i.key()));                                                          r.write(*VString::uitoa(i.index()));
                                                         break;                                                          break;
                                                 case AtResultTypeValue:                                                  case AtResultTypeValue:
                                                         r.write(*i.value());                                                          r.write(*i.value());
Line 1017  static void _select(Request& r, MethodPa Line 997  static void _select(Request& r, MethodPa
                         for(ArrayValue::ReverseIterator i(source_array); i; ){                          for(ArrayValue::ReverseIterator i(source_array); i; ){
                                 if(Value *value=i.prev()){ // here for correct i.key()                                  if(Value *value=i.prev()){ // here for correct i.key()
                                         if(key_var_name)                                          if(key_var_name)
                                                 r.put_element(caller, *key_var_name, new VString(i.key()));                                                  r.put_element(caller, *key_var_name, VString::uitoa(i.index()));
                                         if(value_var_name)                                          if(value_var_name)
                                                 r.put_element(caller, *value_var_name, value);                                                  r.put_element(caller, *value_var_name, value);
   
Line 1037  static void _select(Request& r, MethodPa Line 1017  static void _select(Request& r, MethodPa
                         for(ArrayValue::RobustIterator i(source_array); i; i.next() ){                          for(ArrayValue::RobustIterator i(source_array); i; i.next() ){
                                 if(Value *value=i.value()){                                  if(Value *value=i.value()){
                                         if(key_var_name)                                          if(key_var_name)
                                                 r.put_element(caller, *key_var_name, new VString(i.key()));                                                  r.put_element(caller, *key_var_name, VString::uitoa(i.index()));
                                         if(value_var_name)                                          if(value_var_name)
                                                 r.put_element(caller, *value_var_name, value);                                                  r.put_element(caller, *value_var_name, value);
   

Removed from v.1.39  
changed lines
  Added in v.1.42


E-mail: