xo::db::Attribute method column_spec (public)

 <instance of xo::db::Attribute[i]> column_spec \
    [ -id_column id_column ]

Defined in packages/xotcl-core/tcl/05-db-procs.tcl

Switches:
-id_column (optional, defaults to "false")
Returns:
the full SQL spec for a DB attribute, potentially containing defaults, primary key, constraints, etc.

Testcases:
No testcase defined.
Source code:
set table_name [${:domain} table_name]
set column_spec ""
append column_spec " " [::xo::dc map_datatype ${:sqltype}]
#
# Default
#
if {[info exists :default]} {
  append column_spec " DEFAULT '${:default}' "
}
#
# References
#
if {[info exists :references] && ${:references} ne ""} {
  append column_spec " REFERENCES ${:references}"
} elseif {$id_column} {
  set sc [${:domain} info superclass]
  if {![$sc istype ::xo::db::Class]} {set sc ::xo::db::Object}
  append column_spec " REFERENCES [$sc table_name]([$sc id_column]) ON DELETE CASCADE "
}
#
# Unique and Not NULL
#
if {[info exists :unique]}   {append column_spec " UNIQUE "  }
if {[info exists :not_null]} {append column_spec " NOT NULL "}
#
# Primary key
#
if {$id_column} {
  # add automatically a constraint for the id_column
  append column_spec " PRIMARY KEY "
}
append column_spec [::xo::dc datatype_constraint ${:sqltype} $table_name ${:name}]
return $column_spec
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: