::xotcl::Object
::xo::db::require
::xotcl::Object create ::xo::db::require
Methods
proc exists_table
::xowiki::policy5 proc exists_table name {
if {[db_driverkey ""] eq "oracle"} {
set name [string toupper $name]
} else {
set name [string tolower $name]
}
::xo::db_0or1row "" [subst [my set [db_driverkey ""]_table_exists]]
}
::xo::db::require
function_args \
[ -kernel_older_than kernel_older_than ] \
[ -package_key_and_version_older_than package_key_and_version_older_than ] \
[ -check_function check_function ] sql_file
Load the sql file, if the the kernel is older than the
specified version, and the version of the specified package is older,
and the check_function does not exist in function_args.
Sample usage:
::xo::db::require function_args \
-kernel_older_than 5.5.0 \
-older_than_package_key_and_version "xowiki 0.50" \
-check_function "acs_object_type__create_type" \
[acs_package_root_dir xotcl-request-broker]/patches/funcs-1.sql
- Switches:
- -kernel_older_than (optional)
- -package_key_and_version_older_than (optional)
- -check_function (optional)
- Parameters:
-
sql_file
::xowiki::policy5 proc function_args {-kernel_older_than -package_key_and_version_older_than -check_function sql_file} {
if {[db_driverkey ""] eq "postgresql"} {
# only necessary with postgres
if {[info exists kernel_older_than]} {
if {[apm_version_names_compare $kernel_older_than [ad_acs_version]] < 1} {
# nothing to do
return
}
}
if {[info exists package_key_and_version_older_than]} {
set p [split $package_key_and_version_older_than]
if {[llength $p] != 2} {
error "package_key_and_version_older_than should be of the form 'package_key version'"
}
foreach {package_key version} $p break
set installed_version [apm_highest_version_name $package_key]
if {[apm_version_names_compare $installed_version $version] > -1} {
# nothing to do
return
}
}
if {[info exists check_function]} {
set check_function [string toupper $check_function]
set function_exists [::xo::db_string query_version {
select 1 from acs_function_args where function = :check_function
limit 1
} 0]
if {$function_exists} {
# nothing to do
return
}
}
if {[file readable $sql_file]} {
my log "Sourcing '$sql_file'"
db_source_sql_file $sql_file
::xo::db::Class create_all_functions
return 1
} else {
my log "Could not source '$sql_file'"
}
}
return 0
}
proc index
::xowiki::policy5 proc index {-table -col {-using ""} {-unique false}} {
set colpart $col
regsub -all ", *" $colpart _ colpart
set suffix [expr {$unique ? "un_idx" : "idx"}]
set uniquepart [expr {$unique ? "UNIQUE" : ""}]
set name [::xo::db::mk_sql_constraint_name $table $colpart $suffix]
if {![::xo::db_0or1row "" [subst [my set [db_driverkey ""]_index_exists]]]} {
if {[db_driverkey ""] eq "oracle"} {set using ""}
set using [expr {$using ne "" ? "using $using" : ""}]
db_dml [my qn create-index-$name] "create $uniquepart index $name ON $table $using ($col)"
}
}
proc package
::xowiki::policy5 proc package package_key {
if {![my exists required_package($package_key)]} {
foreach path [apm_get_package_files -package_key $package_key -file_types tcl_procs] {
# Use apm_source instead of source to prevent double
# sourcing by the apm_loader (temporary solution, double
# sourcing should no happen)
uplevel #1 apm_source "[acs_root_dir]/packages/$package_key/$path"
}
my set required_package($package_key) 1
}
}
proc table
::xowiki::policy5 proc table {name definition} {
if {![my exists_table $name]} {
#my log "--table $name does not exist, creating with $definition"
db_dml [my qn create-table-$name] "create table $name ($definition)"
}
}
proc view
::xowiki::policy5 proc view {name definition} {
if {[db_driverkey ""] eq "oracle"} {set name [string toupper $name]}
if {![::xo::db_0or1row "" [subst [my set [db_driverkey ""]_view_exists]]]} {
db_dml [my qn create-view-$name] "create view $name AS $definition"
}
}