Skip to content

Instantly share code, notes, and snippets.

@gpongelli
Created May 21, 2012 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpongelli/2761683 to your computer and use it in GitHub Desktop.
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 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