[niepce] Fix sqlstatement binding: the data is transient. This fixes the duplicate keyword bug. Test included
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] Fix sqlstatement binding: the data is transient. This fixes the duplicate keyword bug. Test included
- Date: Sat, 23 Apr 2016 13:41:47 +0000 (UTC)
commit cfea2cf93948c30ac0aab6795d0c0ce3eae5ace5
Author: Hubert Figuière <hub figuiere net>
Date: Sat Apr 23 09:39:00 2016 -0400
Fix sqlstatement binding: the data is transient.
This fixes the duplicate keyword bug.
Test included.
src/engine/db/test_library.cpp | 5 +++++
src/fwk/utils/db/sqlite/sqlitecnxdrv.cpp | 10 +++++-----
2 files changed, 10 insertions(+), 5 deletions(-)
---
diff --git a/src/engine/db/test_library.cpp b/src/engine/db/test_library.cpp
index c287c4e..a3f2962 100644
--- a/src/engine/db/test_library.cpp
+++ b/src/engine/db/test_library.cpp
@@ -76,6 +76,11 @@ int test_main(int, char *[])
int kwid2 = lib.makeKeyword("bar");
BOOST_CHECK(kwid2 > 0);
+ // duplicate keyword
+ int kwid3 = lib.makeKeyword("foo");
+ // should return kwid1 because it already exists.
+ BOOST_CHECK(kwid3 == kwid1);
+
BOOST_CHECK(lib.assignKeyword(kwid1, file_id));
BOOST_CHECK(lib.assignKeyword(kwid2, file_id));
diff --git a/src/fwk/utils/db/sqlite/sqlitecnxdrv.cpp b/src/fwk/utils/db/sqlite/sqlitecnxdrv.cpp
index ffe5bf4..641e1de 100644
--- a/src/fwk/utils/db/sqlite/sqlitecnxdrv.cpp
+++ b/src/fwk/utils/db/sqlite/sqlitecnxdrv.cpp
@@ -266,7 +266,7 @@ namespace db { namespace sqlite {
bool
SqliteCnxDrv::execute_statement (const SQLStatement &a_statement)
{
- std::lock_guard<std::recursive_mutex> lock(m_mutex);
+ std::lock_guard<std::recursive_mutex> lock(m_mutex);
THROW_IF_FAIL (m_priv && m_priv->sqlite) ;
DBG_OUT("sql string: %s", a_statement.to_string().c_str()) ;
@@ -306,9 +306,9 @@ namespace db { namespace sqlite {
case ColumnType::STRING:
{
try {
- std::string text(boost::any_cast<std::string>(iter->get<2>()));
- sqlite3_bind_text(m_priv->cur_stmt, idx, text.c_str(),
- text.size(), SQLITE_STATIC);
+ const std::string & text(boost::any_cast<std::string>(iter->get<2>()));
+ sqlite3_bind_text(m_priv->cur_stmt, idx, text.c_str(),
+ text.size(), SQLITE_TRANSIENT);
}
catch(...)
{
@@ -321,7 +321,7 @@ namespace db { namespace sqlite {
try {
const fwk::Buffer* blob(boost::any_cast<const fwk::Buffer*>(iter->get<2>()));
sqlite3_bind_blob(m_priv->cur_stmt, idx, blob->get_data(),
- blob->get_len(), SQLITE_STATIC);
+ blob->get_len(), SQLITE_TRANSIENT);
}
catch(...)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]