protected function getSetterSql($params, $declare, $setVars, $fields, $insertValues, UserQuery $pushMethod, $whereValues) { return "CREATE OR REPLACE FUNCTION {$this->setterFunctionName()}({$params}) " . "RETURNS integer AS \$\$ " . $declare . "BEGIN {$setVars} " . "UPDATE public.{$this->getTableName()} SET {$this->sender()->dataField()} = {$pushMethod->getQuery()} WHERE {$whereValues} RETURNING id INTO result; " . "IF result IS NULL THEN " . "INSERT INTO public.{$this->getTableName()} ({$fields}) VALUES({$insertValues}) " . "ON CONFLICT ON CONSTRAINT {$this->valueConstraint()} " . "DO UPDATE SET {$this->sender()->dataField()} = {$pushMethod->getQuery()} WHERE {$whereValues} " . "RETURNING id INTO result; " . "END IF; " . "RETURN result; " . "END; " . "\$\$ LANGUAGE plpgsql;"; }
protected function getSetterSql($params, $declare, $setVars, $fields, $insertValues, UserQuery $pushMethod, $whereValues) { $listDimension = $this->getDimension('dimension_day'); return "CREATE OR REPLACE FUNCTION {$this->setterFunctionName()}({$params}) " . "RETURNS setof integer AS \$\$ " . $declare . "BEGIN {$setVars} " . "FOR {$listDimension->getTableName()}_id_var IN SELECT * FROM public.get_{$listDimension->getTableName()}_id(\$2) LOOP " . "UPDATE public.{$this->getTableName()} SET {$this->sender()->dataField()} = {$pushMethod->getQuery()} WHERE {$whereValues} RETURNING id INTO result; " . "IF result IS NULL THEN " . "INSERT INTO public.{$this->getTableName()} ({$fields}) VALUES({$insertValues}) " . "ON CONFLICT ON CONSTRAINT {$this->valueConstraint()} " . "DO UPDATE SET {$this->sender()->dataField()} = {$pushMethod->getQuery()} WHERE {$whereValues} " . "RETURNING id INTO result; " . "END IF; " . "RETURN NEXT result; END LOOP;" . "END; " . "\$\$ LANGUAGE plpgsql;"; }