Generalize transactions

This commit is contained in:
Jakub Vrana 2013-07-09 11:43:01 -07:00
parent 56b0917acd
commit 7a1133a2fd
7 changed files with 38 additions and 22 deletions

View file

@ -258,6 +258,10 @@ if (isset($_GET["mssql"])) {
return true; return true;
} }
function begin() {
return queries("BEGIN TRANSACTION");
}
} }
@ -485,10 +489,6 @@ WHERE OBJECT_NAME(i.object_id) = " . q($table)
; ;
} }
function begin() {
return queries("BEGIN TRANSACTION");
}
function last_id() { function last_id() {
global $connection; global $connection;
return $connection->result("SELECT SCOPE_IDENTITY()"); // @@IDENTITY can return trigger INSERT return $connection->result("SELECT SCOPE_IDENTITY()"); // @@IDENTITY can return trigger INSERT

View file

@ -837,13 +837,6 @@ if (!defined("DRIVER")) {
return array(); // "SQL" not required return array(); // "SQL" not required
} }
/** Begin transaction
* @return bool
*/
function begin() {
return queries("BEGIN");
}
/** Get last auto increment ID /** Get last auto increment ID
* @return string * @return string
*/ */

View file

@ -138,6 +138,10 @@ if (isset($_GET["oracle"])) {
//! support empty $set in insert() //! support empty $set in insert()
function begin() {
return true; // automatic start
}
} }
@ -328,10 +332,6 @@ ORDER BY uc.constraint_type, uic.column_position", $connection2) as $row) {
return apply_queries("DROP TABLE", $tables); return apply_queries("DROP TABLE", $tables);
} }
function begin() {
return true; // automatic start
}
function last_id() { function last_id() {
return 0; //! return 0; //!
} }

View file

@ -539,10 +539,6 @@ ORDER BY p.proname');
return get_vals("SELECT langname FROM pg_catalog.pg_language"); return get_vals("SELECT langname FROM pg_catalog.pg_language");
} }
function begin() {
return queries("BEGIN");
}
function last_id() { function last_id() {
return 0; // there can be several sequences return 0; // there can be several sequences
} }

View file

@ -210,6 +210,18 @@ if (isset($_GET["simpledb"])) {
return true; return true;
} }
function begin() {
return false;
}
function commit() {
return false;
}
function rollback() {
return false;
}
} }

View file

@ -60,4 +60,19 @@
return false; return false;
} }
/** Begin transaction
* @return bool
*/
function begin() {
return queries("BEGIN");
}
function commit() {
return queries("COMMIT");
}
function rollback() {
return queries("ROLLBACK");
}
} }

View file

@ -173,7 +173,7 @@ if ($_POST && !$error) {
$cols = array_keys($fields); $cols = array_keys($fields);
preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~', $file, $matches); preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~', $file, $matches);
$affected = count($matches[0]); $affected = count($matches[0]);
begin(); $driver->begin();
$separator = ($_POST["separator"] == "csv" ? "," : ($_POST["separator"] == "tsv" ? "\t" : ";")); $separator = ($_POST["separator"] == "csv" ? "," : ($_POST["separator"] == "tsv" ? "\t" : ";"));
$rows = array(); $rows = array();
foreach ($matches[0] as $key => $val) { foreach ($matches[0] as $key => $val) {
@ -192,10 +192,10 @@ if ($_POST && !$error) {
} }
$result = (!$rows || $driver->insertUpdate($TABLE, $rows, $primary)); $result = (!$rows || $driver->insertUpdate($TABLE, $rows, $primary));
if ($result) { if ($result) {
queries("COMMIT"); $driver->commit();
} }
queries_redirect(remove_from_uri("page"), lang('%d row(s) have been imported.', $affected), $result); queries_redirect(remove_from_uri("page"), lang('%d row(s) have been imported.', $affected), $result);
queries("ROLLBACK"); // after queries_redirect() to not overwrite error $driver->rollback(); // after queries_redirect() to not overwrite error
} }
} }