if ($this->default == "''") $this->default = '';
# NB 12.12.17 if (strtoupper($this->default) == "NULL") $this->default = null;
#if (strtoupper($this->default) == "NOW()") $this->default = null;
+ if (strtoupper($this->default) == "NOW()") $this->default = $this->date_microtime();
+ if (strtoupper($this->default) == "CURRENT_TIMESTAMP)") $this->default = $this->date_microtime();
if (strtoupper($this->default) == "NOW()") $this->default = date("Y-m-d H:i:s.u");
if (strtoupper($this->default) == "CURRENT_TIMESTAMP)") $this->default = date("Y-m-d H:i:s.u");
if (strtoupper($this->default) == "CURRENT_DATE)") $this->default = date("Y-m-d");
}
public function replace($hvalues,&$info=[]) {
- # NB 12.12.17: When REPLACE is not supported where call a personalized function
+ # NB 12.12.17: When REPLACE is not supported where call a personalized function to modify $sql
$fct = $this->db()->conf_type('replace_insert');
if (!empty($fct)) {
- $info['sql_fct'] = $fct;
+ $info['fct'] = $fct;
return $this->insert($hvalues,$info);
}
return $this->insert($hvalues,$info,'REPLACE');
if (empty($info['values'])) $info['values'] = [];
if (empty($post)) $this->bye('insert(): No values');
- $info['values'] = $post;
-
$sql_names = $fields = $values = [];
foreach ($this->fields() as $name => $field) {
- #if (!isset($post[$this->field_preff.$name]) and isset($field->default))
- if (!isset($post[$this->field_preff.$name])) continue;
if ($field->key and $field->autoincrement()) continue;
+ if (!isset($post[$this->field_preff.$name])) {
+
+ # For postgres and replace mode, we want to update timestamp for example
+ if (!empty($info['fct']) and isset($field->default)) {
+ $post[$this->field_preff.$name] = $field->default;
+ } else {
+ continue;
+ }
+
+ }
+
$fields[$name] = $field;
$sql_names[$name] = $field->sql_name();
$values[] = $post[$this->field_preff.$name];
.' VALUES (' . join(',',ar_map('":$a"',array_keys($fields))) . ')'
;
- if (!empty($info['sql_fct'])) {
- $fct = $info['sql_fct'];
+ if (!empty($info['fct'])) {
+ $fct = $info['fct'];
+ unset($info['fct']);
$fct($sql,$this,$fields);
}
$info['sql'] = $sql;
return false;
}
+ $info['values'] = $post;
+
foreach ($fields as $name => $field) {
$row = [ $name => $post[$name] ];
$this->db()->table_row_encrypt($this,$row);
} # < ldap_search
+ public static function date_microtime($format='Y-m-d H:i:s') {
+ #return date("Y-m-d H:i:s.u");
+ $micro_date = microtime();
+ $date_array = explode(" ",$micro_date);
+
+ $date = date($format,$date_array[1]);
+
+ $date_array[0] = preg_replace('/^.*?\D/','',$date_array[0]);
+
+ return $date . '.' . $date_array[0];
+ }
} # < Class NB
/*