changeset 137:0e97abc7b950

fix of a bug in older versions of sqlite
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Oct 2012 13:13:14 +0200
parents fe180eae201d
children f333c0398f6e
files Core/SQLite/Connection.cpp Core/SQLite/Statement.cpp Core/SQLite/Statement.h OrthancServer/DicomProtocol/DicomServer.cpp OrthancServer/main.cpp UnitTests/SQLite.cpp UnitTests/main.cpp
diffstat 7 files changed, 67 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/Core/SQLite/Connection.cpp	Tue Oct 09 18:21:01 2012 +0200
+++ b/Core/SQLite/Connection.cpp	Wed Oct 10 13:13:14 2012 +0200
@@ -41,6 +41,7 @@
 #include <sqlite3.h>
 #include <string.h>
 
+#include <glog/logging.h>
 
 
 namespace Orthanc
@@ -149,6 +150,7 @@
 
     bool Connection::Execute(const char* sql) 
     {
+      VLOG(1) << "SQLite::Connection::Execute " << sql;
       CheckIsOpen();
 
       int error = sqlite3_exec(db_, sql, NULL, NULL, NULL);
--- a/Core/SQLite/Statement.cpp	Tue Oct 09 18:21:01 2012 +0200
+++ b/Core/SQLite/Statement.cpp	Wed Oct 10 13:13:14 2012 +0200
@@ -42,6 +42,7 @@
 #include <boost/lexical_cast.hpp>
 #include <sqlite3.h>
 #include <string.h>
+#include <glog/logging.h>
 
 namespace Orthanc
 {
@@ -106,11 +107,13 @@
 
     bool Statement::Run()
     {
+      VLOG(1) << "SQLite::Statement::Run " << sqlite3_sql(GetStatement());
       return CheckError(sqlite3_step(GetStatement())) == SQLITE_DONE;
     }
 
     bool Statement::Step()
     {
+      VLOG(1) << "SQLite::Statement::Step " << sqlite3_sql(GetStatement());
       return CheckError(sqlite3_step(GetStatement())) == SQLITE_ROW;
     }
 
@@ -121,6 +124,7 @@
       // spurious error callback.
       if (clear_bound_vars)
         sqlite3_clear_bindings(GetStatement());
+      //VLOG(1) << "SQLite::Statement::Reset";
       sqlite3_reset(GetStatement());
     }
 
--- a/Core/SQLite/Statement.h	Tue Oct 09 18:21:01 2012 +0200
+++ b/Core/SQLite/Statement.h	Wed Oct 10 13:13:14 2012 +0200
@@ -95,6 +95,11 @@
                 const StatementId& id,
                 const char* sql);
 
+      ~Statement()
+      {
+        Reset();
+      }
+
       bool Run();
 
       bool Step();
--- a/OrthancServer/DicomProtocol/DicomServer.cpp	Tue Oct 09 18:21:01 2012 +0200
+++ b/OrthancServer/DicomProtocol/DicomServer.cpp	Wed Oct 10 13:13:14 2012 +0200
@@ -59,7 +59,7 @@
     /* make sure data dictionary is loaded */
     if (!dcmDataDict.isDictionaryLoaded())
     {
-      LOG(WARNING) << "no data dictionary loaded, check environment variable: " << DCM_DICT_ENVIRONMENT_VARIABLE;
+      LOG(ERROR) << "no data dictionary loaded, check environment variable: " << DCM_DICT_ENVIRONMENT_VARIABLE;
     }
 
     /* initialize network, i.e. create an instance of T_ASC_Network*. */
@@ -72,7 +72,7 @@
       throw OrthancException("Cannot create network");
     }
 
-    LOG(WARNING) << "DICOM server started";
+    LOG(INFO) << "DICOM server started";
 
     server->started_ = true;
 
@@ -95,7 +95,7 @@
       }
     }
 
-    LOG(WARNING) << "DICOM server stopping";
+    LOG(INFO) << "DICOM server stopping";
 
     /* drop the network, i.e. free memory of T_ASC_Network* structure. This call */
     /* is the counterpart of ASC_initializeNetwork(...) which was called above. */
