Compare commits

...

3 Commits

Author SHA1 Message Date
Clemens Schwaighofer
6606f30ceb Basic date compare fix
The date compare now uses correct preg_split for splitting with - and /
as date separators
2017-04-03 17:52:49 +09:00
Clemens Schwaighofer
e1255e0872 DB IO: prepare pk null fix, split -> explode in Basic
- Basic class still had a "split" call -> change that to explode
- The prepare DB IO part missed setting pk name for the cursor to null
so no returning is assumed
2017-04-03 17:46:06 +09:00
Clemens Schwaighofer
5c53621f96 Update DB IO to skip returning on prepare statements
Same as normal exec if pk name is set to NULL
2017-04-03 17:38:33 +09:00
3 changed files with 41 additions and 28 deletions

View File

@@ -158,6 +158,11 @@
print $basic->magic_links('user@bubu.at').'<br>';
print $basic->magic_links('http://test.com/foo/bar.php?foo=1').'<br>';
// compare date
$date_1 = '2017/1/5';
$date_2 = '2017-01-05';
print "COMPARE DATE: ".$basic->CompareDate($date_1, $date_2)."<br>";
// print error messages
print $basic->print_error_msg();

View File

@@ -1239,8 +1239,8 @@
return FALSE;
// splits the data up with / or -
list ($start_year, $start_month, $start_day) = split('[/-]', $start_date);
list ($end_year, $end_month, $end_day) = split('[/-]', $end_date);
list ($start_year, $start_month, $start_day) = preg_split('/[\/-]/', $start_date);
list ($end_year, $end_month, $end_day) = preg_split('/[\/-]/', $end_date);
// check that month & day are two digits and then combine
foreach (array('start', 'end') as $prefix)
{

View File

@@ -1391,34 +1391,41 @@
// if this is an insert query, check if we can add a return
if ($this->_check_query_for_insert($query, true))
{
// set primary key name
// current: only via parameter
if (!$pk_name)
if ($pk_name != 'NULL')
{
// read the primary key from the table, if we do not have one, we get nothing in return
list($schema, $table) = $this->_db_return_table($query);
if (!$this->pk_name_table[$table])
// set primary key name
// current: only via parameter
if (!$pk_name)
{
$this->pk_name_table[$table] = $this->db_functions->_db_primary_key($table, $schema);
// read the primary key from the table, if we do not have one, we get nothing in return
list($schema, $table) = $this->_db_return_table($query);
if (!$this->pk_name_table[$table])
{
$this->pk_name_table[$table] = $this->db_functions->_db_primary_key($table, $schema);
}
$pk_name = $this->pk_name_table[$table];
}
if ($pk_name)
$this->prepare_cursor[$stm_name]['pk_name'] = $pk_name;
// if no returning, then add it
if (!preg_match("/ returning /i", $query) && $this->prepare_cursor[$stm_name]['pk_name'])
{
$query .= " RETURNING ".$this->prepare_cursor[$stm_name]['pk_name'];
$this->prepare_cursor[$stm_name]['returning_id'] = true;
}
// if returning exists but not pk_name, add it
else if (preg_match("/ returning (.*)/i", $query, $matches) && $this->prepare_cursor[$stm_name]['pk_name'])
{
if (!preg_match("/{$this->prepare_cursor[$stm_name]['pk_name']}/", $matches[1]))
{
$query .= " , ".$this->prepare_cursor[$stm_name]['pk_name'];
}
$this->prepare_cursor[$stm_name]['returning_id'] = true;
}
$pk_name = $this->pk_name_table[$table];
}
if ($pk_name)
else
{
$this->prepare_cursor[$stm_name]['pk_name'] = $pk_name;
// if no returning, then add it
if (!preg_match("/ returning /i", $query) && $this->prepare_cursor[$stm_name]['pk_name'])
{
$query .= " RETURNING ".$this->prepare_cursor[$stm_name]['pk_name'];
$this->prepare_cursor[$stm_name]['returning_id'] = true;
}
// if returning exists but not pk_name, add it
else if (preg_match("/ returning (.*)/i", $query, $matches) && $this->prepare_cursor[$stm_name]['pk_name'])
{
if (!preg_match("/{$this->prepare_cursor[$stm_name]['pk_name']}/", $matches[1]))
{
$query .= " , ".$this->prepare_cursor[$stm_name]['pk_name'];
}
$this->prepare_cursor[$stm_name]['returning_id'] = true;
}
}
// search for $1, $2, in the query and push it into the control array
@@ -1484,7 +1491,7 @@ $this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[
$this->_db_error($this->prepare_cursor[$stm_name]['result']);
$this->_db_debug('db', '<span style="color: red;"><b>DB-Error</b> '.$stm_name.': Execution failed</span>', 'DB_ERROR');
}
if ($this->_check_query_for_insert($this->prepare_cursor[$stm_name]['query'], true))
if ($this->_check_query_for_insert($this->prepare_cursor[$stm_name]['query'], true) && $this->prepare_cursor[$stm_name]['pk_name'] != 'NULL')
{
if (!$this->prepare_cursor[$stm_name]['returning_id'])
{
@@ -1493,6 +1500,7 @@ $this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[
elseif ($code)
{
$this->insert_id = array ();
$this->insert_id_ext = array ();
// we have returning, now we need to check if we get one or many returned
// we'll need to loop this, if we have multiple insert_id returns
while ($_insert_id = $this->db_functions->_db_fetch_array($code, PGSQL_ASSOC))
@@ -1518,12 +1526,12 @@ $this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[
}
}
else
{
{
// failed to get insert id
$this->insert_id = '';
$this->warning_id = 33;
$this->_db_error('db', '<span style="color: orange;"><b>DB-Warning</b> '.$stm_name.': insert id returned no data</span>', 'DB_WARNING');
}
}
}
// this error handling is only for pgsql
if (is_array($this->insert_id))