Created
May 21, 2012 10:22
-
-
Save gpongelli/2761683 to your computer and use it in GitHub Desktop.
Modified sqlValue member to address 'character varying', 'timestamp' cases. Fixes docblock and added some break. What's your thought about?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This function return a field value as a prepared string to be used in a SQL statement. | |
* | |
* @param array $columns Array of table's column returned by ::getTableColumns. | |
* @param string $field_name The table field's name. | |
* @param string $field_value The variable value to quote and return. | |
* | |
* @return string The quoted string. | |
* | |
* @since 11.3 | |
*/ | |
public function sqlValue($columns, $field_name, $field_value) | |
{ | |
switch ($columns[$field_name]) | |
{ | |
case 'boolean': | |
if ($field_value == 't') | |
{ | |
$field_value = true; | |
} | |
$val = is_bool($field_value) ? ( $field_value ? 'TRUE' : 'FALSE' ) : 'NULL'; | |
break; | |
case 'bigint': | |
case 'bigserial': | |
case 'integer': | |
case 'money': | |
case 'numeric': | |
case 'real': | |
case 'smallint': | |
case 'serial': | |
case 'character varying': | |
$val = strlen($field_value) == 0 ? 'NULL' : $field_value; | |
break; | |
case 'date': | |
case 'timestamp without time zone': | |
if (empty($field_value)) | |
{ | |
$field_value = $this->getNullDate(); | |
} | |
break; | |
default: | |
$val = $this->quote($field_value); | |
} | |
return $val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment