plsql_utility::generate_oracle_name (public)

 plsql_utility::generate_oracle_name [ -max_length max_length ] \
    [ -include_object_id include_object_id ] stem

Defined in packages/acs-subsite/tcl/plsql-utility-procs.tcl

Returns an object name of max_length characters, in lowercase, beginning with stem but without any unsafe characters. Only allowed characters are numbers, letter, underscore, dash and space, though the returned word will start with a letter. Throws an error if no safe name could be generated. To almost guarantee uniqueness, you can use the next object_id from acs_object_id_seq as the tail of the name we return.

Switches:
-max_length
(defaults to "30") (optional)
-include_object_id
(defaults to "f") (optional)
Parameters:
stem
Author:
Michael Bryzek <mbryzek@arsdigita.com>
Created:
11/2000

Partial Call Graph (max 5 caller/called nodes):
%3 attribute::add attribute::add (public) plsql_utility::generate_oracle_name plsql_utility::generate_oracle_name attribute::add->plsql_utility::generate_oracle_name attribute::exists_p attribute::exists_p (public) attribute::exists_p->plsql_utility::generate_oracle_name group_type::new group_type::new (public) group_type::new->plsql_utility::generate_oracle_name packages/acs-subsite/www/admin/group-types/new.tcl packages/acs-subsite/ www/admin/group-types/new.tcl packages/acs-subsite/www/admin/group-types/new.tcl->plsql_utility::generate_oracle_name packages/acs-subsite/www/admin/rel-types/new-2.tcl packages/acs-subsite/ www/admin/rel-types/new-2.tcl packages/acs-subsite/www/admin/rel-types/new-2.tcl->plsql_utility::generate_oracle_name db_nextval db_nextval (public) plsql_utility::generate_oracle_name->db_nextval

Testcases:
No testcase defined.
Source code:

        if { $include_object_id == "t" } {
            set id [db_nextval "acs_object_id_seq"]
            set suffix "_$id"
        } else {
            set suffix ""
        }
        # Leave only letters, numbers, underscores, dashes, and spaces
        regsub -all -- {[^ _\-a-z0-9]} [string tolower $stem"" stem
        # Make sure it starts with a letter
        regsub {^[^a-z]} $stem "" stem

        # change spaces to underscores
        regsub -all -- {\s+} $stem "_" stem
        #Trim to fit in $max_length character limit
        set max_length_without_suffix [expr {$max_length - [string length $suffix]}]
        if { [string length $stem] >= $max_length_without_suffix } {
            set stem [string range $stem 0 $max_length_without_suffix-1]
        }
        if { $stem eq "" } {
            error "generate_oracle_name failed to generate a safe oracle name from the stem \"$stem\"\n"
        }
        return "$stem$suffix"
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: