summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it_dbi.class6
-rw-r--r--it_dbi_postgres.class7
-rwxr-xr-xtest/it_dbi.t15
3 files changed, 20 insertions, 8 deletions
diff --git a/it_dbi.class b/it_dbi.class
index 2b6f475..d8dfa1b 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -579,8 +579,8 @@ function query($query, $p = array())
if (!($result = $this->_query($query, $p)))
{
- if ($result === false)
- return $result;
+ if ($result === null)
+ return false;
$this->_fatal("query(\"$query\") failed");
}
else if (it::match('^(CREATE|ALTER|DROP) ', $query, array('utf8' => false)))
@@ -1106,7 +1106,7 @@ function _query($query, $p)
{
$errno = mysqli_errno($this->_link);
if (($p['safety'] < 2) && ($errno == 1062)) # Duplicate entry
- return false;
+ return null;
if ($errno == 2006) # mysql server has gone away: retry
{
diff --git a/it_dbi_postgres.class b/it_dbi_postgres.class
index 1161632..bce0fd9 100644
--- a/it_dbi_postgres.class
+++ b/it_dbi_postgres.class
@@ -110,11 +110,10 @@ function _query($query, $p)
if (!($result = pg_query($this->_link, $query)) && $p['safety'])
{
- /* TODO
- $errno = mysqli_errno($this->_link);
- if (($p['safety'] < 2) && ($errno == 1062)) # Duplicate entry
- return false;
+ if (($p['safety'] < 2) && it::match('duplicate key value', pg_last_error($this->_link))) # Duplicate entry
+ return null;
+ /* TODO
if ($errno == 2006) # mysql server has gone away: retry
{
it::log('sqllog', "it_dbi(): reconnecting mysqli_connect {$p['server']}, {$p['db']}");
diff --git a/test/it_dbi.t b/test/it_dbi.t
index 42fae74..7b1c9d7 100755
--- a/test/it_dbi.t
+++ b/test/it_dbi.t
@@ -33,6 +33,13 @@ $dbi->query("create temporary table it_dbi_test (
$opts['subclass']::createclass(['table' => "it_dbi_test", 'forcecreate' => true]);
$record = new it_dbi_test;
+$GLOBALS['it_defaultconfig']['fatal_throws_exception'] = true;
+
+try {
+ is(@$record->select("SYNTAX ERROR"), "Exception", "Syntax triggers exception for fatal_throws_exception mode");
+} catch (Exception $e) {
+ is(it::match('syntax', $e->getMessage()), 'syntax', "Syntax error triggers error");
+}
$record->insert(['x' => 42, 'foo' => null]);
$record->insert(['foo' => "bar"]);
@@ -44,6 +51,12 @@ is(
"auto_increment"
);
+try {
+ @$record->insert(['ID' => 3]);
+} catch (Exception $e) {
+ is($e->getMessage(), false, "Silently ignore duplicate inserts with default safety");
+}
+
$record->read(1);
is(
[$record->_key, $record->x, $record->foo],
@@ -58,7 +71,7 @@ is(
);
is(
- $record->select(['foo <>' => ""], "LIMIT 1"),
+ @$record->select(['foo <>' => ""], "LIMIT 1"),
1,
"select with multiple parameters (LIMIT part)"
);