xo::db::Class instproc check_table_atts (public)

 <instance of xo::db::Class[i]> check_table_atts

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

Check table_name and id_column and set meaningful defaults, if these attributes are not provided.

Partial Call Graph (max 5 caller/called nodes):
%3 test_xotcl_core_tutorial_2 xotcl_core_tutorial_2 (test xotcl-core) xo::db::Class instproc check_table_atts xo::db::Class instproc check_table_atts test_xotcl_core_tutorial_2->xo::db::Class instproc check_table_atts test_xotcl_core_tutorial_3 xotcl_core_tutorial_3 (test xotcl-core) test_xotcl_core_tutorial_3->xo::db::Class instproc check_table_atts test_xotcl_core_tutorial_4 xotcl_core_tutorial_4 (test xotcl-core) test_xotcl_core_tutorial_4->xo::db::Class instproc check_table_atts

Testcases:
xotcl_core_tutorial_2, xotcl_core_tutorial_3, xotcl_core_tutorial_4
Source code:
:check_default_values
set table_name_error_tail ""
set id_column_error_tail ""

if {![info exists :sql_package_name]} {
  set :sql_package_name [self]
  #:log "-- sql_package_name of [self] is '${:sql_package_name}'"
}
if {[string length ${:sql_package_name}] > 30} {
  error "SQL package_name '${:sql_package_name}' can be maximal 30 characters long! Please specify a shorter sql_package_name in the class definition."
}
if {${:sql_package_name} eq ""} {
  error "Cannot determine SQL package_name. Please specify it explicitly!"
}

if {![info exists :table_name]} {
  set tail [namespace tail [self]]
  regexp {^::([^:]+)::} [self] _ head
  :table_name [string tolower ${head}_$tail]
  #:log "-- table_name of [self] is '[:table_name]'"
  set table_name_error_tail ", or use different namespaces/class names"
}

if {![info exists :id_column]} {
  set :id_column [string tolower [namespace tail [self]]]_id
  set id_column_error_tail ", or use different class names"
  #:log "-- created id_column '[:id_column]'"
}

if {![regexp {^[[:alpha:]_][[:alnum:]_]*$} [:table_name]]} {
  error "Table name '[:table_name]' is unsafe in SQL:  Please specify a different table_name$table_name_error_tail."
}

if {[string length [:table_name]] > 30} {
  error "SQL table_name '[:table_name]' can be maximal 30 characters long! Please specify a shorter table_name in the class definition."
}

if {![regexp {^[[:alpha:]_][[:alnum:]_]*$} [:id_column]]} {
  error "Name for id_column '[:id_column]' is unsafe in SQL:  Please specify a different id_column$id_column_error_tail"
}
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: