test id 65 - fixed the number of rows affected returned by the update
@@ -1166,9 +1166,21 @@ int Connection::update(const string& table, const string& payload)
Document document;
SQLBuffer sql;
+
+ // FIXME_I:
+ Logger::getLogger()->setMinLevel("debug");
+ Logger::getLogger()->debug(
+ "DBG update 1.0 : table |%s| payload |%s| ",
+ table.c_str(),
+ payload.c_str());
+
int row = 0;
ostringstream convert;
+ // FIXME_I:
+ Logger::getLogger()->debug("DBG update 2.0");
+
+
std::size_t arr = payload.find("updates");
bool changeReqd = (arr == std::string::npos || arr > 8);
if (changeReqd)
@@ -1185,6 +1197,10 @@ SQLBuffer sql;
}
else
{
+ // FIXME_I:
+ Logger::getLogger()->debug("DBG update 2.1");
+
+
Value &updates = document["updates"];
if (!updates.IsArray())
{
@@ -1192,10 +1208,18 @@ SQLBuffer sql;
return -1;
}
+ // FIXME_I:
+ Logger::getLogger()->debug("DBG update 2.2");
+
+
sql.append("BEGIN TRANSACTION;");
int i=0;
for (Value::ConstValueIterator iter = updates.Begin(); iter != updates.End(); ++iter,++i)
{
+ // FIXME_I:
+ Logger::getLogger()->debug("DBG update 2.3");
+
+
if (!iter->IsObject())
{
raiseError("update",
@@ -1461,6 +1485,10 @@ SQLBuffer sql;
}
}
sql.append(';');
+
+ // FIXME_I:
+ Logger::getLogger()->debug("DBG update 2.9");
+
row++;
}
}
@@ -1471,6 +1499,12 @@ SQLBuffer sql;
char *zErrMsg = NULL;
int rc;
+
+ // FIXME_I:
+ Logger::getLogger()->setMinLevel("debug");
+ Logger::getLogger()->debug(
+ "DBG 1.1 : query |%s| ", query);
+
// Exec the UPDATE statement: no callback, no result set
m_writeAccessOngoing.fetch_add(1);
rc = SQLexec(dbHandle,
@@ -1512,11 +1546,36 @@ SQLBuffer sql;
int update = sqlite3_changes(dbHandle);
+ // FIXME_I:
+ Logger::getLogger()->setMinLevel("debug");
+ Logger::getLogger()->debug(
+ "DBG 1.2 : update |%d| row |%d| ", update, row);
+
+ //# FIXME_I
+ Logger::getLogger()->debug("DBG 1.2 : brfore raiseError");
+
+ int return_value=0;
+
if (update == 0)
+ {
raiseError("update", "Not all updates within transaction succeeded");
+ return_value = -1;
+ }
+ else
+ {
+ return_value = (row == 1 ? update : row);
+ }
- // Return the status
- return (update ? row : -1);
+ //# FIXME_I
+ Logger::getLogger()->debug("DBG 1.2 : after raiseError");
+ Logger::getLogger()->debug("DBG 1.2 : return_value |%d| ", return_value);
+
+ // Returns the number of rows affected, cases :
+ //
+ // 1) update == 0, no update, returns -1
+ // 2) single command SQL that could affects multiple rows, returns 'update'
+ // 3) multiple SQL commands packed and executed in one SQLexec, returns 'row'
+ return (return_value);
}
// Return failure
