You are here

function transliteration_install_compat in Transliteration 6

Helper function; add database-specific compatibility functions.

2 calls to transliteration_install_compat()
transliteration_install in ./transliteration.install
Implementation of hook_install().
transliteration_update_1 in ./transliteration.install
Retroactively transliterate existing filenames.

File

./transliteration.install, line 22

Code

function transliteration_install_compat() {
  switch ($GLOBALS['db_type']) {
    case 'pgsql':

      // Taken from the MySQL Compatibility project
      // http://pgfoundry.org/projects/mysqlcompat/
      if (!db_result(db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'substring_index'"))) {
        db_query("CREATE OR REPLACE FUNCTION substring_index(text, text, integer)\n          RETURNS text AS \$\$\n            DECLARE\n              tokens text[];\n            BEGIN\n              tokens := pg_catalog.string_to_array(\$1, \$2); \n\n              IF \$3 >= 0 THEN\n                RETURN pg_catalog.array_to_string(tokens[1:\$3], \$2);\n              ELSE\n                RETURN pg_catalog.array_to_string(tokens[(\$3 * -1):pg_catalog.array_upper(tokens, 1)], \$2);\n              END IF;\n            END;\n          \$\$ IMMUTABLE STRICT LANGUAGE PLPGSQL;");
        break;
      }
  }
}