[Qgis-user] Retrieve Postgis user from connection string
Karl Magnus Jönsson
Karl-Magnus.Jonsson at kristianstad.se
Wed Mar 22 00:26:35 PDT 2017
Hi Pietro!
Wouldn't a trigger do the job on the database side anyway? I have a trigger:
CREATE TRIGGER update_skotselobjekt_curuser
BEFORE UPDATE
ON park.skotselobjekt
FOR EACH ROW
EXECUTE PROCEDURE park.update_curuser_column();
That executes this trigger function:
CREATE OR REPLACE FUNCTION park.update_curuser_column()
RETURNS trigger AS
$BODY$
BEGIN
--IF row(NEW.*) IS DISTINCT FROM row(OLD.*) THEN
NEW.anvandare = current_user;
RETURN NEW;
--ELSE
-- RETURN OLD;
-- END IF;
END;
$BODY$
Works fine for me. I don't use the check "if the new row is distinct from the old" since small changes in geometry didn't get caught as a different record.
Karl-Magnus Jönsson
-----Ursprungligt meddelande-----
Från: Qgis-user [mailto:qgis-user-bounces at lists.osgeo.org] För Rossin Pietro
Skickat: den 21 mars 2017 17:16
Till: qgis-user at lists.osgeo.org
Ämne: [Qgis-user] Retrieve Postgis user from connection string
Hello
In qgis 2.18 is there some way to automatically get the user name used to load a postgis layer?
I need it to populate a table field qgis side, not postgis side (I know I can do the latest using a trigger).
On Postgis I use
IF NEW.user_inser is NULL or NEW.user_inser = '' then NEW.user_inser = (select current_user); END IF; IF NEW.user_modif is NULL or NEW.user_modif = '' then NEW.user_modif = (select current_user); END IF; NEW.data_inser = current_timestamp; NEW.data_modif = current_timestamp;
To trap a user who is inserting a new feature and set both insertion and modification user/data
Then If I want to get a user/data that updates a record, how can I do?
I mean as a user insert a feature or that feature is updated then next time I can't use
IF NEW.user_modif is NULL or NEW.user_modif = '' then NEW.user_modif = (select current_user);
And as I load this layer in legend Qgis doesn't change user_modif field.
So I'm searching a way to let Qgis change authomatically user_modif field on edit session
I tried to load a query like
select row_number() over(), current_user::text as user
To get the user of a given connection and it performs well but then How can I insert user value in user_modif field?
Any other better way??
Thanks
Pietro Rossin
AVVISO DI RISERVATEZZA Informazioni riservate possono essere contenute nel messaggio o nei suoi allegati. Se non siete i destinatari indicati nel messaggio, o responsabili per la sua consegna alla persona, o se avete ricevuto il messaggio per errore, siete pregati di non trascriverlo, copiarlo o inviarlo ad alcuno. In tal caso vi invitiamo a cancellare il messaggio ed i suoi allegati. Grazie.
CONFIDENTIALITY NOTICE Confidential information may be contained in this message or in its attachments. If you are not the addressee indicated in this message, or responsible for message delivering to that person, or if you have received this message in error, you may not transcribe, copy or deliver this message to anyone. In that case, you should delete this message and its attachments. Thank you.
_______________________________________________
Qgis-user mailing list
Qgis-user at lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
More information about the Qgis-user
mailing list