/** * escape a column's value, or return the default value if none specified * * @NOTE: it is critical to note that colmn values should always be escaped with this function * as it also converts MSSQL specific values from postgresql ones * * @return string */ public static function column_value_default($node_schema, $node_table, $data_column_name, $node_col) { // if marked, make it null or default, depending on column options if (isset($node_col['null']) && strcasecmp('true', $node_col['null']) == 0) { return 'NULL'; } // columns that specify empty attribute are made empty strings if (isset($node_col['empty']) && strcasecmp('true', $node_col['empty']) == 0) { return "''"; } // don't esacape columns marked literal sql values if (isset($node_col['sql']) && strcasecmp($node_col['sql'], 'true') == 0) { return '(' . $node_col . ')'; } $node_column = dbx::get_table_column($node_table, $data_column_name); if ($node_column === NULL) { throw new exception("Failed to find table " . $node_table['name'] . " column " . $data_column_name . " for default value check"); } $value_type = mysql5_column::column_type(dbsteward::$new_database, $node_schema, $node_table, $node_column); // else if col is zero length, make it default, or DB NULL if (strlen($node_col) == 0) { // is there a default defined for the column? $dummy_data_column = new stdClass(); $column_default_value = xml_parser::column_default_value($node_table, $data_column_name, $dummy_data_column); if ($column_default_value != NULL) { // run default value through value_escape to allow data value conversions to happen $value = mysql5::value_escape($value_type, $column_default_value); } else { $value = 'NULL'; } } else { $value = mysql5::value_escape($value_type, dbsteward::string_cast($node_col)); } return $value; }