Annotation of parser3/src/classes/void.C, revision 1.1
1.1 ! parser 1: /** @file
! 2: Parser: @b VOID parser class.
! 3:
! 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
! 5:
! 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
! 7:
! 8: $Id: VOID.C,v 1.4 2001/05/21 17:19:49 parser Exp $
! 9: */
! 10:
! 11: #include "classes.h"
! 12: #include "pa_request.h"
! 13: #include "pa_vint.h"
! 14: #include "pa_vdouble.h"
! 15: #include "pa_vvoid.h"
! 16: #include "pa_sql_connection.h"
! 17:
! 18: // defines
! 19:
! 20: #define VOID_CLASS_NAME "void"
! 21:
! 22: // class
! 23:
! 24: class MVoid : public Methoded {
! 25: public:
! 26: MVoid(Pool& pool);
! 27: public: // Methoded
! 28: bool used_directly() { return true; }
! 29: };
! 30:
! 31: // methods
! 32:
! 33: static void _int(Request& r, const String&, MethodParams *) {
! 34: Pool& pool=r.pool();
! 35: VInt *vunknown=static_cast<VInt *>(r.self);
! 36: Value& value=*new(pool) VInt(pool, vunknown->as_int());
! 37: r.write_no_lang(value);
! 38: }
! 39:
! 40: static void _double(Request& r, const String&, MethodParams *) {
! 41: Pool& pool=r.pool();
! 42: VInt *vunknown=static_cast<VInt *>(r.self);
! 43: Value& value=*new(pool) VDouble(pool, vunknown->as_double());
! 44: r.write_no_lang(value);
! 45: }
! 46:
! 47: static void _sql(Request& r, const String& method_name, MethodParams *params) {
! 48: Pool& pool=r.pool();
! 49:
! 50: if(!r.connection)
! 51: PTHROW(0, 0,
! 52: &method_name,
! 53: "without connect");
! 54:
! 55: Value& statement=params->get_junction(0, "statement must be code");
! 56:
! 57: Temp_lang temp_lang(r, String::UL_SQL);
! 58: const String& statement_string=r.process(statement).as_string();
! 59: const char *statement_cstr=
! 60: statement_string.cstr(String::UL_UNSPECIFIED, r.connection);
! 61: unsigned int sql_column_count; SQL_Driver::Cell *sql_columns;
! 62: unsigned long sql_row_count; SQL_Driver::Cell **sql_rows;
! 63: bool need_rethrow=false; Exception rethrow_me;
! 64: PTRY {
! 65: r.connection->query(
! 66: statement_cstr, 0, 0,
! 67: &sql_column_count, &sql_columns,
! 68: &sql_row_count, &sql_rows);
! 69: }
! 70: PCATCH(e) { // connect/process problem
! 71: rethrow_me=e; need_rethrow=true;
! 72: }
! 73: PEND_CATCH
! 74: if(need_rethrow)
! 75: PTHROW(rethrow_me.type(), rethrow_me.code(),
! 76: &statement_string, // setting more specific source [were url]
! 77: rethrow_me.comment());
! 78:
! 79: // there are some result rows, which is wrong
! 80: if(sql_row_count)
! 81: PTHROW(0, 0,
! 82: &statement_string,
! 83: "must not return result");
! 84: }
! 85:
! 86: // constructor
! 87:
! 88: MVoid::MVoid(Pool& apool) : Methoded(apool) {
! 89: set_name(*NEW String(pool(), VOID_CLASS_NAME));
! 90:
! 91:
! 92: // ^VOID.int[]
! 93: add_native_method("int", Method::CT_DYNAMIC, _int, 0, 0);
! 94:
! 95: // ^VOID.double[]
! 96: add_native_method("double", Method::CT_DYNAMIC, _double, 0, 0);
! 97:
! 98: // ^sql[query]
! 99: add_native_method("sql", Method::CT_STATIC, _sql, 1, 1);
! 100: }
! 101:
! 102: // global variable
! 103:
! 104: Methoded *void_class;
! 105:
! 106: // creator
! 107:
! 108: Methoded *MVoid_create(Pool& pool) {
! 109: return void_class=new(pool) MVoid(pool);
! 110: }
E-mail: