Beispiel #1
0
 /**
  * escape data types that need it
  *
  * @param mixed $value value to check for escaping
  *
  * @value mixed value, escaped as necessary
  */
 public static function value_escape($type, $value, $db_doc = NULL)
 {
     if (strlen($value) > 0) {
         // data types that should be quoted
         $enum_regex = dbx::enum_regex($db_doc);
         if (strlen($enum_regex) > 0) {
             $enum_regex = '|' . $enum_regex;
         }
         // complain when assholes use colon time notation instead of postgresql verbose for interval expressions
         if (dbsteward::$require_verbose_interval_notation) {
             if (preg_match('/interval/i', $type) > 0) {
                 if (substr($value, 0, 1) != '@') {
                     throw new exception("bad interval value: " . $value . " -- interval types must be postgresql verbose format: '@ 2 hours 30 minutes' etc for cfxn comparisons to work");
                 }
             }
         }
         // data types that should be quoted
         if (preg_match("/^bool.*|^character.*|^string|^text|^date|^time.*|^(?:var)?char.*|^interval|^money.*|^inet|uuid" . $enum_regex . "/i", $type) > 0) {
             $value = "'" . pg_escape_string($value) . "'";
             // data types that should have E prefix to their quotes
             if (pgsql8::E_ESCAPE && preg_match("/^character.*|^string|^text|^(?:var)?char.*/", $type) > 0) {
                 $value = 'E' . $value;
             }
         }
     } else {
         // value is zero length, make it NULL
         $value = "NULL";
     }
     return $value;
 }
Beispiel #2
0
 /**
  * escape data types that need it
  *
  * @param mixed $value value to check for escaping
  *
  * @value mixed value, escaped as necessary
  */
 public static function value_escape($type, $value, $db_doc = NULL)
 {
     if (strlen($value) > 0) {
         // data types that should be quoted
         $enum_regex = dbx::enum_regex($db_doc);
         if (strlen($enum_regex) > 0) {
             $enum_regex = '|' . $enum_regex;
         }
         $PATTERN_QUOTED_TYPES = "/^char.*|^string|^date.*|^time.*|^varchar.*|^interval|^money.*|^inet" . $enum_regex . "/i";
         // strip quoting if it is a quoted type, it will be added after conditional conversion
         if (preg_match($PATTERN_QUOTED_TYPES, $type) > 0) {
             $value = mysql5::strip_single_quoting($value);
         }
         // complain when assholes use colon time notation instead of postgresql verbose for interval expressions
         if (dbsteward::$require_verbose_interval_notation) {
             if (preg_match('/interval/i', $type) > 0) {
                 if (substr($value, 0, 1) != '@') {
                     throw new exception("bad interval value: " . $value . " -- interval types must be postgresql verbose format: '@ 2 hours 30 minutes' etc for cfxn comparisons to work");
                 }
             }
         }
         // mssql doesn't understand epoch
         if (stripos('date', $type) !== FALSE && strcasecmp($value, 'epoch') == 0) {
             $value = '1970-01-01';
         }
         // special case for postgresql type value conversion
         // the boolean type for the column would have been translated to char(1) by xml_parser::mysql5_type_convert()
         if (strcasecmp($type, 'char(1)') == 0) {
             $value = mysql5::boolean_value_convert($value);
         } else {
             if (strcasecmp($type, 'datetimeoffset(7)') == 0) {
                 $value = date('c', strtotime($value));
                 // use date()'s ISO 8601 date format to be conformant
             } else {
                 if (strcasecmp($type, 'datetime2') == 0) {
                     $value = date('Y-m-dTG:i:s', strtotime($value));
                     // use date() to make date format conformant
                 } else {
                     if (strcasecmp($type, 'time') == 0 && strlen($value) > 8) {
                         $value = substr($value, 0, 8);
                     }
                 }
             }
         }
         if (preg_match($PATTERN_QUOTED_TYPES, $type) > 0) {
             $value = static::quote_string_value($value);
         }
     } else {
         // value is zero length, make it NULL
         $value = "NULL";
     }
     return $value;
 }
 public static function enum_type_check($db_doc, $node_schema, $node_table, $node_column, &$drop_sql, &$add_sql)
 {
     // if the column type is a defined enum, (re)add a check constraint to enforce the pseudo-enum
     $foreign = array();
     $column_type = mssql10_column::column_type($db_doc, $node_schema, $node_table, $node_column, $foreign, FALSE);
     if (preg_match('/' . dbx::enum_regex($db_doc) . '/i', $column_type) > 0) {
         $type_schema_name = sql_parser::get_schema_name($column_type, $db_doc);
         $type_schema = dbx::get_schema($db_doc, $type_schema_name);
         $node_type = dbx::get_type($type_schema, sql_parser::get_object_name($column_type, $db_doc));
         if (!$node_type) {
             var_dump($node_type);
             throw new exception('failed to find column_type ' . $column_type . ' in type_schema_name ' . $type_schema_name);
         }
         $drop_sql = mssql10_type::get_drop_check_sql($node_schema, $node_table, $node_column, $node_type);
         $add_sql = mssql10_type::get_add_check_sql($node_schema, $node_table, $node_column, $node_type);
         return TRUE;
     }
     return FALSE;
 }