/** @brief Load a specified query from the database query tables. @param ctx Pointer to the current method context. @return Zero if successful, or -1 if not. Method parameters: - query id (key of query.stored_query table) Returns: a hash with two entries: - "token": A character string serving as a token for future references to the query. - "bind_variables" A hash of bind variables; see notes for doParamList(). */ int doPrepare( osrfMethodContext* ctx ) { if(osrfMethodVerifyContext( ctx )) { osrfLogError( OSRF_LOG_MARK, "Invalid method context" ); return -1; } // Get the query id from a method parameter const jsonObject* query_id_obj = jsonObjectGetIndex( ctx->params, 0 ); if( query_id_obj->type != JSON_NUMBER ) { osrfAppSessionStatus( ctx->session, OSRF_STATUS_BADREQUEST, "osrfMethodException", ctx->request, "Invalid parameter; query id must be a number" ); return -1; } int query_id = atoi( jsonObjectGetString( query_id_obj )); if( query_id <= 0 ) { osrfAppSessionStatus( ctx->session, OSRF_STATUS_BADREQUEST, "osrfMethodException", ctx->request, "Invalid parameter: query id must be greater than zero" ); return -1; } osrfLogInfo( OSRF_LOG_MARK, "Loading query for id # %d", query_id ); BuildSQLState* state = buildSQLStateNew( dbhandle ); state->defaults_usable = 1; state->values_required = 0; StoredQ* query = getStoredQuery( state, query_id ); if( state->error ) { osrfLogWarning( OSRF_LOG_MARK, "Unable to load stored query # %d", query_id ); osrfAppSessionStatus( ctx->session, OSRF_STATUS_BADREQUEST, "osrfMethodException", ctx->request, "Unable to load stored query" ); if( state->panic ) { osrfLogError( OSRF_LOG_MARK, sqlAddMsg( state, "Database connection isn't working" )); osrfAppSessionPanic( ctx->session ); } return -1; } const char* token = save_query( ctx, state, query ); osrfLogInfo( OSRF_LOG_MARK, "Token for query id # %d is \"%s\"", query_id, token ); // Build an object to return. It will be a hash containing the query token and a // list of bind variables. jsonObject* returned_obj = jsonNewObjectType( JSON_HASH ); jsonObjectSetKey( returned_obj, "token", jsonNewObject( token )); jsonObjectSetKey( returned_obj, "bind_variables", oilsBindVarList( state->bindvar_list )); osrfAppRespondComplete( ctx, returned_obj ); return 0; }
Querytextedit::Querytextedit(QWidget *parent) : QTextEdit(parent) { this->mainwindow = (Mainwindow*) parent; this->highlighter = new MySQLHighlighter(this->document()); this->mainwindow->hist_menu = new QMenu(); this->drinlassen = new QAction(tr("So lassen"), this); this->drinlassen->setCheckable(true); this->einzeln = new QAction(tr("nur eins"), this); this->einzeln->setCheckable(true); this->behavior = new QActionGroup(this); this->behavior->addAction(this->drinlassen); this->behavior->addAction(this->einzeln); this->einzeln->setChecked(true); this->save = new QAction(tr("Save"), this); this->save->setShortcut(QKeySequence::Save); this->load = new QAction(tr("Load"), this); this->load->setShortcut(QKeySequence::Open); this->mainwindow->hist_menu->addAction(this->drinlassen); this->mainwindow->hist_menu->addAction(this->einzeln); this->mainwindow->hist_menu->addSeparator(); this->mainwindow->hist_menu->addAction(this->save); this->mainwindow->hist_menu->addAction(this->load); connect(this->save, SIGNAL(triggered()), this, SLOT(save_query())); connect(this->load, SIGNAL(triggered()), this, SLOT(load_query())); connect(this, SIGNAL(textChanged()), this, SLOT(something_changed())); this->hist_position = 0; hist_something_changed = false; }