Added db generate uuid function. The postgresql implementation depends on the contrib module contrib/uuid-ossp.

This commit is contained in:
Heng Sin Low 2011-01-11 17:29:58 +08:00
parent 440f3a7c43
commit 75a5355937
3 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,28 @@
/*
*This file is part of Adempiere ERP Bazaar
*http://www.adempiere.org
*
*This program is free software; you can redistribute it and/or
*modify it under the terms of the GNU General Public License
*as published by the Free Software Foundation; either version 2
*of the License, or (at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program; if not, write to the Free Software
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.of
*/
create or replace function generate_uuid return varchar as
guid varchar(32);
uuid varchar(36);
begin
guid := lower(sys_guid());
uuid := substr(guid, 1, 8) || '-' || substr(guid, 9, 4) || '-' || substr(guid, 13, 4) || '-' || substr(guid, 17, 4) || '-' || substr(guid, 21, 12);
return uuid;
end;
/

View File

@ -0,0 +1,26 @@
/*
*This file is part of Adempiere ERP Bazaar
*http://www.adempiere.org
*
*This program is free software; you can redistribute it and/or
*modify it under the terms of the GNU General Public License
*as published by the Free Software Foundation; either version 2
*of the License, or (at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program; if not, write to the Free Software
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.of
*/
CREATE OR REPLACE FUNCTION generate_uuid()
RETURNS char(36) AS $$
BEGIN
return uuid_generate_v4()::char(36);
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT;

View File

@ -0,0 +1,54 @@
/* $PostgreSQL: pgsql/contrib/uuid-ossp/uuid-ossp.sql.in,v 1.6 2007/11/13 04:24:29 momjian Exp $ */
-- Adjust this setting to control where the objects get created.
SET search_path = public;
CREATE OR REPLACE FUNCTION uuid_nil()
RETURNS uuid
AS '$libdir/uuid-ossp', 'uuid_nil'
IMMUTABLE STRICT LANGUAGE C;
CREATE OR REPLACE FUNCTION uuid_ns_dns()
RETURNS uuid
AS '$libdir/uuid-ossp', 'uuid_ns_dns'
IMMUTABLE STRICT LANGUAGE C;
CREATE OR REPLACE FUNCTION uuid_ns_url()
RETURNS uuid
AS '$libdir/uuid-ossp', 'uuid_ns_url'
IMMUTABLE STRICT LANGUAGE C;
CREATE OR REPLACE FUNCTION uuid_ns_oid()
RETURNS uuid
AS '$libdir/uuid-ossp', 'uuid_ns_oid'
IMMUTABLE STRICT LANGUAGE C;
CREATE OR REPLACE FUNCTION uuid_ns_x500()
RETURNS uuid
AS '$libdir/uuid-ossp', 'uuid_ns_x500'
IMMUTABLE STRICT LANGUAGE C;
CREATE OR REPLACE FUNCTION uuid_generate_v1()
RETURNS uuid
AS '$libdir/uuid-ossp', 'uuid_generate_v1'
VOLATILE STRICT LANGUAGE C;
CREATE OR REPLACE FUNCTION uuid_generate_v1mc()
RETURNS uuid
AS '$libdir/uuid-ossp', 'uuid_generate_v1mc'
VOLATILE STRICT LANGUAGE C;
CREATE OR REPLACE FUNCTION uuid_generate_v3(namespace uuid, name text)
RETURNS uuid
AS '$libdir/uuid-ossp', 'uuid_generate_v3'
IMMUTABLE STRICT LANGUAGE C;
CREATE OR REPLACE FUNCTION uuid_generate_v4()
RETURNS uuid
AS '$libdir/uuid-ossp', 'uuid_generate_v4'
VOLATILE STRICT LANGUAGE C;
CREATE OR REPLACE FUNCTION uuid_generate_v5(namespace uuid, name text)
RETURNS uuid
AS '$libdir/uuid-ossp', 'uuid_generate_v5'
IMMUTABLE STRICT LANGUAGE C;