xo::db::require proc index (public)
xo::db::requireindex [ -table table ] [ -col col ] \ [ -expression expression ] [ -expression_name expression_name ] \ [ -using using ] [ -unique unique ]
Defined in /var/www/openacs/packages/xotcl-core/tcl/05-db-procs.tcl
Create the named-by-convention index if it is missing. Supply either a column list or an expression.
- Switches:
- -table (optional)
- Table to index.
- -col (optional)
- Comma-separated column list.
- -expression (optional)
- SQL expression to index.
- -expression_name (optional)
- Optional name component for an expression index.
- -using (optional)
- Optional index access method for PostgreSQL.
- -unique (optional, defaults to
"false")- Whether to create a unique index.
- Testcases:
- xotcl_core_tutorial_2
Source code: if {![info exists col] && ![info exists expression]} { error "Neither col nor expression were provided" } if { [info exists col] && [info exists expression]} { error "Please provide either col or expression" } if {[info exists col]} { set colExpSQL $col regsub -all -- ", *" $col _ colExpName } else { set colExpSQL ($expression) if {[info exists expression_name]} { set colExpName $expression_name } else { regsub -all -- {[^[:alnum:]]} $expression "" colExpName } } set suffix [expr {$unique ? "un_idx" : "idx"}] set uniquepart [expr {$unique ? "UNIQUE" : ""}] set name [::xo::dc mk_sql_constraint_name $table $colExpName $suffix] if {![::acs::dc call util index_exists -name $name]} { if {[db_driverkey ""] eq "oracle"} {set using ""} set using [expr {$using ne "" ? "using $using" : ""}] ::xo::dc dml create-index-$name "create $uniquepart index $name ON $table $using ($colExpSQL)" }XQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)