Fix problems with quote and apostrophe

This commit is contained in:
Grégory Soutadé 2012-05-12 10:28:16 +02:00
parent 669532d385
commit 8c61a32a6f
2 changed files with 6 additions and 4 deletions

View File

@ -32,7 +32,8 @@
#define APP_VERSION "0.3" #define APP_VERSION "0.3"
#define ESCAPE_CHARS(s) s = s.replace("\"", "\\\""); s = s.replace("\'", "\\\'"); #define ESCAPE_CHARS(s) s = s.replace("\"", " ");
// #define ESCAPE_CHARS(s) s = s.replace("\"", "\\\""); s = s.replace("\'", "\\\'");
/*{ \ /*{ \
if (s.Find(wxT("\\\"")) == wxNOT_FOUND) \ if (s.Find(wxT("\\\"")) == wxNOT_FOUND) \
s.Replace(wxT("\""), wxT("\\\""), true); \ s.Replace(wxT("\""), wxT("\\\""), true); \
@ -40,7 +41,8 @@
s.Replace(wxT("\'"), wxT("\\\'"), true); \ s.Replace(wxT("\'"), wxT("\\\'"), true); \
} }
*/ */
#define UNESCAPE_CHARS(s) s = s.replace("\\\"", "\""); s = s.replace("\\\'", "\'"); #define UNESCAPE_CHARS(s) s = s.replace("\\\"", " ");
// #define UNESCAPE_CHARS(s) s = s.replace("\\\"", "\""); s = s.replace("\\\'", "\'");
/*{ \ /*{ \
s.Replace(wxT("\\\""), wxT("\""), true); \ s.Replace(wxT("\\\""), wxT("\""), true); \
s.Replace(wxT("\\\'"), wxT("\'"), true); \ s.Replace(wxT("\\\'"), wxT("\'"), true); \

View File

@ -585,7 +585,7 @@ int Database::AddOperation(User* user, Operation& op, bool checkTransfert)
ESCAPE_CHARS(op.description); ESCAPE_CHARS(op.description);
req = "INSERT INTO operation ('user', 'parent', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost', 'formula', 'transfert', 'meta', 'virtual', 'checked') VALUES ('%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8'" ; req = "INSERT INTO operation ('user', 'parent', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost', 'formula', 'transfert', 'meta', 'virtual', 'checked') VALUES ('%1', '%2', '%3', '%4', '%5', '%6', '%7', \"%8\"" ;
req = req.arg(QString::number(user->_id), (op.parent) ? QString::number(op.parent): "", QString::number(op.account), QString::number(op.year), req = req.arg(QString::number(user->_id), (op.parent) ? QString::number(op.parent): "", QString::number(op.account), QString::number(op.year),
QString::number(op.month), QString::number(op.day), v.sprintf("%d", op.amount), op.description); QString::number(op.month), QString::number(op.day), v.sprintf("%d", op.amount), op.description);
req += ", '%1', '%2', '%3', '%4', '%5', '%6', '%7')"; req += ", '%1', '%2', '%3', '%4', '%5', '%6', '%7')";
@ -1280,7 +1280,7 @@ std::vector<Operation>* Database::Search(User* user, QString* description, QDate
ESCAPE_CHARS(desc); ESCAPE_CHARS(desc);
if (wildcards) if (wildcards)
req += "UPPER(description) LIKE UPPER('%" + desc + "%')"; req += "UPPER(description) LIKE UPPER(\"%" + desc + "%\")";
else else
req += "description=\"" + desc + "\""; req += "description=\"" + desc + "\"";
firstCond = true; firstCond = true;