From 1167ec308258f09a5403bae6ccba90974e1bd062 Mon Sep 17 00:00:00 2001 From: Ben Boudaoud Date: Thu, 16 Jun 2022 16:51:32 -0400 Subject: [PATCH] Add replaceSingleQuote() routine --- source/sqlHelpers.cpp | 29 ++++++++++++++++++++++++++--- source/sqlHelpers.h | 1 + 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/source/sqlHelpers.cpp b/source/sqlHelpers.cpp index d2e5740d..1934fc4b 100644 --- a/source/sqlHelpers.cpp +++ b/source/sqlHelpers.cpp @@ -36,11 +36,17 @@ bool insertRowIntoDB(sqlite3* db, const String tableName, const Array& v // Note that ID does not need to be provided unless PRIMARY KEY is set. String insertC = "INSERT INTO " + tableName + colNames + " VALUES("; for (int i = 0; i < values.size(); i++) { - insertC += values[i]; + String insertVal = values[i]; + if (beginsWith(values[i], "'")) { // Check if we are handling a single-quote delimited string + insertVal = values[i].substr(1, values[i].length() - 2); + replaceSingleQuote(insertVal); + insertVal = "'" + insertVal + "'"; + } + insertC += insertVal; if(i < values.size() - 1) insertC += ","; } insertC += ");"; - //logPrintf("Inserting row into %s table w/ SQL query:%s\n\n", tableName.c_str(), insertC.c_str()); + char* errmsg; int ret = sqlite3_exec(db, insertC.c_str(), 0, 0, &errmsg); if (ret != SQLITE_OK) { @@ -60,7 +66,13 @@ bool insertRowsIntoDB(sqlite3* db, const String tableName, const Array>& columns); bool insertRowIntoDB(sqlite3* db, const String tableName, const Array& values, const String colNames = ""); bool insertRowsIntoDB(sqlite3* db, const String tableName, const Array>& valueVector, const String colNames = ""); +bool replaceSingleQuote(String& str); \ No newline at end of file