Skip to content

Commit 17b51a2

Browse files
authored
Merge pull request #4553 from jjimenezshaw/sqlite-msg
On SQLite query error, show first the error msg than the sql query
2 parents 2de2d85 + 2653d98 commit 17b51a2

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/iso19111/factory.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,13 @@ SQLResultSet SQLiteHandle::run(sqlite3_stmt *stmt, const std::string &sql,
494494
} else if (ret == SQLITE_DONE) {
495495
break;
496496
} else {
497-
throw FactoryException(std::string("SQLite error on ")
498-
.append(sql)
499-
.append(": code = ")
497+
throw FactoryException(std::string("SQLite error [ ")
498+
.append("code = ")
500499
.append(internal::toString(ret))
501500
.append(", msg = ")
502-
.append(sqlite3_errmsg(sqlite_handle_)));
501+
.append(sqlite3_errmsg(sqlite_handle_))
502+
.append(" ] on ")
503+
.append(sql));
503504
}
504505
}
505506
return result;
@@ -515,8 +516,10 @@ SQLResultSet SQLiteHandle::run(const std::string &sql,
515516
if (sqlite3_prepare_v2(sqlite_handle_, sql.c_str(),
516517
static_cast<int>(sql.size()), &stmt,
517518
nullptr) != SQLITE_OK) {
518-
throw FactoryException("SQLite error on " + sql + ": " +
519-
sqlite3_errmsg(sqlite_handle_));
519+
throw FactoryException(std::string("SQLite error [ ")
520+
.append(sqlite3_errmsg(sqlite_handle_))
521+
.append(" ] on ")
522+
.append(sql));
520523
}
521524
auto ret = run(stmt, sql, parameters, useMaxFloatPrecision);
522525
sqlite3_finalize(stmt);
@@ -1443,8 +1446,11 @@ SQLResultSet DatabaseContext::Private::run(const std::string &sql,
14431446
if (sqlite3_prepare_v2(l_handle->handle(), sql.c_str(),
14441447
static_cast<int>(sql.size()), &stmt,
14451448
nullptr) != SQLITE_OK) {
1446-
throw FactoryException("SQLite error on " + sql + ": " +
1447-
sqlite3_errmsg(l_handle->handle()));
1449+
throw FactoryException(
1450+
std::string("SQLite error [ ")
1451+
.append(sqlite3_errmsg(l_handle->handle()))
1452+
.append(" ] on ")
1453+
.append(sql));
14481454
}
14491455
mapSqlToStatement_.insert(
14501456
std::pair<std::string, sqlite3_stmt *>(sql, stmt));

0 commit comments

Comments
 (0)