Diff for /parser3/src/classes/void.C between versions 1.30 and 1.33

version 1.30, 2003/11/20 16:34:23 version 1.33, 2004/06/18 15:55:47
Line 1 Line 1
 /** @file  /** @file
         Parser: @b VOID parser class.          Parser: @b VOID parser class.
   
         Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
 */  */
   
Line 16  static const char * const IDENT_VOID_C=" Line 16  static const char * const IDENT_VOID_C="
 #include "pa_vvoid.h"  #include "pa_vvoid.h"
 #include "pa_sql_connection.h"  #include "pa_sql_connection.h"
   
   // externs
   
   extern String sql_bind_name;
   
 // class  // class
   
 class MVoid: public Methoded {  class MVoid: public Methoded {
Line 56  static void _double(Request& r, MethodPa Line 60  static void _double(Request& r, MethodPa
 }  }
   
 #ifndef DOXYGEN  #ifndef DOXYGEN
   static void marshal_bind(
                                                    HashStringValue::key_type aname, 
                                                    HashStringValue::value_type avalue,
                                                    SQL_Driver::Placeholder** pptr) 
   {
           SQL_Driver::Placeholder& ph=**pptr;
           ph.name=aname.cstr();
           ph.value=avalue->as_string().cstr();
           ph.is_null=avalue->get_class()==void_class;
           ph.were_updated=false;
   
           *pptr++;
   }
   
   // not static, used elsewhere
   int marshal_binds(HashStringValue& hash, SQL_Driver::Placeholder*& placeholders) {
           int hash_count=hash.count();
           placeholders=new(UseGC) SQL_Driver::Placeholder[hash_count];
           SQL_Driver::Placeholder* ptr=placeholders;
           hash.for_each(marshal_bind, &ptr);
           return hash_count;
   }
   
 class Void_sql_event_handlers: public SQL_Driver_query_event_handlers {  class Void_sql_event_handlers: public SQL_Driver_query_event_handlers {
         const String& statement_string;          const String& statement_string;
 public:  public:
Line 76  public: Line 103  public:
 static void _sql(Request& r, MethodParams& params) {  static void _sql(Request& r, MethodParams& params) {
         Value& statement=params.as_junction(0, "statement must be code");          Value& statement=params.as_junction(0, "statement must be code");
   
           HashStringValue* bind=0;
           if(params.count()>1) {
                   Value& voptions=params.as_no_junction(1, "options must be hash, not code");
                   if(!voptions.is_string())
                           if(HashStringValue* options=voptions.get_hash()) {
                                   int valid_options=0;
                                   if(Value* vbind=options->get(sql_bind_name)) {
                                           valid_options++;
                                           bind=vbind->get_hash();
                                   }
                                   if(valid_options!=options->count())
                                           throw Exception("parser.runtime",
                                                   0,
                                                   "called with invalid option");
                           } else
                                   throw Exception("parser.runtime",
                                           0,
                                           "options must be hash");
           }
   
           SQL_Driver::Placeholder* placeholders=0;
           uint placeholders_count=0;
           if(bind)
                   placeholders_count=marshal_binds(*bind, placeholders);
   
         Temp_lang temp_lang(r, String::L_SQL);          Temp_lang temp_lang(r, String::L_SQL);
         const String& statement_string=r.process_to_string(statement);          const String& statement_string=r.process_to_string(statement);
         const char* statement_cstr=          const char* statement_cstr=
                 statement_string.cstr(String::L_UNSPECIFIED, r.connection());                  statement_string.cstr(String::L_UNSPECIFIED, r.connection());
         Void_sql_event_handlers handlers(statement_string);          Void_sql_event_handlers handlers(statement_string);
         r.connection()->query(          r.connection()->query(
                 statement_cstr, 0, 0,                  statement_cstr, 
                   placeholders_count, placeholders,
                   0, 0,
                 handlers,                  handlers,
                 statement_string);                  statement_string);
 }  }
   
   static void _left_right(Request& r, MethodParams& params) {
           ssize_t sn=params.as_int(0, "n must be int", r);
           if(sn<0)
                   throw Exception("parser.runtime",
                           0, 
                           "n(%d) must be >=0", sn);
   
           // return nothing
   }
   
   static void _mid(Request& r, MethodParams& params) {
           ssize_t sbegin=params.as_int(0, "p must be int", r);
           if(sbegin<0)
                   throw Exception("parser.runtime",
                           0, 
                           "p(%d) must be >=0", sbegin);
   
           if(params.count()>1) {
                   ssize_t sn=params.as_int(1, "n must be int", r);
                   if(sn<0)
                           throw Exception("parser.runtime",
                                   0, 
                                   "n(%d) must be >=0", sn);
           }
   
           // return nothing
   }
   
 // constructor  // constructor
   
 MVoid::MVoid(): Methoded("void") {  MVoid::MVoid(): Methoded("void") {
Line 96  MVoid::MVoid(): Methoded("void") { Line 178  MVoid::MVoid(): Methoded("void") {
         // ^void.pos[substr]          // ^void.pos[substr]
         add_native_method("pos", Method::CT_DYNAMIC, _pos, 1, 1);          add_native_method("pos", Method::CT_DYNAMIC, _pos, 1, 1);
   
         // ^void.int[]           // ^void.int[]
         // ^void.int(default)          // ^void.int(default)
         add_native_method("int", Method::CT_DYNAMIC, _int, 0, 1);          add_native_method("int", Method::CT_DYNAMIC, _int, 0, 1);
   
         // ^void.double[]           // ^void.double[]
         // ^void.double(default)          // ^void.double(default)
         add_native_method("double", Method::CT_DYNAMIC, _double, 0, 1);          add_native_method("double", Method::CT_DYNAMIC, _double, 0, 1);
   
         // ^sql[query]          // ^sql[query]
         add_native_method("sql", Method::CT_STATIC, _sql, 1, 1);          add_native_method("sql", Method::CT_STATIC, _sql, 1, 2);
   
           // ^void.left() ^void.right()
           add_native_method("left", Method::CT_DYNAMIC, _left_right, 1, 1);
           add_native_method("right", Method::CT_DYNAMIC, _left_right, 1, 1);
   
           // ^void.mid(p;n)
           add_native_method("mid", Method::CT_DYNAMIC, _mid, 1, 2);
 }  }

Removed from v.1.30  
changed lines
  Added in v.1.33


E-mail: