[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [krecipes] src/backends: Create the CHECK_QUERY macro.
From: José_Manuel_Santamaría_Lema <panfaust () gmail ! com>
Date: 2016-04-01 18:19:06
Message-ID: E1am3f0-0004Ph-Mt () scm ! kde ! org
[Download RAW message or body]
Git commit 4b8a49847859a0c52cab2f1d09ae297f4785dc0d by José Manuel Santamaría Lema.
Committed on 01/04/2016 at 14:47.
Pushed by joselema into branch 'master'.
Create the CHECK_QUERY macro.
Use it when creating authors to test the idea.
M +2 -0 src/backends/qsqlrecipedb.cpp
M +13 -3 src/backends/qsqlrecipedb.h
http://commits.kde.org/krecipes/4b8a49847859a0c52cab2f1d09ae297f4785dc0d
diff --git a/src/backends/qsqlrecipedb.cpp b/src/backends/qsqlrecipedb.cpp
index 9265176..9898b85 100644
--- a/src/backends/qsqlrecipedb.cpp
+++ b/src/backends/qsqlrecipedb.cpp
@@ -2425,6 +2425,8 @@ RecipeDB::IdType QSqlRecipeDB::createNewAuthor( const QString \
&authorName ) command = QString( "INSERT INTO authors VALUES(%2,'%1');" ).arg( \
escapeAndEncode( real_name ) ).arg( getNextInsertIDStr( "authors", "id" ) ); \
QSqlQuery authorToCreate( command, *database);
+ CHECK_QUERY(authorToCreate,return RecipeDB::InvalidId;)
+
RecipeDB::IdType last_insert_id = lastInsertId( authorToCreate );
emit authorCreated( Element( real_name, last_insert_id ) );
return last_insert_id;
diff --git a/src/backends/qsqlrecipedb.h b/src/backends/qsqlrecipedb.h
index 49bbf2e..a8a7698 100644
--- a/src/backends/qsqlrecipedb.h
+++ b/src/backends/qsqlrecipedb.h
@@ -27,6 +27,19 @@
#include "datablocks/ingredientpropertylist.h"
#include "datablocks/unitratiolist.h"
+//macro with the debug output for SQL queries
+#define KRECIPES_SQL_DEBUG_OUTPUT kDebug()
+//macro to test that 'query' was executed succesfully, in
+//case something goes wrong, it executes 'abortCode'
+#define CHECK_QUERY(query,abortCode) \
+if ( query.isActive() ) { \
+ KRECIPES_SQL_DEBUG_OUTPUT << "SQL query:" << query.lastQuery(); \
+} else { \
+ KRECIPES_SQL_DEBUG_OUTPUT << "SQL query FAILED:" << query.lastQuery(); \
+ abortCode \
+}
+
+
/**
@author Unai Garro, Jason Kivlighn
*/
@@ -241,7 +254,4 @@ private:
bool m_transactionsEnabled;
};
-
-
-
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic