------------------------------------------------------------
revno: 234
committer: John Deal <bassd...@yahoo.com>
branch nick: dbBackEnd
timestamp: Mon 2011-09-05 20:59:09 -0400
message:
Modified mira-server SQLite backend to privide optional one-time DB rebuild
or re-analyze initialization. Also modified compiler options to display
warnings.
modified:
mira-server/CompilerOptions.cmake.in
mira-server/conf/Directory.sqlite
mira-server/conf/mysqlInit.sql
mira-server/include/directory/db/DbDirectory.h
mira-server/include/directory/db/mysql/DbMySqlDirectory.h
mira-server/include/directory/db/sqlite/DbSqliteDirectory.h
mira-server/src/directory/db/DbDirectory.cpp
mira-server/src/directory/db/mysql/DbMySqlDirectory.cpp
mira-server/src/directory/db/sqlite/DbSqliteDirectory.cpp
mira-server/src/main.cpp
--
lp:~mira-dev/mira/dbBackEnd
https://code.launchpad.net/~mira-dev/mira/dbBackEnd
You are subscribed to branch lp:~mira-dev/mira/dbBackEnd.
To unsubscribe from this branch go to
https://code.launchpad.net/~mira-dev/mira/dbBackEnd/+edit-subscription
=== modified file 'mira-server/CompilerOptions.cmake.in'
--- mira-server/CompilerOptions.cmake.in 2009-11-09 04:12:33 +0000
+++ mira-server/CompilerOptions.cmake.in 2011-09-06 00:59:09 +0000
@@ -3,5 +3,5 @@
# gcc
IF (CMAKE_COMPILER_IS_GNUCC)
- SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-operator-names -g")
+ SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-operator-names -g -Wall")
ENDIF (CMAKE_COMPILER_IS_GNUCC)
=== modified file 'mira-server/conf/Directory.sqlite'
Binary files mira-server/conf/Directory.sqlite 2011-04-13 01:11:51 +0000 and mira-server/conf/Directory.sqlite 2011-09-06 00:59:09 +0000 differ
=== modified file 'mira-server/conf/mysqlInit.sql'
--- mira-server/conf/mysqlInit.sql 2011-08-12 01:38:32 +0000
+++ mira-server/conf/mysqlInit.sql 2011-09-06 00:59:09 +0000
@@ -29,7 +29,7 @@
workplaceName varchar(32) unique not null,
workplaceDesc varchar(255) not null,
createdOn bigint unsigned not null, /* Will store OS-specific timestamp */
- createdBy integer unsigned references users(userID), /* Currently not used */
+ createdBy integer unsigned /* references users(userID) */, /* Currently not used */
installedUtilities varchar(255) /* Comma separated list */
)
engine InnoDB;
=== modified file 'mira-server/include/directory/db/DbDirectory.h'
--- mira-server/include/directory/db/DbDirectory.h 2011-08-13 19:20:20 +0000
+++ mira-server/include/directory/db/DbDirectory.h 2011-09-06 00:59:09 +0000
@@ -33,23 +33,32 @@
namespace miraserver
{
-
namespace directory
{
+typedef struct
+{
+ std::string db_path;
+ bool clean; // Should be false except cleaning DB.
+ bool analyze;
+ bool vacuum;
+} db_config_struct;
+
enum dbType {sqlite, mysql};
class DbDirectory : public Directory
{
public:
- static std::string getConfigTypeName() { return "DIRECTORY_TYPE"; };
- static std::string getConfigPathName() { return "DIRECTORY_PATH"; };
- static std::string getConfigUserName() { return "DIRECTORY_USER"; };
- static std::string getConfigHostName() { return "DIRECTORY_HOST"; };
- static std::string getConfigDbName() { return "DIRECTORY_NAME"; };
- static std::string getConfigPassword() { return "DIRECTORY_PASSWORD"; };
- static std::string getConfigPort() { return "DIRECTORY_PORT"; };
- static std::string getConfigSocket() { return "DIRECTORY_SOCKET"; };
+ static std::string getConfigTypeName() {return "DIRECTORY_TYPE";};
+ static std::string getConfigPathName() {return "DIRECTORY_PATH";};
+ static std::string getConfigUserName() {return "DIRECTORY_USER";};
+ static std::string getConfigHostName() {return "DIRECTORY_HOST";};
+ static std::string getConfigDbName() {return "DIRECTORY_NAME";};
+ static std::string getConfigPassword() {return "DIRECTORY_PASSWORD";};
+ static std::string getConfigPort() {return "DIRECTORY_PORT";};
+ static std::string getConfigSocket() {return "DIRECTORY_SOCKET";};
+ static std::string getConfigRebuild() {return "DIRECTORY_REBUILD";};
+ static std::string getConfigAnalyze() {return "DIRECTORY_ANALYZE";};
typedef struct
{
@@ -62,7 +71,7 @@
typedef std::list<subscription_record> SubscriptionList;
DbDirectory(); // Should not be used directly.
- DbDirectory(dbType db_type, std::string path);
+ DbDirectory(dbType db_type, void* db_config);
~DbDirectory();
virtual unsigned int login(const std::string &username,
@@ -85,7 +94,8 @@
void load_plugins() {};
protected:
- std::string m_version_rec;
+ std::string m_version_rec;
+ db_config_struct m_db_config;
// Utility methods not involving database connections.
virtual std::string getFieldValue(Field field);
@@ -98,7 +108,6 @@
private:
dbType m_db_type;
- std::string m_db_path;
pthread_rwlock_t m_db_rwlock; // Read/write lock for DB.
pthread_mutex_t m_inst_table_lock; // Lock for instance table.
bool m_main_db_directory; // Flag for main DbDirectory
@@ -108,8 +117,8 @@
bool rlock_db(const std::string& module_name);
void unlock_db(const std::string& module_name);
DbDirectory* get_instance();
- // void* loopFindUser(void* userId);
- // void* loopAddUser(void* param);
+ // void* loopFindUser(void* userId); // For testing only!
+ // void* loopAddUser(void* param); // For testing only!
};
} // namespace directory
=== modified file 'mira-server/include/directory/db/mysql/DbMySqlDirectory.h'
--- mira-server/include/directory/db/mysql/DbMySqlDirectory.h 2011-08-28 15:47:45 +0000
+++ mira-server/include/directory/db/mysql/DbMySqlDirectory.h 2011-09-06 00:59:09 +0000
@@ -41,11 +41,10 @@
std::string workplace_name;
std::string workplace_description;
unsigned int created_on; // Timestamp.
- unsigned int created_by; // References user ID of creator.
+ unsigned int created_by; // References user ID of creator. Not used.
std::string installed_utilities; // Comma separated list.
} workplace_record;
-// typedef std::list<DbDirectory::subscription_record> SubscriptionList;
typedef std::list<unsigned int> IdList;
@@ -60,7 +59,7 @@
static const char *configDefaultSocket;
DbMySqlDirectory();
- DbMySqlDirectory(std::string path);
+ DbMySqlDirectory(void* db_config); // Parameter ignored for MySQL.
~DbMySqlDirectory();
bool add_user(User& user);
=== modified file 'mira-server/include/directory/db/sqlite/DbSqliteDirectory.h'
--- mira-server/include/directory/db/sqlite/DbSqliteDirectory.h 2011-08-28 15:47:45 +0000
+++ mira-server/include/directory/db/sqlite/DbSqliteDirectory.h 2011-09-06 00:59:09 +0000
@@ -41,22 +41,21 @@
std::string workplace_name;
std::string workplace_description;
unsigned int created_on; // Timestamp.
- unsigned int created_by; // References user ID of creator.
+ unsigned int created_by; // References user ID of creator. Not used.
std::string installed_utilities; // Comma separated list.
} workplace_record;
-// typedef std::list<DbDirectory::subscription_record> SubscriptionList;
typedef std::list<unsigned int> IdList;
-
class DbSqliteDirectory: public DbDirectory
{
public:
- static std::string getConfigTypeName() { return "SQLITE"; };
- static std::string getConfigDefaultPath() { return "Directory.sqlite"; };
+ static std::string getConfigTypeName() {return "SQLITE";};
+ static std::string getConfigDefaultPath() {return "Directory.sqlite";};
+ static std::string getConfigEnableReply() {return "ENABLE";};
DbSqliteDirectory();
- DbSqliteDirectory(std::string path);
+ DbSqliteDirectory(void* db_config);
~DbSqliteDirectory();
bool add_user(User& user);
@@ -90,9 +89,8 @@
WorkPlace find_workplace(const unsigned int workplace_id);
private:
- std::string m_db_path;
+ // db_config_struct m_db_config;
sqlite3* m_db;
- pid_t m_pid; // DEBUG!:JRD
// Prepared statements
sqlite3_stmt* m_prep_begin_transaction_exclusive;
@@ -141,6 +139,7 @@
unsigned int get_workplace_id(const std::string& workplace_name);
bool beginTransaction(const std::string& methodName);
bool commitTransaction(const int max_tries, const std::string& methodName);
+ void clean_db();
};
} // namespace directory
=== modified file 'mira-server/src/directory/db/DbDirectory.cpp'
--- mira-server/src/directory/db/DbDirectory.cpp 2011-08-13 19:20:20 +0000
+++ mira-server/src/directory/db/DbDirectory.cpp 2011-09-06 00:59:09 +0000
@@ -31,11 +31,6 @@
// End of includes needed for testing.
#include "DbSqliteDirectory.h"
-// #include "Crypto.h"
-// #include "field_defs.h"
-// #include "Field.h"
-// #include "Application.h"
-// #include "tools.h"
#include "DbDirectory.h"
#include "DbMySqlDirectory.h"
#include "DbSqliteDirectory.h"
@@ -46,6 +41,8 @@
namespace directory
{
+static bool first_time = true; // Flag for initializing on first invocation.
+
bool DbDirectory::wlock_db(const std::string& module_name)
{
int lock_error_code;
@@ -55,7 +52,7 @@
if (lock_error_code != 0)
{ // Error unlocking DB.
- std::cout << "Error (DbSqliteDirectory::" << module_name <<
+ std::cout << "Error (DbDirectory::" << module_name <<
"): Obtaining Write lock on DB failed. Error Code: " <<
lock_error_code << std::endl;
return false;
@@ -73,7 +70,7 @@
if (lock_error_code != 0)
{ // Error unlocking DB.
- std::cout << "Error (DbSqliteDirectory::" << module_name <<
+ std::cout << "Error (DbDirectory::" << module_name <<
"): Obtaining read lock on DB failed. Error Code: " <<
lock_error_code << std::endl;
return false;
@@ -91,7 +88,7 @@
if (unlock_error_code != 0)
{ // Error unlocking DB.
- std::cout << "Error (DbSqliteDirectory::" << module_name <<
+ std::cout << "Error (DbDirectory::" << module_name <<
"): Releasing lock on DB failed. Error Code: " <<
unlock_error_code << std::endl;
}
@@ -105,16 +102,20 @@
/********
This constructor should only be invoked once for the main DB Directory.
********/
-DbDirectory::DbDirectory(dbType db_type, std::string path)
+DbDirectory::DbDirectory(dbType db_type, void* db_config)
{
int pthread_return;
m_main_db_directory = true;
m_db_type = db_type;
- m_db_path = path;
-
-
- pthread_return = pthread_mutex_init(&m_inst_table_lock, NULL);
+ // m_db_path = path;
+ // m_db_config = db_config;
+ m_db_config.db_path = ((db_config_struct*) db_config)->db_path;
+ m_db_config.clean = ((db_config_struct*) db_config)->clean;
+ m_db_config.analyze = ((db_config_struct*) db_config)->analyze;
+ m_db_config.vacuum = ((db_config_struct*) db_config)->vacuum;
+
+ pthread_return = pthread_mutex_init(&m_inst_table_lock, NULL);
if (pthread_return != 0)
{
@@ -136,11 +137,36 @@
throw message;
}
- if (db_type == mysql)
- { // Initialize MySQL library.
- mysql_library_init(0, NULL, NULL);
- }
-}
+ if (first_time == true)
+ {
+ first_time = false;
+
+ switch(db_type)
+ {
+ case mysql:
+ { // Initialize MySQL library.
+ mysql_library_init(0, NULL, NULL);
+ break;
+ }
+
+ case sqlite:
+ { // Do DB clean if requested on temporary SQLite DB instance.
+ DbSqliteDirectory* temp_db;
+
+ m_db_config.clean = true;
+ temp_db = new DbSqliteDirectory((void*) &m_db_config);
+ delete temp_db;
+ m_db_config.clean = false;
+ break;
+ }
+
+ default:
+ {
+ throw "ERROR: Invalid Directory type specified.";
+ }
+ } // End switch(db_type).
+ } // End if (first_time == true).
+}
DbDirectory::~DbDirectory()
{
@@ -170,7 +196,8 @@
switch (m_db_type)
{
case sqlite:
- return_instance = new DbSqliteDirectory(m_db_path);
+ m_db_config.clean = false; // Clean only on global DB init.
+ return_instance = new DbSqliteDirectory((void*) &m_db_config);
break;
case mysql:
@@ -412,7 +439,6 @@
message = charMessage;
- // if (rlock_db("DbDirectory::find_workplace(int)") == false)
if (rlock_db(message) == false)
{ // Lock failed.
work_workplace.set_invalid();
@@ -421,7 +447,6 @@
work_workplace = get_instance()->find_workplace(workplace_id);
- // (void) unlock_db("DbDirectory::find_workplace(int)");
(void) unlock_db(message);
return work_workplace;
}
=== modified file 'mira-server/src/directory/db/mysql/DbMySqlDirectory.cpp'
--- mira-server/src/directory/db/mysql/DbMySqlDirectory.cpp 2011-08-28 15:47:45 +0000
+++ mira-server/src/directory/db/mysql/DbMySqlDirectory.cpp 2011-09-06 00:59:09 +0000
@@ -748,7 +748,7 @@
}
}
-DbMySqlDirectory::DbMySqlDirectory(): DbDirectory(mysql, "")
+DbMySqlDirectory::DbMySqlDirectory(): DbDirectory(mysql, NULL)
{
int mysql_result;
std::string workStr;
=== modified file 'mira-server/src/directory/db/sqlite/DbSqliteDirectory.cpp'
--- mira-server/src/directory/db/sqlite/DbSqliteDirectory.cpp 2011-08-28 15:47:45 +0000
+++ mira-server/src/directory/db/sqlite/DbSqliteDirectory.cpp 2011-09-06 00:59:09 +0000
@@ -119,23 +119,22 @@
// Enable shared cache. This is for the entire process (not just
// current thread).
errorCode = sqlite3_enable_shared_cache((int) true);
- // errorCode = sqlite3_enable_shared_cache((int) false);
if (errorCode != SQLITE_OK)
{ // Can't enable shared cache. Issue warning and run non-cached.
cout << "Warning: Opening of shared cache failed. Running non-cached. Error: "
- << errorCode << " Msg: " << sqlite3_errmsg(m_db) << endl;
+ << errorCode << endl;
}
// Open database in read/write multi-thread (one thread per connection)
// nmode.
- errorCode = sqlite3_open_v2(m_db_path.c_str(), &m_db,
+ errorCode = sqlite3_open_v2(m_db_config.db_path.c_str(), &m_db,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_SHAREDCACHE,
NULL);
if (errorCode != SQLITE_OK)
{ // Can't open database. Issue error.
- cout << "Error: Can;t open SQLite database " << m_db_path <<
+ cout << "Error: Can;t open SQLite database " << m_db_config.db_path <<
" Error Msg: " << sqlite3_errmsg(m_db) << endl;
success = false;
}
@@ -455,6 +454,53 @@
return results;
}
+/********
+ This method should only be called once once on the 1st open of the DB.
+********/
+void DbSqliteDirectory::clean_db()
+{
+ int error_code;
+ char** error_message = NULL; // To remove warning.
+ bool vacuumed = false;
+
+
+ if (m_db_config.vacuum == true)
+ { // Rebuild the DB.
+ cout << "Rebuilding SQLite database...." << endl;
+ error_code = sqlite3_exec(m_db, "vacuum", NULL, NULL, error_message);
+
+ if (error_code == SQLITE_OK)
+ {
+ vacuumed = true;
+ cout << "Successfully Rebuilt SQLite database."<< endl;
+ }
+ else
+ { // Error. Report and continue.
+ cout << "WARNING: Vacuum of Sqlite DB " << m_db_config.db_path <<
+ " FAILED. Error Code: " << error_code << ". Message: " <<
+ **error_message << "." << endl;
+ sqlite3_free((void*) error_message);
+ }
+ }
+
+ if ((vacuumed == false) && (m_db_config.analyze == true))
+ { // Re-analyze the DB if not already vacuumed.
+ error_code = sqlite3_exec(m_db, "analyze", NULL, NULL, error_message);
+
+ if (error_code == SQLITE_OK)
+ {
+ cout << "Successfully Re-analyzed SQLite database."<< endl;
+ }
+ else
+ { // Error. Report and continue.
+ cout << "WARNING: Analyze of Sqlite DB " << m_db_config.db_path <<
+ " FAILED. Error Code: " << error_code << ". Message: " <<
+ **error_message << "." << endl;
+ sqlite3_free((void*) error_message);
+ }
+ }
+}
+
DbSqliteDirectory::DbSqliteDirectory()
{
int error_code;
@@ -467,12 +513,13 @@
return;
}
- m_db_path = Application::get_configuration().GetConfiguration(
- DbDirectory::getConfigPathName());
+ // m_db_config.db_path = Application::get_configuration().GetConfiguration(
+ // DbDirectory::getConfigPathName());
+ m_db_config.db_path = getConfigDefaultPath();
if (!openDb())
{
- throw "Open of SQLite DB '" + m_db_path + "' failed.";
+ throw "Open of SQLite DB '" + m_db_config.db_path + "' failed.";
}
error_code = sqlite3_exec(m_db, m_set_foreign_keys, NULL, NULL,
@@ -486,26 +533,42 @@
}
}
-DbSqliteDirectory::DbSqliteDirectory(std::string path):
- DbDirectory(sqlite, path)
+DbSqliteDirectory::DbSqliteDirectory(void* db_config):
+ DbDirectory(sqlite, (void*) db_config)
{
int error_code;
int work_int;
- if (configMultiThread() == false)
- { // SQLite not configured for multi-thread operation. Can't use it.
- cout << "SQLite DB set to single treaded. Directory not started" <<
- endl;
+ m_db_config.db_path = ((db_config_struct*) db_config)->db_path;
+ m_db_config.clean = ((db_config_struct*) db_config)->clean;
+ m_db = NULL;
+
+ if (m_db_config.clean == true)
+ { // Clean and apply global configuration.
+ if (configMultiThread() == false)
+ { // SQLite not configured for multi-thread operation. Can't use it.
+ cout << "SQLite DB set to single treaded. Directory not started"
+ << endl;
return;
+ }
+
+ // Load the passed configuration parameters.
+ m_db_config.analyze = ((db_config_struct*) db_config)->analyze;
+ m_db_config.vacuum = ((db_config_struct*) db_config)->vacuum;
+
+ if (!openDb())
+ {
+ throw "Open of SQLite DB '" + m_db_config.db_path + "' failed.";
+ }
+
+ clean_db();
+ return; // Exit out of constructor.
}
- m_db_path = path;
- m_db = NULL;
-
if (!openDb())
{
- throw "Open of SQLite DB '" + m_db_path + "' failed.";
+ throw "Open of SQLite DB '" + m_db_config.db_path + "' failed.";
}
// Enable foreign key constraints.
@@ -548,7 +611,7 @@
msg += m_begin_transaction_exclusive_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -563,7 +626,7 @@
msg += m_rollback_transaction_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -577,7 +640,7 @@
msg += m_commit_transaction_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -592,7 +655,7 @@
msg += m_get_version_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -606,7 +669,8 @@
msg += m_update_version_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ // msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -620,7 +684,7 @@
msg += m_delete_version_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -635,7 +699,7 @@
msg += m_get_user_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -649,7 +713,8 @@
msg += m_get_user_username_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ // msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -663,7 +728,7 @@
msg += m_put_user_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -678,7 +743,7 @@
msg += m_update_user_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -692,7 +757,8 @@
msg += m_delete_user_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ // msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -707,7 +773,7 @@
msg += m_get_workplace_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -721,7 +787,7 @@
msg += m_get_workplace_id_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -736,7 +802,7 @@
msg += m_get_workplace_workplacename_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -750,7 +816,8 @@
msg += m_get_workplace_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ // msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -764,35 +831,36 @@
msg += m_get_workplace_sql;
msg += "' failed on database '";
- msg += m_db_path;
- msg += "'";
- throw msg;
- }
-
- error_code = sqlite3_prepare_v2(m_db, m_delete_workplace_sql,
- sizeof(m_delete_workplace_sql) + 1, &m_prep_delete_workplace, NULL);
-
- if (error_code != SQLITE_OK)
- {
- std::string msg = "Prep of statement '";
-
- msg += m_delete_workplace_sql;
- msg += "' failed on database '";
- msg += m_db_path;
- msg += "'";
- throw msg;
- }
-
- error_code = sqlite3_prepare_v2(m_db, m_delete_workplace_sql,
- sizeof(m_delete_workplace_sql) + 1, &m_prep_delete_workplace, NULL);
-
- if (error_code != SQLITE_OK)
- {
- std::string msg = "Prep of statement '";
-
- msg += m_delete_workplace_sql;
- msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
+ msg += "'";
+ throw msg;
+ }
+
+ error_code = sqlite3_prepare_v2(m_db, m_delete_workplace_sql,
+ sizeof(m_delete_workplace_sql) + 1, &m_prep_delete_workplace, NULL);
+
+ if (error_code != SQLITE_OK)
+ {
+ std::string msg = "Prep of statement '";
+
+ msg += m_delete_workplace_sql;
+ msg += "' failed on database '";
+ msg += m_db_config.db_path;
+ msg += "'";
+ throw msg;
+ }
+
+ error_code = sqlite3_prepare_v2(m_db, m_delete_workplace_sql,
+ sizeof(m_delete_workplace_sql) + 1, &m_prep_delete_workplace, NULL);
+
+ if (error_code != SQLITE_OK)
+ {
+ std::string msg = "Prep of statement '";
+
+ msg += m_delete_workplace_sql;
+ msg += "' failed on database '";
+ // msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -807,35 +875,35 @@
msg += m_get_role_type_sql;
msg += "' failed on database '";
- msg += m_db_path;
- msg += "'";
- throw msg;
- }
-
- error_code = sqlite3_prepare_v2(m_db, m_delete_role_type_sql,
- sizeof(m_delete_role_type_sql) + 1, &m_prep_delete_role_type, NULL);
-
- if (error_code != SQLITE_OK)
- {
- std::string msg = "Prep of statement '";
-
- msg += m_delete_role_type_sql;
- msg += "' failed on database '";
- msg + m_db_path;
- msg += "'";
- throw msg;
- }
-
- error_code = sqlite3_prepare_v2(m_db, m_delete_role_type_sql,
- sizeof(m_delete_role_type_sql) + 1, &m_prep_delete_role_type, NULL);
-
- if (error_code != SQLITE_OK)
- {
- std::string msg = "Prep of statement '";
-
- msg += m_delete_role_type_sql;
- msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
+ msg += "'";
+ throw msg;
+ }
+
+ error_code = sqlite3_prepare_v2(m_db, m_delete_role_type_sql,
+ sizeof(m_delete_role_type_sql) + 1, &m_prep_delete_role_type, NULL);
+
+ if (error_code != SQLITE_OK)
+ {
+ std::string msg = "Prep of statement '";
+
+ msg += m_delete_role_type_sql;
+ msg += "' failed on database '";
+ msg += m_db_config.db_path;
+ msg += "'";
+ throw msg;
+ }
+
+ error_code = sqlite3_prepare_v2(m_db, m_delete_role_type_sql,
+ sizeof(m_delete_role_type_sql) + 1, &m_prep_delete_role_type, NULL);
+
+ if (error_code != SQLITE_OK)
+ {
+ std::string msg = "Prep of statement '";
+
+ msg += m_delete_role_type_sql;
+ msg += "' failed on database '";
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -850,7 +918,7 @@
msg += m_get_role_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -864,7 +932,7 @@
msg += m_put_role_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -878,7 +946,7 @@
msg += m_delete_role_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -893,7 +961,7 @@
msg += m_get_subscription_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -908,7 +976,7 @@
msg += m_get_subscription_user_list_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -923,7 +991,7 @@
msg += m_get_subscription_workplace_list_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -937,7 +1005,8 @@
msg += m_put_subscription_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ // msg += m_db_path;
+ msg += m_db_config.db_path;
msg += "'";
throw msg;
}
@@ -952,7 +1021,7 @@
msg += m_delete_subscription_sql;
msg += "' failed on database '";
- msg += m_db_path;
+ msg += m_db_config.db_path;
msg + "'";
throw msg;
}
@@ -963,41 +1032,43 @@
int errorCode;
- // Finalize all prepared statements to release resources.
- sqlite3_finalize(m_prep_begin_transaction_exclusive);
- sqlite3_finalize(m_prep_rollback_transaction);
- sqlite3_finalize(m_prep_commit_transaction);
-
- sqlite3_finalize(m_prep_get_version);
- sqlite3_finalize(m_prep_update_version);
- sqlite3_finalize(m_prep_delete_version);
-
- sqlite3_finalize(m_prep_get_user);
- sqlite3_finalize(m_prep_get_user_username);
- sqlite3_finalize(m_prep_put_user);
- sqlite3_finalize(m_prep_update_user);
- sqlite3_finalize(m_prep_delete_user);
-
- sqlite3_finalize(m_prep_get_workplace);
- sqlite3_finalize(m_prep_get_workplace_id);
- sqlite3_finalize(m_prep_get_workplace_workplacename);
- sqlite3_finalize(m_prep_put_workplace);
- sqlite3_finalize(m_prep_update_workplace);
- sqlite3_finalize(m_prep_delete_workplace);
-
- sqlite3_finalize(m_prep_get_role_type);
- sqlite3_finalize(m_prep_put_role_type);
- sqlite3_finalize(m_prep_delete_role_type);
-
- sqlite3_finalize(m_prep_get_role);
- sqlite3_finalize(m_prep_put_role);
- sqlite3_finalize(m_prep_delete_role);
-
- sqlite3_finalize(m_prep_get_subscription);
- sqlite3_finalize(m_prep_get_subscription_user_list);
- sqlite3_finalize(m_prep_get_subscription_workplace_list);
- sqlite3_finalize(m_prep_put_subscription);
- sqlite3_finalize(m_prep_delete_subscription);
+ if (m_db_config.clean == false)
+ { // Normal instance. Finalize all prepared statements to release resources.
+ sqlite3_finalize(m_prep_begin_transaction_exclusive);
+ sqlite3_finalize(m_prep_rollback_transaction);
+ sqlite3_finalize(m_prep_commit_transaction);
+
+ sqlite3_finalize(m_prep_get_version);
+ sqlite3_finalize(m_prep_update_version);
+ sqlite3_finalize(m_prep_delete_version);
+
+ sqlite3_finalize(m_prep_get_user);
+ sqlite3_finalize(m_prep_get_user_username);
+ sqlite3_finalize(m_prep_put_user);
+ sqlite3_finalize(m_prep_update_user);
+ sqlite3_finalize(m_prep_delete_user);
+
+ sqlite3_finalize(m_prep_get_workplace);
+ sqlite3_finalize(m_prep_get_workplace_id);
+ sqlite3_finalize(m_prep_get_workplace_workplacename);
+ sqlite3_finalize(m_prep_put_workplace);
+ sqlite3_finalize(m_prep_update_workplace);
+ sqlite3_finalize(m_prep_delete_workplace);
+
+ sqlite3_finalize(m_prep_get_role_type);
+ sqlite3_finalize(m_prep_put_role_type);
+ sqlite3_finalize(m_prep_delete_role_type);
+
+ sqlite3_finalize(m_prep_get_role);
+ sqlite3_finalize(m_prep_put_role);
+ sqlite3_finalize(m_prep_delete_role);
+
+ sqlite3_finalize(m_prep_get_subscription);
+ sqlite3_finalize(m_prep_get_subscription_user_list);
+ sqlite3_finalize(m_prep_get_subscription_workplace_list);
+ sqlite3_finalize(m_prep_put_subscription);
+ sqlite3_finalize(m_prep_delete_subscription);
+ } // End if (m_db_config.clean == false).
if (m_db != NULL)
{
@@ -1005,8 +1076,8 @@
if (errorCode != SQLITE_OK)
{ // Close of db failed. Issue warning.
- cout << "Warning: Closing of db '" << m_db_path << "' failed." <<
- endl;
+ cout << "Warning: Closing of db '" << m_db_config.db_path <<
+ "' failed." << endl;
}
} // End if m_db != NULL
}
=== modified file 'mira-server/src/main.cpp'
--- mira-server/src/main.cpp 2011-06-30 15:37:01 +0000
+++ mira-server/src/main.cpp 2011-09-06 00:59:09 +0000
@@ -237,6 +237,9 @@
int main(int argc, char* argv[])
{
+ std:string workConfig;
+
+
try
{
Application::set_configuration(new ConfigParser);
@@ -248,45 +251,73 @@
DbDirectory::getConfigTypeName());
Application::get_configuration().InsertItem(
DbDirectory::getConfigPathName());
+ Application::get_configuration().InsertItem(
+ DbDirectory::getConfigAnalyze());
+ Application::get_configuration().InsertItem(
+ DbDirectory::getConfigRebuild());
// Application::get_configuration().InsertItem("ASIO_INPUT_BUFFER_SIZE");
Application::get_configuration().ParseConfigFile();
- { // Set type of directory to use.
- std:string workConfig;
-
- workConfig = Application::get_configuration().GetConfiguration(
- "DIRECTORY_TYPE");
-
- if ((workConfig.compare("") == 0) || (workConfig.compare(
- DbSqliteDirectory::getConfigTypeName()) == 0))
- { // SQLite specified or taken as default.
- workConfig = Application::get_configuration().GetConfiguration(
+ workConfig = Application::get_configuration().GetConfiguration(
+ // "DIRECTORY_TYPE");
+ DbDirectory::getConfigTypeName());
+
+ if ((workConfig.compare("") == 0) || (workConfig.compare(
+ DbSqliteDirectory::getConfigTypeName()) == 0))
+ { // SQLite specified or taken as default.
+ directory::db_config_struct db_config;
+
+ db_config.db_path =
+ Application::get_configuration().GetConfiguration(
DbDirectory::getConfigPathName());
- if (workConfig.compare("") == 0)
- { // Set default path for SQLite DB.
- workConfig = DbSqliteDirectory::getConfigDefaultPath();
- }
-
- // dbLoadTest(new DbDirectory(sqlite, workConfig)); // TEST! DB load test.
- Application::set_directory(new DbDirectory(sqlite, workConfig));
- }
- else
- {
- if (workConfig.compare(DbMySqlDirectory::configTypeName)
- == 0)
- { // MySql specified.
- Application::set_directory(new DbDirectory(mysql,
- workConfig));
- }
- else
- { // Directory is XML file.
- Application::set_directory(new PlainTextDirectory(
- "Directory.xml"));
- }
- }
- } // End set type of directory.
+ if (db_config.db_path.compare("") == 0)
+ { // Set default path for SQLite DB.
+ db_config.db_path =
+ DbSqliteDirectory::getConfigDefaultPath();
+ }
+
+ if (Application::get_configuration().GetConfiguration(
+ DbDirectory::getConfigAnalyze()).compare(
+ DbSqliteDirectory::getConfigEnableReply()) == 0)
+ { // Analyze DB before use.
+ db_config.analyze = true;
+ }
+ else
+ {
+ db_config.analyze = false;
+ }
+
+ if (Application::get_configuration().GetConfiguration(
+ DbSqliteDirectory::getConfigRebuild()).compare(
+ DbSqliteDirectory::getConfigEnableReply()) == 0)
+ { // Vacuum (rebuild) DB before use.
+ db_config.vacuum = true;
+ }
+ else
+ {
+ db_config.vacuum = false;
+ }
+
+ // dbLoadTest(new DbDirectory(sqlite, workConfig)); // TEST! DB load test.
+ Application::set_directory(new DbDirectory(sqlite,
+ (void *) &db_config));
+ }
+ else
+ {
+ if (workConfig.compare(DbMySqlDirectory::configTypeName)
+ == 0)
+ { // MySql specified.
+ Application::set_directory(new DbDirectory(mysql,
+ (void*) NULL));
+ }
+ else
+ { // Directory is XML file.
+ Application::set_directory(new PlainTextDirectory(
+ "Directory.xml"));
+ }
+ }
Application::set_server(new AsioServer(Application::get_configuration().GetConfigurationAsInt("PORT")));
------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Mira-development mailing list
Mira-development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mira-development