Skip to content

Commit

Permalink
Merge pull request #107 from SiLVA-Project/master
Browse files Browse the repository at this point in the history
 support for 'NOW()', 'CURDATE()', 'CURTIME()', 'CURRENT_TIMESTAMP()', 'CURRENT_TIMESTAMP()'
  • Loading branch information
cyberscribe committed Nov 29, 2015
2 parents 0ec6c41 + 9fc6b95 commit 32e7061
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions core/models/mvc_database_adapter.php
Expand Up @@ -120,11 +120,22 @@ public function get_where_sql_clauses($conditions, $options=array()) {
if (strpos($key, '.') === false && $use_table_alias) {
$key = $this->defaults['model_name'].'.'.$key;
}
if (!is_null($value)) {
$operator = preg_match('/\s+(<|>|<=|>=|<>|\!=|[\w\s]+)/', $key) ? ' ' : ' = ';

$operator = preg_match('/\s+(<|>|<=|>=|<>|\!=|IS|[\w\s]+)/', $key) ? ' ' : ' = ';

$functions = array('NULL', 'NOW()', 'CURDATE()', 'CURTIME()', 'CURRENT_TIMESTAMP()', 'CURRENT_TIMESTAMP()');

if(in_array($value, $functions) || is_null($value)){
if((is_null($value) || $value === 'NULL')){
if(trim($operator) == "=")
$operator = " IS ";
else if(trim($operator) == "!=")
$operator = " IS NOT ";
}
$sql_clauses[] = $this->escape($key).$operator.$value;
}
else{
$sql_clauses[] = $this->escape($key).$operator.'"'.$this->escape($value).'"';
} else {
$sql_clauses[] = $this->escape($key).' IS NULL';
}
}
return $sql_clauses;
Expand Down Expand Up @@ -170,7 +181,12 @@ public function get_insert_columns_sql($data) {
public function get_insert_values_sql($data) {
$values = array();
foreach ($data as $value) {
$values[] = '"'.$this->escape($value).'"';
if($value == null){
$values[] = 'NULL';
}
else{
$values[] = '"'.$this->escape($value).'"';
}
}
$sql = '('.implode(', ', $values).')';
return $sql;
Expand Down

0 comments on commit 32e7061

Please sign in to comment.