diff options
author | Steve Dibb <beandog@gentoo.org> | 2010-01-01 06:19:06 +0000 |
---|---|---|
committer | Steve Dibb <beandog@gentoo.org> | 2010-01-01 06:19:06 +0000 |
commit | 51c072ae2e570adb1c16d835003c50ed2fba126f (patch) | |
tree | a536888f6893520dc9ff118a498fb9981de4cb14 | |
parent | Run final imports (diff) | |
download | znurt-org-backend-51c072ae2e570adb1c16d835003c50ed2fba126f.tar.gz znurt-org-backend-51c072ae2e570adb1c16d835003c50ed2fba126f.tar.bz2 znurt-org-backend-51c072ae2e570adb1c16d835003c50ed2fba126f.zip |
add these because they are such a valuable reference
git-svn-id: file:///var/svn/portage@26 3218660a-b0cf-4799-a991-8ddcc5b9e0f3
-rw-r--r-- | functions.sql | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/functions.sql b/functions.sql new file mode 100644 index 0000000..176906b --- /dev/null +++ b/functions.sql @@ -0,0 +1,53 @@ +CREATE OR REPLACE FUNCTION package_id(atom varchar, OUT id integer) AS $$ +DECLARE + c varchar; + p varchar; +BEGIN + c := category_name(atom); + p := package_name(atom); + id := package_id(c, p); +END; +$$ language plpgsql; + +CREATE OR REPLACE FUNCTION category_id(atom varchar, OUT i integer) AS $$ + DECLARE c varchar; +BEGIN + c := category_name(atom); + i := id FROM category WHERE name = c; +END; +$$ language plpgsql; + +CREATE OR REPLACE FUNCTION category_name (str varchar, OUT v varchar) AS $$ BEGIN IF POSITION('/' IN str) > 0 THEN +v := regexp_replace(str, E'^(!{1,2})?(>|<)?(~|=)?', ''); +v := regexp_replace(v, E'/.*', ''); +ELSE +v := str; +END IF; +END; +$$ language plpgsql; + +CREATE OR REPLACE FUNCTION package_name(str varchar, OUT package_name varchar) AS $$ +BEGIN + +package_name := str; + +IF POSITION('/' IN str) > 0 THEN +package_name := regexp_replace(package_name, E'^(!{1,2})?(>|<)?(~|=)?.*/', ''); +END IF; + +IF POSITION('*' IN package_name) > 0 THEN +package_name := regexp_replace(package_name, E'\\*.*$', ''); +END IF; + +IF POSITION(':' IN package_name) > 0 THEN +package_name := regexp_replace(package_name, E':.+$', ''); +END IF; + +IF POSITION('[' IN package_name) > 0 THEN +package_name := regexp_replace(package_name, E'\\[.+$', ''); +END IF; + + +package_name := regexp_replace(package_name, E'-\\d+((\.\\d+)+)?([a-z])?((_(alpha|beta|pre|rc|p)\\d*)+)?(-r\\d+)?(:.+)?([.+])?$', ''); +END; +$$ language plpgsql;
\ No newline at end of file |