--- a/OrthancServer/main.cpp	Tue Oct 09 18:21:01 2012 +0200
+++ b/OrthancServer/main.cpp	Wed Oct 10 13:13:14 2012 +0200
@@ -113,6 +113,8 @@
     << "<https://code.google.com/p/orthanc/wiki/OrthancCookbook>." << std::endl
     << std::endl
     << "Command-line options:" << std::endl
+    << "  --verbose\t\tbe verbose in logs" << std::endl
+    << "  --trace\t\thighest verbosity in logs (for debug)" << std::endl
     << "  --help\t\tdisplay this help and exit" << std::endl
     << "  --version\t\toutput version information and exit" << std::endl
     << "  --logdir=[dir]\tdirectory where to store the log files" << std::endl
@@ -142,6 +144,8 @@
 {
   // Initialize Google's logging library.
   FLAGS_logtostderr = true;
+  FLAGS_minloglevel = 1;
+  FLAGS_v = 0;
 
   for (int i = 1; i < argc; i++)
   {
@@ -157,6 +161,17 @@
       return 0;
     }
 
+    if (std::string(argv[i]) == "--verbose")
+    {
+      FLAGS_minloglevel = 0;
+    }
+
+    if (std::string(argv[i]) == "--trace")
+    {
+      FLAGS_minloglevel = 0;
+      FLAGS_v = 1;
+    }
+
     if (boost::starts_with(argv[i], "--logdir="))
     {
       FLAGS_logtostderr = false;
@@ -235,11 +250,11 @@
       httpServer.Start();
       dicomServer.Start();
 
-      LOG(INFO) << "The server has started";
+      LOG(WARNING) << "Orthanc has started";
       Toolbox::ServerBarrier();
 
       // Stop
-      LOG(INFO) << "The server is stopping";
+      LOG(WARNING) << "Orthanc is stopping";
     }
 
     storeScp.Done();
--- a/UnitTests/SQLite.cpp	Tue Oct 09 18:21:01 2012 +0200
+++ b/UnitTests/SQLite.cpp	Wed Oct 10 13:13:14 2012 +0200
@@ -3,6 +3,7 @@
 #include "../Core/Toolbox.h"
 #include "../Core/SQLite/Connection.h"
 #include "../Core/SQLite/Statement.h"
+#include "../Core/SQLite/Transaction.h"
 
 #include <sqlite3.h>
 
@@ -202,3 +203,36 @@
   ASSERT_TRUE(func->deleted_.find(4300) != func->deleted_.end());
   ASSERT_TRUE(func->deleted_.find(4301) != func->deleted_.end());
 }
+
+
+TEST(SQLite, EmptyTransactions)
+{
+  try
+  {
+    SQLite::Connection c;
+    c.OpenInMemory();
+
+    c.Execute("CREATE TABLE a(id INTEGER PRIMARY KEY);");
+    c.Execute("INSERT INTO a VALUES(NULL)");
+      
+    {
+      SQLite::Transaction t(c);
+      t.Begin();
+      {
+        SQLite::Statement s(c, SQLITE_FROM_HERE, "SELECT * FROM a");
+        s.Step();
+      }
+      //t.Commit();
+    }
+
+    {
+      SQLite::Statement s(c, SQLITE_FROM_HERE, "SELECT * FROM a");
+      s.Step();
+    }
+  }
+  catch (OrthancException& e)
+  {
+    fprintf(stderr, "Exception: [%s]\n", e.What());
+    throw e;
+  }
+}
--- a/UnitTests/main.cpp	Tue Oct 09 18:21:01 2012 +0200
+++ b/UnitTests/main.cpp	Wed Oct 10 13:13:14 2012 +0200
@@ -325,6 +325,8 @@
 {
   // Initialize Google's logging library.
   FLAGS_logtostderr = true;
+  FLAGS_minloglevel = 0;
+  FLAGS_v = 1;
   google::InitGoogleLogging("Orthanc");
 
   OrthancInitialize();