create table WAnswer( RequestId INTEGER, groupId INTEGER, error INTEGER, errorString varchar(255));CREATE OR REPLACE FUNCTION selAnswer(integer) RETURNS RECORD AS $$DECLARE id ALIAS FOR $1; rec RECORD;BEGIN SELECT * INTO rec from WAnswer WHERE RequestId = id; RETURN rec;END;$$ LANGUAGE plpgsql;
QSqlQuery answQuery(db);answQuery.prepare("SELECT selAnswer(:requestId)");answQuery.bindValue(":requestId", requestId);answQuery.exec();if(answQuery.next()){ int groupId = answQuery.value(1).toInt(); ...}
CREATE OR REPLACE FUNCTION selGroupFunctions(integer) RETURNS TABLE(RequestId_ INTEGER, funId_ INTEGER, enabled_ boolean) AS $$DECLARE id ALIAS FOR $1;BEGIN RETURN QUERY SELECT RequestId, funId, enabled from WGroupFunctions WHERE RequestId = id; END;$$ LANGUAGE plpgsql;
SELECT * FROM selAnswer(:requestId) as (col_name_1 type_of_col_1, ..., col_name_N type_of_col_N)
SELECT * FROM selAnswer(:requestId)
groupVars.groupId = answQuery.value(answRec.indexOf("groupId")).toInt();groupVars.error = answQuery.value(answRec.indexOf("error")).toInt();
CREATE FUNCTION selAnswer(integer) RETURNS SETOF WAnswer AS $$BEGIN RETURN QUERY SELECT * from WAnswer WHERE RequestId = $1;END;$$ LANGUAGE plpgsql;
QSqlQuery answQuery(db); answQuery.prepare("SELECT * from selAnswer(:requestId) "); answQuery.bindValue(":requestId", requestId); answQuery.exec(); QSqlRecord answRec = answQuery.record(); if(answQuery.next()){ groupVars.groupId = answQuery.value(answRec.indexOf("groupId")).toInt(); groupVars.error = answQuery.value(answRec.indexOf("error")).toInt(); groupVars.errorString = answQuery.value(answRec.indexOf("errorString")).toString(); ... }