From 29a8cd2abffc6a422142cef31961e316441d42f7 Mon Sep 17 00:00:00 2001 From: linuxpoet Date: Tue, 24 Oct 2006 01:01:52 +0000 Subject: added functions create_user and update_user.. see docs git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@274 4979c152-3d1c-0410-bac9-87ea11338e46 --- sql/Pg-tables.sql | 17 +++++++++++++++++ sql/Pg-upgrade-2.6.18-2.6.19.sql | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/sql/Pg-tables.sql b/sql/Pg-tables.sql index d512ccbb..5201e55e 100755 --- a/sql/Pg-tables.sql +++ b/sql/Pg-tables.sql @@ -757,3 +757,20 @@ COMMENT ON COLUMN users_conf.password IS 'This means we have to get rid of the c -- The two below statements must be run from a single session INSERT INTO users(username) VALUES ('admin'); INSERT INTO users_conf(id,password) VALUES (currval('users_id_seq'),NULL); + + +CREATE FUNCTION create_user(text) RETURNS int4 AS $$ + INSERT INTO users(username) VALUES ('$1'); + SELECT 1; + $$ LANGUAGE 'SQL'; + +COMMENT ON FUNCTION create_user(text) IS $$ Function to create user. Returns 1 if successful, else it is an error. $$; + +CREATE FUNCTION update_user(int4,text) RETURNS int4 AS $$ + UPDATE users SET username = '$2' WHERE id = $1; + SELECT 1; + $$ LANGUAGE 'SQL'; + +COMMENT ON FUNCTION update_user(int4,text) IS $$ Takes int4 which is users.id and text which is username. Will update username based on id. Username is unique $$; + + diff --git a/sql/Pg-upgrade-2.6.18-2.6.19.sql b/sql/Pg-upgrade-2.6.18-2.6.19.sql index f06f661e..ce34ab29 100644 --- a/sql/Pg-upgrade-2.6.18-2.6.19.sql +++ b/sql/Pg-upgrade-2.6.18-2.6.19.sql @@ -189,4 +189,20 @@ COMMIT; BEGIN; INSERT INTO users(username) VALUES ('admin'); INSERT INTO users_conf(id,password) VALUES (currval('users_id_seq'),NULL); -COMMIT; \ No newline at end of file +COMMIT; + +-- Functions + +CREATE FUNCTION create_user(text) RETURNS int4 AS $$ + INSERT INTO users(username) VALUES ('$1'); + SELECT 1; + $$ LANGUAGE 'SQL'; + +COMMENT ON FUNCTION create_user(text) IS $$ Function to create user Returns 1 if successful, else it is an error. $$; + +CREATE FUNCTION update_user(int4,text) RETURNS int4 AS $$ + UPDATE users SET username = '$2' WHERE id = $1; + SELECT 1; + $$ LANGUAGE 'SQL'; + +COMMENT ON FUNCTION update_user(int4,text) IS $$ Takes int4 which is users.id and text which is username. Will update username based on id. Username is unique $$; -- cgit v1.2.3