aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-03-07 10:21:09 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-03-07 10:21:09 +0200
commit382d0972301fb575f36eb2e5d442d735d7da3da4 (patch)
treef6fe9c80389c85e72bf849e8527f09e207cece0e
parent58f14a5a500b92f6ed34fe20a896ae9c2d777071 (diff)
Use RAII to free select statement results
-rw-r--r--common/query/driver.cxx19
-rw-r--r--common/query/test.std1
-rw-r--r--common/threads/driver.cxx31
3 files changed, 42 insertions, 9 deletions
diff --git a/common/query/driver.cxx b/common/query/driver.cxx
index 6afd82d..c207955 100644
--- a/common/query/driver.cxx
+++ b/common/query/driver.cxx
@@ -513,6 +513,25 @@ main (int argc, char* argv[])
t.commit ();
}
+
+ // Test empty result set.
+ //
+ cout << "test 018" << endl;
+ {
+ {
+ transaction t (db->begin ());
+ result r (db->query<person> (query::last_name == "None"));
+ assert (r.empty ());
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ result r (db->query<person> (query::last_name == "None"));
+ assert (r.begin () == r.end ());
+ t.commit ();
+ }
+ }
}
catch (const odb::exception& e)
{
diff --git a/common/query/test.std b/common/query/test.std
index 58a2aa0..e4ed7a0 100644
--- a/common/query/test.std
+++ b/common/query/test.std
@@ -98,3 +98,4 @@ Jane Doe 29 married
test 016
test 017
+test 018
diff --git a/common/threads/driver.cxx b/common/threads/driver.cxx
index 710b162..cbfb283 100644
--- a/common/threads/driver.cxx
+++ b/common/threads/driver.cxx
@@ -42,7 +42,7 @@ struct task
{
}
- void
+ void*
execute ()
{
try
@@ -121,24 +121,31 @@ struct task
}
}
}
+ catch (int)
+ {
+ }
+ /*
catch (const odb::exception& e)
{
cerr << e.what () << endl;
+ return reinterpret_cast<void*> (1);
}
+ */
+
+ return 0;
}
static void*
execute (void* arg)
{
- static_cast<task*> (arg)->execute ();
- return 0;
+ return static_cast<task*> (arg)->execute ();
}
database& db_;
unsigned long n_;
};
-void
+bool
test (int argc, char* argv[], size_t max_connections)
{
auto_ptr<database> db (create_database (argc, argv, true, max_connections));
@@ -156,8 +163,11 @@ test (int argc, char* argv[], size_t max_connections)
new (details::shared) details::thread (&task::execute, t.get ())));
}
+ bool r (true);
+
for (unsigned long i (0); i < thread_count; ++i)
- threads[i]->join ();
+ if (threads[i]->join () != 0)
+ r = false;
{
typedef odb::result<object> result;
@@ -170,6 +180,8 @@ test (int argc, char* argv[], size_t max_connections)
t.commit ();
}
+
+ return r;
}
int
@@ -177,10 +189,11 @@ main (int argc, char* argv[])
{
try
{
- test (argc, argv, 0);
- test (argc, argv, thread_count - 1);
- test (argc, argv, thread_count / 2);
- test (argc, argv, thread_count / 4);
+ if (!(test (argc, argv, 0) &&
+ test (argc, argv, thread_count - 1) &&
+ test (argc, argv, thread_count / 2) &&
+ test (argc, argv, thread_count / 4)))
+ return 1;
}
catch (const odb::exception& e)
{