db_tables (public)

 db_tables [ -pattern pattern ] [ -dbn dbn ]

Defined in packages/acs-tcl/tcl/01-database-procs.tcl

Switches:
-pattern (optional)
Will be used as LIKE 'pattern%' to limit the number of tables returned.
-dbn (optional)
The database name to use. If empty_string, uses the default database.
Returns:
a Tcl list of all the tables owned by the connected user.
Authors:
Don Baccus <dhogaza@pacifier.com>
Lars Pind <lars@pinds.com>
Changelog:
yon@arsdigita.com 20000711 changed to return lowercase table names

Partial Call Graph (max 5 caller/called nodes):
%3 db_driverkey db_driverkey (public) db_foreach db_foreach (public) db_tables db_tables db_tables->db_driverkey db_tables->db_foreach

Testcases:
No testcase defined.
Source code:
    set proc_name {db_tables}
    set driverkey [db_driverkey $dbn]

    switch -- $driverkey {
        oracle {
            set sql_table_names_with_pattern {
                select lower(table_name) as table_name
                from user_tables
                where table_name like upper(:pattern)
            }
            set sql_table_names_without_pattern {
                select lower(table_name) as table_name
                from user_tables
            }
        }

        postgresql {
            set sql_table_names_with_pattern {
                select relname as table_name
                from pg_class
                where relname like lower(:pattern) and
                relname !~ '^pg_' and relkind = 'r'
            }
            set sql_table_names_without_pattern {
                select relname as table_name
                from pg_class
                where relname !~ '^pg_' and relkind = 'r'
            }
        }

        nsodbc -
        default {
            error "$proc_name is not supported for this database."
        }
    }

    set tables [list]
    if { [info exists pattern] } {
        db_foreach -dbn $dbn table_names_with_pattern  $sql_table_names_with_pattern {
                lappend tables $table_name
            }
    } else {
        db_foreach -dbn $dbn table_names_without_pattern  $sql_table_names_without_pattern {
                lappend tables $table_name
            }
    }

    return $tables
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: