Ejemplo n.º 1
0
 /**
  * return the column default value if it is defined
  *
  * @param SimpleXMLNode  $table_name   table definition xml node
  * @param string         $column_name  name of column to look up default value
  *
  * @return string column default value, null if not defined for the $column_name
  */
 public static function column_default_value(&$table_node, $column_name, &$node)
 {
     // find the column node in the table
     $nodes = static::inheritance_get_column($table_node, $column_name);
     if (is_null($nodes) || count($nodes) != 1) {
         throw new exception(count($nodes) . " column elements found via xpath '" . 'column[@name="' . $column_name . '"]' . "' - unexpected!");
     }
     $column_node =& $nodes[0];
     $default_value = NULL;
     // if it has a default value defined, use it
     if (isset($column_node['default']) && strlen($column_node['default']) > 0) {
         $default_value = dbsteward::string_cast($column_node['default']);
         if (strcasecmp($column_node['default'], 'null') == 0) {
             // the column is allowed to be null and the definition of default is null
             // so instead of setting the value, mark the column null
             dbsteward::trace('column_default_value ' . $table_node['name'] . '.' . $column_node['name'] . ' default null');
             $node['null'] = 'true';
         } else {
             dbsteward::trace('column_default_value ' . $table_node['name'] . '.' . $column_node['name'] . ' default value ' . $column_node['default']);
             $default_value = format::strip_string_quoting($default_value);
         }
     }
     return $default_value;
 }