attribute::datatype_to_sql_type (private)

 attribute::datatype_to_sql_type [ -default default ] table column \
    datatype

Defined in packages/acs-subsite/tcl/attribute-procs.tcl

Returns the appropriate sql type for a table definition based on the table, column, datatype, and default value. Note that for default values, this proc automatically generates appropriate constraint names as well.

Switches:
-default
(optional)
If specified, we add a default clause to the SQL statement
Parameters:
table
column
datatype
Author:
Michael Bryzek <mbryzek@arsdigita.com>
Created:
12/2000

Partial Call Graph (max 5 caller/called nodes):
%3 attribute::add attribute::add (public) attribute::datatype_to_sql_type attribute::datatype_to_sql_type attribute::add->attribute::datatype_to_sql_type plsql_utility::generate_constraint_name plsql_utility::generate_constraint_name (public) attribute::datatype_to_sql_type->plsql_utility::generate_constraint_name

Testcases:
No testcase defined.
Source code:
        set type ""
        set constraint ""

        switch -- $datatype {
            "string" { set type "varchar(1000)" }
            "boolean" { set type "char(1)"
                        set constraint "[plsql_utility::generate_constraint_name $table $column "ck"] check ($column in ('t','f'))" }
            "number" { set type "number" }
            "money" { set type "number (12,2)" }
            "date" { set type "date" }
            "text" { set type "varchar(4000)" }
            "integer" { set type "integer" }
            "enumeration" { set type "varchar(100)" }
            "keyword" { set type "varchar(1000)" }
            default {error "Unsupported datatype. Datatype $datatype is not implemented at this time"}
        }

        set sql "$type"

        if { $default ne "" } {
            # This is also pretty nasty - we have to make sure we
            # treat db literals appropriately - null is much different
            # than 'null' - mbryzek
            set vars [list null sysdate]
            if {[string tolower $default] ni $vars} {
                set default "'$default'"
            }
            append sql " default $default"
        }
        if { $constraint ne "" } {
            append sql " constraint $constraint"
        }
        return $sql
Generic XQL file:
packages/acs-subsite/tcl/attribute-procs.xql

PostgreSQL XQL file:
packages/acs-subsite/tcl/attribute-procs-postgresql.xql

Oracle XQL file:
packages/acs-subsite/tcl/attribute-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: