xo::db::require proc default
xo::db::require default
- Testcases:
- xotcl_core_tutorial_2, xotcl-core
Source code: set default [::acs::dc call util get_default -table $table -column $col] if {[db_driverkey ""] eq "oracle"} { # # Oracle behaves differently: one needs the "modify" # subcommand, the stunt with the case below raises exceptions # of several reasons (cast needs length, boolean value in # coalesce, ...). Furthermore, Oracle does not allow a bind # variable for the default value. # set default [string trim $default] if {$default ne $value} { ::xo::dc dml alter-table-$table "alter table $table modify $col default [ns_dbquotevalue $value]" } return } # # Newer versions of PostgreSQL return default values with type # casts (e.g. 'en_US'::character varying). In these cases, we # remove the type cast from the returned default value before # comparison. # # Depending on the generation and real datatype of the DBMS, # certain datatype values are reported differently from the # DBMS. Therefore, we use a type cast to check whether # specified default value (e.g. '1900-01-01') is in fact # equivalent to default stored in db (e.g. '1900-01-01 # 00:00:00+01'::timestamp with timezone). # # Booleans can be normalized in advance without involving the # database if { ($default eq "f" && $value eq "false") || ($default eq "t" && $value eq "true") } { set value $default } if {$default ne $value} { if {[regexp {^'(.*)'::(.*)$} $default match default_value default_datatype]} { set clause "$default <> cast(:value as $default_datatype)" } else { set datatype [db_column_type $table $col] set clause "cast(:default as $datatype) <> cast(:value as $datatype)" } # This last coalesce is in case one of the compared values # was null: as we know they were different, this is # certainly a new default if {[::xo::dc get_value check_default " select coalesce($clause, true) from dual"]} { ::xo::dc dml alter-table-$table "alter table $table alter column $col set default :value" } }XQL Not present: Generic, PostgreSQL, Oracle