Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e85bf5ee8 | ||
|
|
ff94efee8d | ||
|
|
93f2cf9b73 | ||
|
|
c39e48a709 | ||
|
|
1cc010818d | ||
|
|
1e164f3b93 |
@@ -1 +0,0 @@
|
||||
smarty-3.1.27/
|
||||
@@ -88,14 +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');
|
||||
$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' => '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' => '');
|
||||
$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>";
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@
|
||||
// queue key
|
||||
if (preg_match("/^(add|save|delete|remove|move|up|down|push_live)$/", $this->action))
|
||||
{
|
||||
$this->queue_key = join('', array_map(create_function('', '$range = $GLOBALS["_KEY_RANGE"]; return $range[rand(0, (count($range) - 1))];'), range(1, 3)));
|
||||
$this->queue_key = join('', array_map(function () { $range = $GLOBALS['_KEY_RANGE']; return $range[rand(0, (count($range) - 1))]; }, range(1, 3)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -661,14 +661,14 @@
|
||||
{
|
||||
$this->pk_name_table[$table] = $this->db_functions->_db_primary_key($table, $schema);
|
||||
}
|
||||
$this->pk_name = $this->pk_name_table[$table];
|
||||
$this->pk_name = $this->pk_name_table[$table] ? $this->pk_name_table[$table] : 'NULL';
|
||||
}
|
||||
if (!preg_match("/ returning /i", $this->query) && $this->pk_name)
|
||||
if (!preg_match("/ returning /i", $this->query) && $this->pk_name && $this->pk_name != 'NULL')
|
||||
{
|
||||
$this->query .= " RETURNING ".$this->pk_name;
|
||||
$this->returning_id = true;
|
||||
}
|
||||
elseif (preg_match("/ returning (.*)/i", $this->query, $matches) && $this->pk_name)
|
||||
elseif (preg_match("/ returning (.*)/i", $this->query, $matches) && $this->pk_name && $this->pk_name != 'NULL')
|
||||
{
|
||||
// add the primary key if it is not in the returning set
|
||||
if (!preg_match("/$this->pk_name/", $matches[1]))
|
||||
@@ -714,7 +714,7 @@
|
||||
if (!$this->cursor || $this->db_functions->_db_last_error_query())
|
||||
{
|
||||
// printout Query if debug is turned on
|
||||
if (!$this->db_debug)
|
||||
if ($this->db_debug)
|
||||
$this->_db_debug('db', $this->query, 'db_exec', 'Q[nc]');
|
||||
// internal error handling
|
||||
$this->error_id = 13;
|
||||
@@ -763,7 +763,7 @@
|
||||
$this->insert_id[] = $_insert_id;
|
||||
}
|
||||
// if we have only one, revert from array to single
|
||||
if (count($this->insert_id) == 1)
|
||||
if (count($this->insert_id) >= 1)
|
||||
{
|
||||
// echo "* SINGLE DATA CONVERT: ".count($this->insert_id[0])." => ".array_key_exists($this->pk_name, $this->insert_id[0])."<br>";
|
||||
// echo "* PK DIRECT: ".$this->insert_id[0][$this->pk_name]."<Br>";
|
||||
@@ -1015,7 +1015,7 @@
|
||||
// if still no cursor ...
|
||||
if (!$this->cursor_ext[$md5]['cursor'])
|
||||
{
|
||||
if (!$this->db_debug)
|
||||
if ($this->db_debug)
|
||||
$this->_db_debug('db', $this->cursor_ext[$md5]['query'], 'db_return', 'Q');
|
||||
// internal error handling
|
||||
$this->error_id = 13;
|
||||
@@ -1707,13 +1707,25 @@ $this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[
|
||||
if ((!$primary_key['value'] || ($primary_key['value'] && !in_array($field, $not_write_update_array))) && !in_array($field, $not_write_array))
|
||||
{
|
||||
// data from external or data field
|
||||
$_data = (count($data) >= 1) ? $data[$field] : $GLOBALS[$field];
|
||||
$_data = null;
|
||||
if (count($data) >= 1 && array_key_exists($field, $data))
|
||||
$_data = $data[$field];
|
||||
elseif (array_key_exists($field, $GLOBALS))
|
||||
$_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
|
||||
if (($not_null && !$_data) || (!$has_default && !$_data) || ($is_bool && !$_data) || (is_numeric($_data) && isset($_data)) || ($primary_key['value'] && !$_data) || $_data)
|
||||
// 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 && 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 .= ', ';
|
||||
@@ -1728,9 +1740,10 @@ $this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[
|
||||
$_data = '';
|
||||
// write data into sql string
|
||||
if (strstr($table_data[$field]['type'], 'int'))
|
||||
$q_sub_data .= (is_numeric($_data) && isset($_data)) ? $_data : ($has_default ? $has_default : 'NULL');
|
||||
$q_sub_data .= (is_numeric($_data) && isset($_data)) ? $_data : 'NULL';
|
||||
else
|
||||
$q_sub_data .= ($_data ? "'".$this->db_escape_string($_data)."'" : (($primary_key['value'] && $is_bool) ? "'".$this->db_boolean($_data, true)."'" : ($has_default ? "'".$this->db_escape_string($has_default)."'" : 'NULL')));
|
||||
// if bool -> set bool, else write data
|
||||
$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