Use transactions for SQL updates

This commit is contained in:
Grégory Soutadé 2015-10-11 09:42:32 +02:00
parent 9dac732efe
commit fe5e9208a3
5 changed files with 23 additions and 15 deletions

View File

@ -1,3 +1,7 @@
v0.6 (11/10/2015)
** Dev **
Use transactions for SQL updates
v0.5 (19/06/2015)
** User **
Add tag management

View File

@ -1,5 +1,5 @@
/*
Copyright 2010-2012 Grégory Soutadé
Copyright 2010-2015 Grégory Soutadé
This file is part of KissCount.
@ -30,7 +30,7 @@
#include <view/wxUI.hpp>
#define APP_VERSION "0.5"
#define APP_VERSION "0.6"
#define ESCAPE_CHARS(s) s = s.replace("\"", " ");
// #define ESCAPE_CHARS(s) s = s.replace("\"", "\\\""); s = s.replace("\'", "\\\'");

View File

@ -1,5 +1,5 @@
/*
Copyright 2010-2012 Grégory Soutadé
Copyright 2010-2015 Grégory Soutadé
This file is part of KissCount.

View File

@ -49,6 +49,7 @@
#define EXECUTE_SQL_UPDATE_WITH_CODE(req, return_value, code_if_fail, code_if_syntax_fail) \
do { \
_db.transaction(); \
QSqlQuery query; \
if (!query.exec(req)) \
{ \
@ -56,22 +57,26 @@
std::cerr << __FUNCTION__ << " " << __FILE__ << " " << __LINE__ << "\n" ; \
std::cerr << req.toStdString() << "\n" ; \
std::cerr << query.lastError().text().toStdString() << "\n" ; \
_db.rollback(); \
code_if_fail; \
return return_value; \
} \
_db.commit(); \
} while(0);
#define EXECUTE_SQL_QUERY_WITH_CODE(req, return_value, code_if_fail, code_if_syntax_fail) \
do { \
if (!query.exec(req)) \
{ \
QMessageBox::critical(0, _("Error"), _("Query failed !\n") + req); \
std::cerr << __FUNCTION__ << "\n" ; \
std::cerr << req.toStdString() << "\n" ; \
std::cerr << query.lastError().text().toStdString() << "\n" ; \
code_if_fail; \
return return_value; \
} \
} while(0);
#define EXECUTE_SQL_QUERY_WITH_CODE(req, return_value, code_if_fail, code_if_syntax_fail) \
if (!query.exec(req)) \
{ \
QMessageBox::critical(0, _("Error"), _("Query failed !\n") + req); \
std::cerr << __FUNCTION__ << "\n" ; \
std::cerr << req.toStdString() << "\n" ; \
std::cerr << query.lastError().text().toStdString() << "\n" ; \
code_if_fail; \
return return_value; \
} \
#define EXECUTE_SQL_QUERY(req, return_value) EXECUTE_SQL_QUERY_WITH_CODE(req, return_value, {}, {})
#define EXECUTE_SQL_UPDATE(req, return_value) EXECUTE_SQL_UPDATE_WITH_CODE(req, return_value, {}, {})

View File

@ -310,7 +310,6 @@ void wxUI::ChangeUser()
}
catch (UsersDialog::ExceptionNewUser e)
{
}
}