#include <memory>
#include <dpl/noncopyable.h>
#include <dpl/assert.h>
+#include <dpl/log/log.h>
#include <unistd.h>
#include <cstdio>
#include <cstdarg>
return;
}
- VcoreLogD("Notifying after successful synchronize");
+ LogDebug("Notifying after successful synchronize");
m_synchronizationObject->NotifyAll();
}
};
&m_stmt, NULL);
if (ret == SQLITE_OK) {
- VcoreLogD("Data command prepared successfuly");
+ LogDebug("Data command prepared successfuly");
break;
} else if (ret == SQLITE_BUSY) {
- VcoreLogD("Collision occurred while preparing SQL command");
+ LogDebug("Collision occurred while preparing SQL command");
// Synchronize if synchronization object is available
if (connection->m_synchronizationObject) {
- VcoreLogD("Performing synchronization");
+ LogDebug("Performing synchronization");
connection->m_synchronizationObject->Synchronize();
continue;
}
// Fatal error
const char *error = sqlite3_errmsg(m_masterConnection->m_connection);
- VcoreLogD("SQL prepare data command failed");
- VcoreLogD(" Statement: %s", buffer);
- VcoreLogD(" Error: %s", error);
+ LogDebug("SQL prepare data command failed");
+ LogDebug(" Statement : " << buffer);
+ LogDebug(" Error : " << error);
ThrowMsg(Exception::SyntaxError, error);
}
- VcoreLogD("Prepared data command: %s", buffer);
+ LogDebug("Prepared data command : " << buffer);
// Increment stored data command count
++m_masterConnection->m_dataCommandsCount;
SqlConnection::DataCommand::~DataCommand()
{
- VcoreLogD("SQL data command finalizing");
+ LogDebug("SQL data command finalizing");
if (sqlite3_finalize(m_stmt) != SQLITE_OK) {
- VcoreLogD("Failed to finalize data command");
+ LogDebug("Failed to finalize data command");
}
// Decrement stored data command count
const char *error = sqlite3_errmsg(
m_masterConnection->m_connection);
- VcoreLogD("Failed to bind SQL statement parameter");
- VcoreLogD(" Error: %s", error);
+ LogDebug("Failed to bind SQL statement parameter");
+ LogDebug(" Error : " << error);
ThrowMsg(Exception::SyntaxError, error);
}
SqlConnection::ArgumentIndex position)
{
CheckBindResult(sqlite3_bind_null(m_stmt, position));
- VcoreLogD("SQL data command bind null: [%i]", position);
+ LogDebug("SQL data command bind null: [" << position << "]");
}
void SqlConnection::DataCommand::BindInteger(
int value)
{
CheckBindResult(sqlite3_bind_int(m_stmt, position, value));
- VcoreLogD("SQL data command bind integer: [%i] -> %i", position, value);
+ LogDebug("SQL data command bind integer: [" << position << "] -> " << value);
}
void SqlConnection::DataCommand::BindInt8(
{
CheckBindResult(sqlite3_bind_int(m_stmt, position,
static_cast<int>(value)));
- VcoreLogD("SQL data command bind int8: [%i] -> %i", position, value);
+ LogDebug("SQL data command bind int8: [" << position << "] -> " << value);
}
void SqlConnection::DataCommand::BindInt16(
{
CheckBindResult(sqlite3_bind_int(m_stmt, position,
static_cast<int>(value)));
- VcoreLogD("SQL data command bind int16: [%i] -> %i", position, value);
-}
+ LogDebug("SQL data command bind int16: [" << position << "] -> " << value);}
void SqlConnection::DataCommand::BindInt32(
SqlConnection::ArgumentIndex position,
{
CheckBindResult(sqlite3_bind_int(m_stmt, position,
static_cast<int>(value)));
- VcoreLogD("SQL data command bind int32: [%i] -> %i", position, value);
+ LogDebug("SQL data command bind int32: [" << position << "] -> " << value);
}
void SqlConnection::DataCommand::BindInt64(
{
CheckBindResult(sqlite3_bind_int64(m_stmt, position,
static_cast<sqlite3_int64>(value)));
- VcoreLogD("SQL data command bind int64: [%i] -> %lli", position, value);
+ LogDebug("SQL data command bind int64: [" << position << "] -> " << value);
}
void SqlConnection::DataCommand::BindFloat(
{
CheckBindResult(sqlite3_bind_double(m_stmt, position,
static_cast<double>(value)));
- VcoreLogD("SQL data command bind float: [%i] -> %f", position, value);
+ LogDebug("SQL data command bind float: [" << position << "] -> " << value);
}
void SqlConnection::DataCommand::BindDouble(
double value)
{
CheckBindResult(sqlite3_bind_double(m_stmt, position, value));
- VcoreLogD("SQL data command bind double: [%i] -> %f", position, value);
+ LogDebug("SQL data command bind double: [" << position << "] -> " << value);
}
void SqlConnection::DataCommand::BindString(
value, strlen(value),
SQLITE_TRANSIENT));
- VcoreLogD("SQL data command bind string: [%i] -> %s", position, value);
+ LogDebug("SQL data command bind string: [" << position << "] -> " << value);
}
void SqlConnection::DataCommand::BindString(
int ret = sqlite3_step(m_stmt);
if (ret == SQLITE_ROW) {
- VcoreLogD("SQL data command step ROW");
+ LogDebug("SQL data command step ROW");
return true;
} else if (ret == SQLITE_DONE) {
- VcoreLogD("SQL data command step DONE");
+ LogDebug("SQL data command step DONE");
return false;
} else if (ret == SQLITE_BUSY) {
- VcoreLogD("Collision occurred while executing SQL command");
+ LogDebug("Collision occurred while executing SQL command");
// Synchronize if synchronization object is available
if (m_masterConnection->m_synchronizationObject) {
- VcoreLogD("Performing synchronization");
+ LogDebug("Performing synchronization");
m_masterConnection->
m_synchronizationObject->Synchronize();
// Fatal error
const char *error = sqlite3_errmsg(m_masterConnection->m_connection);
- VcoreLogD("SQL step data command failed");
- VcoreLogD(" Error: %s", error);
+ LogDebug("SQL step data command failed");
+ LogDebug(" Error : " << error);
ThrowMsg(Exception::InternalError, error);
}
*/
sqlite3_reset(m_stmt);
- VcoreLogD("SQL data command reset");
+ LogDebug("SQL data command reset");
}
void SqlConnection::DataCommand::CheckColumnIndex(
bool SqlConnection::DataCommand::IsColumnNull(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column type: [%i]", column);
+ LogDebug("SQL data command get column type: [" << column << "]");
CheckColumnIndex(column);
return sqlite3_column_type(m_stmt, column) == SQLITE_NULL;
}
int SqlConnection::DataCommand::GetColumnInteger(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column integer: [%i]", column);
+ LogDebug("SQL data command get column integer: [" << column << "]");
CheckColumnIndex(column);
int value = sqlite3_column_int(m_stmt, column);
- VcoreLogD(" Value: %i", value);
+ LogDebug(" Value : " << value);
return value;
}
int8_t SqlConnection::DataCommand::GetColumnInt8(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column int8: [%i]", column);
+ LogDebug("SQL data command get column int8: [" << column << "]");
CheckColumnIndex(column);
int8_t value = static_cast<int8_t>(sqlite3_column_int(m_stmt, column));
- VcoreLogD(" Value: %i", value);
+ LogDebug(" Value : " << value);
return value;
}
int16_t SqlConnection::DataCommand::GetColumnInt16(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column int16: [%i]", column);
+ LgDebug("SQL data command get column int16: [" << column << "]");
CheckColumnIndex(column);
int16_t value = static_cast<int16_t>(sqlite3_column_int(m_stmt, column));
- VcoreLogD(" Value: %i", value);
+ LogDebug(" Value : " << value);
return value;
}
int32_t SqlConnection::DataCommand::GetColumnInt32(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column int32: [%i]", column);
+ LogDebug("SQL data command get column int32: [" << column << "]");
CheckColumnIndex(column);
int32_t value = static_cast<int32_t>(sqlite3_column_int(m_stmt, column));
- VcoreLogD(" Value: %i", value);
+ LogDebug(" Value : " << value);
return value;
}
int64_t SqlConnection::DataCommand::GetColumnInt64(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column int64: [%i]", column);
+ LogDebug("SQL data command get column int64: [" << column << "]");
CheckColumnIndex(column);
int64_t value = static_cast<int64_t>(sqlite3_column_int64(m_stmt, column));
- VcoreLogD(" Value: %lli", value);
+ LogDebug(" Value : " << value);
return value;
}
float SqlConnection::DataCommand::GetColumnFloat(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column float: [%i]", column);
+ LogDebug("SQL data command get column float: [" << column << "]");
CheckColumnIndex(column);
float value = static_cast<float>(sqlite3_column_double(m_stmt, column));
- VcoreLogD(" Value: %f", value);
+ LogDebug(" Value : " << value);
return value;
}
double SqlConnection::DataCommand::GetColumnDouble(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column double: [%i]", column);
+ LogDebug("SQL data command get column double: [" << column << "]");
CheckColumnIndex(column);
double value = sqlite3_column_double(m_stmt, column);
- VcoreLogD(" Value: %f", value);
+ LogDebug(" Value : " << value);
return value;
}
std::string SqlConnection::DataCommand::GetColumnString(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column string: [%i]", column);
+ LogDebug("SQL data command get column string: [" << column << "]");
CheckColumnIndex(column);
const char *value = reinterpret_cast<const char *>(
sqlite3_column_text(m_stmt, column));
- VcoreLogD(" Value: %s", value);
+ LogDebug(" Value : " << value);
if (value == NULL) {
return std::string();
boost::optional<int> SqlConnection::DataCommand::GetColumnOptionalInteger(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column optional integer: [%i]", column);
+ LogDebug("SQL data command get column optional integer: [" << column << "]");
CheckColumnIndex(column);
if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) {
return boost::optional<int>();
}
int value = sqlite3_column_int(m_stmt, column);
- VcoreLogD(" Value: %i", value);
+ LogDebug(" Value : " << value);
return boost::optional<int>(value);
}
boost::optional<int8_t> SqlConnection::DataCommand::GetColumnOptionalInt8(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column optional int8: [%i]", column);
+ LogDebug("SQL data command get column optional int8: [" << column << "]");
CheckColumnIndex(column);
if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) {
return boost::optional<int8_t>();
}
int8_t value = static_cast<int8_t>(sqlite3_column_int(m_stmt, column));
- VcoreLogD(" Value: %i", value);
+ LogDebug(" Value: " << value);
return boost::optional<int8_t>(value);
}
boost::optional<int16_t> SqlConnection::DataCommand::GetColumnOptionalInt16(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column optional int16: [%i]", column);
+ LogDebug("SQL data command get column optional int16: [" << column << "]");
CheckColumnIndex(column);
if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) {
return boost::optional<int16_t>();
}
int16_t value = static_cast<int16_t>(sqlite3_column_int(m_stmt, column));
- VcoreLogD(" Value: %i", value);
+ LogDebug(" Value : " << value);
return boost::optional<int16_t>(value);
}
boost::optional<int32_t> SqlConnection::DataCommand::GetColumnOptionalInt32(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column optional int32: [%i]", column);
+ LogDebug("SQL data command get column optional int32: [" << column << "]");
CheckColumnIndex(column);
if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) {
return boost::optional<int32_t>();
}
int32_t value = static_cast<int32_t>(sqlite3_column_int(m_stmt, column));
- VcoreLogD(" Value: %i", value);
+ LogDebug(" Value : " << value);
return boost::optional<int32_t>(value);
}
boost::optional<int64_t> SqlConnection::DataCommand::GetColumnOptionalInt64(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column optional int64: [%i]", column);
+ LogDebug("SQL data command get column optional int64: [" << column << "]");
CheckColumnIndex(column);
if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) {
return boost::optional<int64_t>();
}
int64_t value = static_cast<int64_t>(sqlite3_column_int64(m_stmt, column));
- VcoreLogD(" Value: %lli", value);
+ LogDebug(" Value : " << value);
return boost::optional<int64_t>(value);
}
boost::optional<float> SqlConnection::DataCommand::GetColumnOptionalFloat(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column optional float: [%i]", column);
+ LogDebug("SQL data command get column optional float: [" << column << "]");
CheckColumnIndex(column);
if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) {
return boost::optional<float>();
}
float value = static_cast<float>(sqlite3_column_double(m_stmt, column));
- VcoreLogD(" Value: %f", value);
+ LogDebug(" Value : " << value);
return boost::optional<float>(value);
}
boost::optional<double> SqlConnection::DataCommand::GetColumnOptionalDouble(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column optional double: [%i]", column);
+ LogDebug("SQL data command get column optional double: [" << column << "]");
CheckColumnIndex(column);
if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) {
return boost::optional<double>();
}
double value = sqlite3_column_double(m_stmt, column);
- VcoreLogD(" Value: %f", value);
+ LogDebug(" Value : " << value);
return boost::optional<double>(value);
}
boost::optional<String> SqlConnection::DataCommand::GetColumnOptionalString(
SqlConnection::ColumnIndex column)
{
- VcoreLogD("SQL data command get column optional string: [%i]", column);
+ LogDebug("SQL data command get column optional string: [" << column << "]");
CheckColumnIndex(column);
if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL) {
return boost::optional<String>();
}
const char *value = reinterpret_cast<const char *>(
sqlite3_column_text(m_stmt, column));
- VcoreLogD(" Value: %s", value);
+ LogDebug(" Value : " << value);
String s = FromUTF8String(value);
return boost::optional<String>(s);
}
Flag::Option flag)
{
if (m_connection != NULL) {
- VcoreLogD("Already connected.");
+ LogDebug("Already connected.");
return;
}
- VcoreLogD("Connecting to DB: %s...", address.c_str());
+ LogDebug("Connecting to DB: " << address << "...");
// Connect to database
int result;
NULL);
m_usingLucene = true;
- VcoreLogD("Lucene index enabled");
+ LogDebug("Lucene index enabled");
} else {
result = sqlite3_open_v2(
address.c_str(),
NULL);
m_usingLucene = false;
- VcoreLogD("Lucene index disabled");
+ LogDebug("Lucene index disabled");
}
if (result == SQLITE_OK) {
- VcoreLogD("Connected to DB");
+ LogDebug("Connected to DB");
} else {
- VcoreLogD("Failed to connect to DB!");
+ LogDebug("Failed to connect to DB!");
ThrowMsg(Exception::ConnectionBroken, address);
}
void SqlConnection::Disconnect()
{
if (m_connection == NULL) {
- VcoreLogD("Already disconnected.");
+ LogDebug("Already disconnected.");
return;
}
- VcoreLogD("Disconnecting from DB...");
+ LogDebug("Disconnecting from DB...");
// All stored data commands must be deleted before disconnect
AssertMsg(m_dataCommandsCount == 0,
if (result != SQLITE_OK) {
const char *error = sqlite3_errmsg(m_connection);
- VcoreLogD("SQL close failed");
- VcoreLogD(" Error: %s", error);
+ LogDebug("SQL close failed");
+ LogDebug(" Error : " << error);
Throw(Exception::InternalError);
}
m_connection = NULL;
- VcoreLogD("Disconnected from DB");
+ LogDebug("Disconnected from DB");
}
bool SqlConnection::CheckTableExist(const char *tableName)
{
if (m_connection == NULL) {
- VcoreLogD("Cannot execute command. Not connected to DB!");
+ LogDebug("Cannot execute command. Not connected to DB!");
return false;
}
command->BindString(1, tableName);
if (!command->Step()) {
- VcoreLogD("No matching records in table");
+ LogDebug("No matching records in table");
return false;
}
m_dataCommandsCount(0),
m_synchronizationObject(synchronizationObject)
{
- VcoreLogD("Opening database connection to: %s", address.c_str());
+ LogDebug("Opening database connection to : " << address);
// Connect to DB
SqlConnection::Connect(address, flag, option);
if (!m_synchronizationObject) {
- VcoreLogD("No synchronization object defined");
+ LogDebug("No synchronization object defined");
}
}
SqlConnection::~SqlConnection()
{
- VcoreLogD("Closing database connection");
+ LogDebug("Closing database connection");
// Disconnect from DB
Try
}
Catch(Exception::Base)
{
- VcoreLogD("Failed to disconnect from database");
+ LogDebug("Failed to disconnect from database");
}
}
void SqlConnection::ExecCommand(const char *format, ...)
{
if (m_connection == NULL) {
- VcoreLogD("Cannot execute command. Not connected to DB!");
+ LogDebug("Cannot execute command. Not connected to DB!");
return;
}
if (format == NULL) {
- VcoreLogD("Null query!");
+ LogDebug("Null query!");
ThrowMsg(Exception::SyntaxError, "Null statement");
}
std::unique_ptr<char[],free_deleter> buffer(rawBuffer);
if (!buffer) {
- VcoreLogD("Failed to allocate statement string");
+ LogDebug("Failed to allocate statement string");
return;
}
- VcoreLogD("Executing SQL command: %s", buffer.get());
+ LogDebug("Executing SQL command : " << buffer.get());
// Notify all after potentially synchronized database connection access
ScopedNotifyAll notifyAll(m_synchronizationObject.get());
}
if (ret == SQLITE_BUSY) {
- VcoreLogD("Collision occurred while executing SQL command");
+ LogDebug("Collision occurred while executing SQL command");
// Synchronize if synchronization object is available
if (m_synchronizationObject) {
- VcoreLogD("Performing synchronization");
+ LogDebug("Performing synchronization");
m_synchronizationObject->Synchronize();
continue;
}
}
// Fatal error
- VcoreLogD("Failed to execute SQL command. Error: %s", errorMsg.c_str());
+ LogDebug("Failed to execute SQL command. Error : " << errorMsg);
ThrowMsg(Exception::SyntaxError, errorMsg);
}
}
...)
{
if (m_connection == NULL) {
- VcoreLogD("Cannot execute data command. Not connected to DB!");
+ LogDebug("Cannot execute data command. Not connected to DB!");
return DataCommandAutoPtr();
}
std::unique_ptr<char[],free_deleter> buffer(rawBuffer);
if (!buffer) {
- VcoreLogD("Failed to allocate statement string");
+ LogDebug("Failed to allocate statement string");
return DataCommandAutoPtr();
}
- VcoreLogD("Executing SQL data command: %s", buffer.get());
+ LogDebug("Executing SQL data command : " << buffer.get());
return DataCommandAutoPtr(new DataCommand(this, buffer.get()));
}
int mode;
if((pszFilePath == NULL) || (ppDB == NULL)) {
- VcoreLogW("sqlite3 handle null error");
+ LogWarning("sqlite3 handle null error");
return SQLITE_ERROR;
}
if((geteuid() != 0) && (access(pszFilePath, mode))) {
if(errno == EACCES) {
- VcoreLogD("file access permission error");
+ LogDebug("file access permission error");
return SQLITE_PERM;
}
}
/* Open DB */
int rc = sqlite3_open_v2(pszFilePath, ppDB, flags, zVfs);
if (SQLITE_OK != rc) {
- VcoreLogE("sqlite3_open_v2 error(%d)",rc);
+ LogError("sqlite3_open_v2 error(" << rc << ")");
return rc;
}
/* Close DB */
int rc = sqlite3_close(pDB);
if (SQLITE_OK != rc) {
- VcoreLogW("Fail to change journal mode: %s\n", pszErrorMsg);
+ LogWarning("Fail to change journal mode : " << pszErrorMsg);
sqlite3_free(pszErrorMsg);
return rc;
}