Bug fix Class DB IO data write function
The data write function did not write data correctly if it was empty or null. Especially for boolean ones when set 0 was set NULL and not 'f'. This is fixed now. Also filles MUST set not null fields with 0/'' but does not add missing column to list yet
This commit is contained in:
@@ -88,15 +88,22 @@
|
||||
|
||||
# db write class test
|
||||
$table = 'foo';
|
||||
print "TABLE META DATA: ".$basic->print_ar($basic->db_show_table_meta_data($table))."<br>";
|
||||
$primary_key = ''; # unset
|
||||
$db_write_table = array ('test', 'some_bool');
|
||||
$db_write_table = array ('test', 'string_a', 'number_a', 'some_bool');
|
||||
// $db_write_table = array ('test');
|
||||
$object_fields_not_touch = array ();
|
||||
$object_fields_not_update = array ();
|
||||
$data = array ('test' => 'BOOL TEST SOMETHING '.time());
|
||||
$data = array ('test' => 'BOOL TEST SOMETHING '.time(), 'string_a' => 'SOME TEXT', 'number_a' => 5);
|
||||
$primary_key = $basic->db_write_data_ext($db_write_table, $primary_key, $table, $object_fields_not_touch, $object_fields_not_update, $data);
|
||||
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
|
||||
$data = array ('test' => 'BOOL TEST OFF '.time(), 'some_bool' => 1);
|
||||
$data = array ('test' => 'BOOL TEST ON '.time(), 'string_a' => '', 'number_a' => 0, 'some_bool' => 1);
|
||||
$primary_key = $basic->db_write_data_ext($db_write_table, $primary_key, $table, $object_fields_not_touch, $object_fields_not_update, $data);
|
||||
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
|
||||
$data = array ('test' => 'BOOL TEST OFF '.time(), 'string_a' => null, 'number_a' => null, 'some_bool' => 0);
|
||||
$primary_key = $basic->db_write_data_ext($db_write_table, $primary_key, $table, $object_fields_not_touch, $object_fields_not_update, $data);
|
||||
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
|
||||
$data = array ('test' => 'BOOL TEST UNSET '.time());
|
||||
$primary_key = $basic->db_write_data_ext($db_write_table, $primary_key, $table, $object_fields_not_touch, $object_fields_not_update, $data);
|
||||
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
|
||||
|
||||
|
||||
@@ -1714,10 +1714,18 @@ $this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[
|
||||
$_data = $GLOBALS[$field];
|
||||
$has_default = $table_data[$field]['has default'];
|
||||
$not_null = $table_data[$field]['not null'];
|
||||
// if not null and string => '', if not null and int or numeric => 0, if bool => skip, all others skip
|
||||
if ($not_null && !isset($_data))
|
||||
{
|
||||
if (strstr($table_data[$field]['type'], 'int') || strstr($table_data[$field]['type'], 'numeric'))
|
||||
$_data = 0;
|
||||
else
|
||||
$_data = '';
|
||||
}
|
||||
// we detect bool, so we can force a write on "false"
|
||||
$is_bool = $table_data[$field]['type'] == 'bool' ? true : false;
|
||||
// write if the field has to be not null, or if there is no data and the field has no default values or if there is data or if this is an update and there is no data (set null)
|
||||
if (($not_null && !$_data) || (!$has_default && !$_data) || (is_numeric($_data) && isset($_data)) || ($primary_key['value'] && !$_data) || $_data)
|
||||
if (($not_null && isset($_data)) || (!$has_default && !isset($_data)) || (is_numeric($_data) && isset($_data)) || ($primary_key['value'] && !isset($_data)) || isset($_data))
|
||||
{
|
||||
if ($q_sub_value && !$primary_key['value'])
|
||||
$q_sub_value .= ', ';
|
||||
@@ -1735,7 +1743,7 @@ $this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[
|
||||
$q_sub_data .= (is_numeric($_data) && isset($_data)) ? $_data : 'NULL';
|
||||
else
|
||||
// if bool -> set bool, else write data
|
||||
$q_sub_data .= $_data ? "'".($is_bool ? $this->db_boolean($_data, true) : $this->db_escape_string($_data))."'" : 'NULL';
|
||||
$q_sub_data .= isset($_data) ? "'".($is_bool ? $this->db_boolean($_data, true) : $this->db_escape_string($_data))."'" : 'NULL';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user