mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-10 00:43:59 +02:00
Fix code style consistency in lobby server project
This commit is contained in:
parent
428a71087a
commit
50c1452221
@ -56,7 +56,7 @@ LobbyDatabase::LobbyDatabase(const std::string & databasePath)
|
|||||||
{
|
{
|
||||||
database = SQLiteInstance::open(databasePath, true);
|
database = SQLiteInstance::open(databasePath, true);
|
||||||
|
|
||||||
if (!database)
|
if(!database)
|
||||||
throw std::runtime_error("Failed to open SQLite database!");
|
throw std::runtime_error("Failed to open SQLite database!");
|
||||||
|
|
||||||
initializeDatabase();
|
initializeDatabase();
|
||||||
|
@ -77,7 +77,7 @@ public:
|
|||||||
std::vector<GameRoom> getActiveGameRooms();
|
std::vector<GameRoom> getActiveGameRooms();
|
||||||
std::vector<ChatMessage> getRecentMessageHistory();
|
std::vector<ChatMessage> getRecentMessageHistory();
|
||||||
|
|
||||||
bool checkAccessCookie(const std::string & accountName,const std::string & accessCookieUUID);
|
bool checkAccessCookie(const std::string & accountName, const std::string & accessCookieUUID);
|
||||||
bool isPlayerInGameRoom(const std::string & accountName);
|
bool isPlayerInGameRoom(const std::string & accountName);
|
||||||
bool isAccountNameAvailable(const std::string & accountName);
|
bool isAccountNameAvailable(const std::string & accountName);
|
||||||
};
|
};
|
||||||
|
@ -21,7 +21,7 @@ void LobbyServer::sendMessage(const std::shared_ptr<NetworkConnection> & target,
|
|||||||
std::string payloadString = json.toJson(true);
|
std::string payloadString = json.toJson(true);
|
||||||
|
|
||||||
// FIXME: find better approach
|
// FIXME: find better approach
|
||||||
uint8_t * payloadBegin = reinterpret_cast<uint8_t*>(payloadString.data());
|
uint8_t * payloadBegin = reinterpret_cast<uint8_t *>(payloadString.data());
|
||||||
uint8_t * payloadEnd = payloadBegin + payloadString.size();
|
uint8_t * payloadEnd = payloadBegin + payloadString.size();
|
||||||
|
|
||||||
std::vector<uint8_t> payloadBuffer(payloadBegin, payloadEnd);
|
std::vector<uint8_t> payloadBuffer(payloadBegin, payloadEnd);
|
||||||
@ -35,8 +35,7 @@ void LobbyServer::onTimer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LobbyServer::onNewConnection(const std::shared_ptr<NetworkConnection> & connection)
|
void LobbyServer::onNewConnection(const std::shared_ptr<NetworkConnection> & connection)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
void LobbyServer::onDisconnected(const std::shared_ptr<NetworkConnection> & connection)
|
void LobbyServer::onDisconnected(const std::shared_ptr<NetworkConnection> & connection)
|
||||||
{
|
{
|
||||||
@ -48,19 +47,19 @@ void LobbyServer::onPacketReceived(const std::shared_ptr<NetworkConnection> & co
|
|||||||
// FIXME: find better approach
|
// FIXME: find better approach
|
||||||
JsonNode json(message.data(), message.size());
|
JsonNode json(message.data(), message.size());
|
||||||
|
|
||||||
if (json["type"].String() == "sendChatMessage")
|
if(json["type"].String() == "sendChatMessage")
|
||||||
return receiveSendChatMessage(connection, json);
|
return receiveSendChatMessage(connection, json);
|
||||||
|
|
||||||
if (json["type"].String() == "authentication")
|
if(json["type"].String() == "authentication")
|
||||||
return receiveAuthentication(connection, json);
|
return receiveAuthentication(connection, json);
|
||||||
|
|
||||||
if (json["type"].String() == "joinGameRoom")
|
if(json["type"].String() == "joinGameRoom")
|
||||||
return receiveJoinGameRoom(connection, json);
|
return receiveJoinGameRoom(connection, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyServer::receiveSendChatMessage(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json)
|
void LobbyServer::receiveSendChatMessage(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json)
|
||||||
{
|
{
|
||||||
if (activeAccounts.count(connection) == 0)
|
if(activeAccounts.count(connection) == 0)
|
||||||
return; // unauthenticated
|
return; // unauthenticated
|
||||||
|
|
||||||
std::string senderName = activeAccounts[connection].accountName;
|
std::string senderName = activeAccounts[connection].accountName;
|
||||||
@ -73,7 +72,7 @@ void LobbyServer::receiveSendChatMessage(const std::shared_ptr<NetworkConnection
|
|||||||
reply["messageText"].String() = messageText;
|
reply["messageText"].String() = messageText;
|
||||||
reply["senderName"].String() = senderName;
|
reply["senderName"].String() = senderName;
|
||||||
|
|
||||||
for (auto const & connection : activeAccounts)
|
for(const auto & connection : activeAccounts)
|
||||||
sendMessage(connection.first, reply);
|
sendMessage(connection.first, reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +101,7 @@ void LobbyServer::receiveAuthentication(const std::shared_ptr<NetworkConnection>
|
|||||||
JsonNode reply;
|
JsonNode reply;
|
||||||
reply["type"].String() = "chatHistory";
|
reply["type"].String() = "chatHistory";
|
||||||
|
|
||||||
for (auto const & message : boost::adaptors::reverse(history))
|
for(const auto & message : boost::adaptors::reverse(history))
|
||||||
{
|
{
|
||||||
JsonNode jsonEntry;
|
JsonNode jsonEntry;
|
||||||
|
|
||||||
@ -119,12 +118,12 @@ void LobbyServer::receiveAuthentication(const std::shared_ptr<NetworkConnection>
|
|||||||
|
|
||||||
void LobbyServer::receiveJoinGameRoom(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json)
|
void LobbyServer::receiveJoinGameRoom(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json)
|
||||||
{
|
{
|
||||||
if (activeAccounts.count(connection) == 0)
|
if(activeAccounts.count(connection) == 0)
|
||||||
return; // unauthenticated
|
return; // unauthenticated
|
||||||
|
|
||||||
std::string senderName = activeAccounts[connection].accountName;
|
std::string senderName = activeAccounts[connection].accountName;
|
||||||
|
|
||||||
if (database->isPlayerInGameRoom(senderName))
|
if(database->isPlayerInGameRoom(senderName))
|
||||||
return; // only 1 room per player allowed
|
return; // only 1 room per player allowed
|
||||||
|
|
||||||
// TODO: roomType: private, public
|
// TODO: roomType: private, public
|
||||||
|
@ -41,6 +41,7 @@ class LobbyServer : public INetworkServerListener
|
|||||||
void receiveSendChatMessage(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json);
|
void receiveSendChatMessage(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json);
|
||||||
void receiveAuthentication(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json);
|
void receiveAuthentication(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json);
|
||||||
void receiveJoinGameRoom(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json);
|
void receiveJoinGameRoom(const std::shared_ptr<NetworkConnection> & connection, const JsonNode & json);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LobbyServer(const std::string & databasePath);
|
LobbyServer(const std::string & databasePath);
|
||||||
~LobbyServer();
|
~LobbyServer();
|
||||||
|
@ -12,111 +12,113 @@
|
|||||||
|
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
|
||||||
static void on_sqlite_error( sqlite3 * connection, [[maybe_unused]] int result )
|
[[noreturn]] static void handleSQLiteError(sqlite3 * connection)
|
||||||
{
|
{
|
||||||
if ( result != SQLITE_OK )
|
const char * message = sqlite3_errmsg(connection);
|
||||||
{
|
throw std::runtime_error(std::string("SQLite error: ") + message);
|
||||||
const char * message = sqlite3_errmsg( connection );
|
|
||||||
printf( "sqlite error: %s\n", message );
|
|
||||||
}
|
|
||||||
|
|
||||||
assert( result == SQLITE_OK );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SQLiteStatement::SQLiteStatement( SQLiteInstance & instance, sqlite3_stmt * statement ):
|
static void checkSQLiteError(sqlite3 * connection, int result)
|
||||||
m_instance( instance ),
|
{
|
||||||
m_statement( statement )
|
if(result != SQLITE_OK)
|
||||||
{ }
|
handleSQLiteError(connection);
|
||||||
|
|
||||||
SQLiteStatement::~SQLiteStatement( )
|
|
||||||
{
|
|
||||||
int result = sqlite3_finalize( m_statement );
|
|
||||||
on_sqlite_error( m_instance.m_connection, result );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SQLiteStatement::execute( )
|
SQLiteStatement::SQLiteStatement(SQLiteInstance & instance, sqlite3_stmt * statement)
|
||||||
{
|
: m_instance(instance)
|
||||||
int result = sqlite3_step( m_statement );
|
, m_statement(statement)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
switch ( result )
|
SQLiteStatement::~SQLiteStatement()
|
||||||
|
{
|
||||||
|
int result = sqlite3_finalize(m_statement);
|
||||||
|
checkSQLiteError(m_instance.m_connection, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SQLiteStatement::execute()
|
||||||
|
{
|
||||||
|
int result = sqlite3_step(m_statement);
|
||||||
|
|
||||||
|
switch(result)
|
||||||
{
|
{
|
||||||
case SQLITE_DONE:
|
case SQLITE_DONE:
|
||||||
return false;
|
return false;
|
||||||
case SQLITE_ROW:
|
case SQLITE_ROW:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
on_sqlite_error( m_instance.m_connection, result );
|
checkSQLiteError(m_instance.m_connection, result);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::reset( )
|
void SQLiteStatement::reset()
|
||||||
{
|
{
|
||||||
int result = sqlite3_reset( m_statement );
|
int result = sqlite3_reset(m_statement);
|
||||||
on_sqlite_error( m_instance.m_connection, result );
|
checkSQLiteError(m_instance.m_connection, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::clear()
|
void SQLiteStatement::clear()
|
||||||
{
|
{
|
||||||
int result = sqlite3_clear_bindings(m_statement);
|
int result = sqlite3_clear_bindings(m_statement);
|
||||||
on_sqlite_error(m_instance.m_connection, result);
|
checkSQLiteError(m_instance.m_connection, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::setBindSingle( size_t index, double const & value )
|
void SQLiteStatement::setBindSingle(size_t index, const double & value)
|
||||||
{
|
{
|
||||||
int result = sqlite3_bind_double( m_statement, static_cast<int>(index), value );
|
int result = sqlite3_bind_double(m_statement, static_cast<int>(index), value);
|
||||||
on_sqlite_error( m_instance.m_connection, result );
|
checkSQLiteError(m_instance.m_connection, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::setBindSingle(size_t index, uint8_t const & value)
|
void SQLiteStatement::setBindSingle(size_t index, const uint8_t & value)
|
||||||
{
|
{
|
||||||
int result = sqlite3_bind_int(m_statement, static_cast<int>(index), value);
|
int result = sqlite3_bind_int(m_statement, static_cast<int>(index), value);
|
||||||
on_sqlite_error(m_instance.m_connection, result);
|
checkSQLiteError(m_instance.m_connection, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::setBindSingle(size_t index, uint16_t const & value)
|
void SQLiteStatement::setBindSingle(size_t index, const uint16_t & value)
|
||||||
{
|
{
|
||||||
int result = sqlite3_bind_int(m_statement, static_cast<int>(index), value);
|
int result = sqlite3_bind_int(m_statement, static_cast<int>(index), value);
|
||||||
on_sqlite_error(m_instance.m_connection, result);
|
checkSQLiteError(m_instance.m_connection, result);
|
||||||
}
|
}
|
||||||
void SQLiteStatement::setBindSingle(size_t index, uint32_t const & value)
|
void SQLiteStatement::setBindSingle(size_t index, const uint32_t & value)
|
||||||
{
|
{
|
||||||
int result = sqlite3_bind_int(m_statement, static_cast<int>(index), value);
|
int result = sqlite3_bind_int(m_statement, static_cast<int>(index), value);
|
||||||
on_sqlite_error(m_instance.m_connection, result);
|
checkSQLiteError(m_instance.m_connection, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::setBindSingle( size_t index, int32_t const & value )
|
void SQLiteStatement::setBindSingle(size_t index, const int32_t & value)
|
||||||
{
|
{
|
||||||
int result = sqlite3_bind_int( m_statement, static_cast<int>( index ), value );
|
int result = sqlite3_bind_int(m_statement, static_cast<int>(index), value);
|
||||||
on_sqlite_error( m_instance.m_connection, result );
|
checkSQLiteError(m_instance.m_connection, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::setBindSingle( size_t index, int64_t const & value )
|
void SQLiteStatement::setBindSingle(size_t index, const int64_t & value)
|
||||||
{
|
{
|
||||||
int result = sqlite3_bind_int64( m_statement, static_cast<int>( index ), value );
|
int result = sqlite3_bind_int64(m_statement, static_cast<int>(index), value);
|
||||||
on_sqlite_error( m_instance.m_connection, result );
|
checkSQLiteError(m_instance.m_connection, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::setBindSingle( size_t index, std::string const & value )
|
void SQLiteStatement::setBindSingle(size_t index, const std::string & value)
|
||||||
{
|
{
|
||||||
int result = sqlite3_bind_text( m_statement, static_cast<int>( index ), value.data(), static_cast<int>( value.size() ), SQLITE_STATIC );
|
int result = sqlite3_bind_text(m_statement, static_cast<int>(index), value.data(), static_cast<int>(value.size()), SQLITE_STATIC);
|
||||||
on_sqlite_error( m_instance.m_connection, result );
|
checkSQLiteError(m_instance.m_connection, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::setBindSingle( size_t index, char const * value )
|
void SQLiteStatement::setBindSingle(size_t index, const char * value)
|
||||||
{
|
{
|
||||||
int result = sqlite3_bind_text( m_statement, static_cast<int>( index ), value, -1, SQLITE_STATIC );
|
int result = sqlite3_bind_text(m_statement, static_cast<int>(index), value, -1, SQLITE_STATIC);
|
||||||
on_sqlite_error( m_instance.m_connection, result );
|
checkSQLiteError(m_instance.m_connection, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::getColumnSingle( size_t index, double & value )
|
void SQLiteStatement::getColumnSingle(size_t index, double & value)
|
||||||
{
|
{
|
||||||
value = sqlite3_column_double( m_statement, static_cast<int>( index ) );
|
value = sqlite3_column_double(m_statement, static_cast<int>(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::getColumnSingle( size_t index, uint8_t & value )
|
void SQLiteStatement::getColumnSingle(size_t index, uint8_t & value)
|
||||||
{
|
{
|
||||||
value = static_cast<uint8_t>(sqlite3_column_int( m_statement, static_cast<int>( index ) ));
|
value = static_cast<uint8_t>(sqlite3_column_int(m_statement, static_cast<int>(index)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::getColumnSingle(size_t index, uint16_t & value)
|
void SQLiteStatement::getColumnSingle(size_t index, uint16_t & value)
|
||||||
@ -124,9 +126,9 @@ void SQLiteStatement::getColumnSingle(size_t index, uint16_t & value)
|
|||||||
value = static_cast<uint16_t>(sqlite3_column_int(m_statement, static_cast<int>(index)));
|
value = static_cast<uint16_t>(sqlite3_column_int(m_statement, static_cast<int>(index)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::getColumnSingle( size_t index, int32_t & value )
|
void SQLiteStatement::getColumnSingle(size_t index, int32_t & value)
|
||||||
{
|
{
|
||||||
value = sqlite3_column_int( m_statement, static_cast<int>( index ) );
|
value = sqlite3_column_int(m_statement, static_cast<int>(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::getColumnSingle(size_t index, uint32_t & value)
|
void SQLiteStatement::getColumnSingle(size_t index, uint32_t & value)
|
||||||
@ -134,65 +136,50 @@ void SQLiteStatement::getColumnSingle(size_t index, uint32_t & value)
|
|||||||
value = sqlite3_column_int(m_statement, static_cast<int>(index));
|
value = sqlite3_column_int(m_statement, static_cast<int>(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::getColumnSingle( size_t index, int64_t & value )
|
void SQLiteStatement::getColumnSingle(size_t index, int64_t & value)
|
||||||
{
|
{
|
||||||
value = sqlite3_column_int64( m_statement, static_cast<int>( index ) );
|
value = sqlite3_column_int64(m_statement, static_cast<int>(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::getColumnSingle( size_t index, std::string & value )
|
void SQLiteStatement::getColumnSingle(size_t index, std::string & value)
|
||||||
{
|
{
|
||||||
auto value_raw = sqlite3_column_text(m_statement, static_cast<int>(index));
|
const auto * value_raw = sqlite3_column_text(m_statement, static_cast<int>(index));
|
||||||
value = reinterpret_cast<char const*>( value_raw );
|
value = reinterpret_cast<const char *>(value_raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLiteStatement::getColumnBlob(size_t index, std::byte * value, [[maybe_unused]] size_t capacity)
|
SQLiteInstancePtr SQLiteInstance::open(const std::string & db_path, bool allow_write)
|
||||||
{
|
|
||||||
auto * blob_data = sqlite3_column_blob(m_statement, static_cast<int>(index));
|
|
||||||
size_t blob_size = sqlite3_column_bytes(m_statement, static_cast<int>(index));
|
|
||||||
|
|
||||||
assert(blob_size < capacity);
|
|
||||||
|
|
||||||
std::copy_n(static_cast<std::byte const*>(blob_data), blob_size, value);
|
|
||||||
value[blob_size] = std::byte(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
SQLiteInstancePtr SQLiteInstance::open( std::string const & db_path, bool allow_write)
|
|
||||||
{
|
{
|
||||||
int flags = allow_write ? (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE) : SQLITE_OPEN_READONLY;
|
int flags = allow_write ? (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE) : SQLITE_OPEN_READONLY;
|
||||||
|
|
||||||
sqlite3 * connection;
|
sqlite3 * connection;
|
||||||
int result = sqlite3_open_v2( db_path.c_str( ), &connection, flags, nullptr );
|
int result = sqlite3_open_v2(db_path.c_str(), &connection, flags, nullptr);
|
||||||
|
|
||||||
on_sqlite_error( connection, result );
|
if(result == SQLITE_OK)
|
||||||
|
return SQLiteInstancePtr(new SQLiteInstance(connection));
|
||||||
|
|
||||||
assert(result == SQLITE_OK);
|
sqlite3_close(connection);
|
||||||
|
handleSQLiteError(connection);
|
||||||
if ( result == SQLITE_OK )
|
|
||||||
return SQLiteInstancePtr( new SQLiteInstance( connection ) );
|
|
||||||
|
|
||||||
sqlite3_close( connection );
|
|
||||||
return SQLiteInstancePtr( );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SQLiteInstance::SQLiteInstance( sqlite3 * connection ):
|
SQLiteInstance::SQLiteInstance(sqlite3 * connection)
|
||||||
m_connection( connection )
|
: m_connection(connection)
|
||||||
{ }
|
|
||||||
|
|
||||||
SQLiteInstance::~SQLiteInstance( )
|
|
||||||
{
|
{
|
||||||
int result = sqlite3_close( m_connection );
|
|
||||||
on_sqlite_error( m_connection, result );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SQLiteStatementPtr SQLiteInstance::prepare( std::string const & sql_text )
|
SQLiteInstance::~SQLiteInstance()
|
||||||
|
{
|
||||||
|
int result = sqlite3_close(m_connection);
|
||||||
|
checkSQLiteError(m_connection, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
SQLiteStatementPtr SQLiteInstance::prepare(const std::string & sql_text)
|
||||||
{
|
{
|
||||||
sqlite3_stmt * statement;
|
sqlite3_stmt * statement;
|
||||||
int result = sqlite3_prepare_v2( m_connection, sql_text.data(), static_cast<int>( sql_text.size()), &statement, nullptr );
|
int result = sqlite3_prepare_v2(m_connection, sql_text.data(), static_cast<int>(sql_text.size()), &statement, nullptr);
|
||||||
|
|
||||||
on_sqlite_error( m_connection, result );
|
|
||||||
|
|
||||||
if ( result == SQLITE_OK )
|
if(result == SQLITE_OK)
|
||||||
return SQLiteStatementPtr( new SQLiteStatement( *this, statement ) );
|
return SQLiteStatementPtr(new SQLiteStatement(*this, statement));
|
||||||
sqlite3_finalize( statement );
|
|
||||||
return SQLiteStatementPtr( );
|
sqlite3_finalize(statement);
|
||||||
|
handleSQLiteError(m_connection);
|
||||||
}
|
}
|
||||||
|
@ -15,76 +15,74 @@ typedef struct sqlite3_stmt sqlite3_stmt;
|
|||||||
class SQLiteInstance;
|
class SQLiteInstance;
|
||||||
class SQLiteStatement;
|
class SQLiteStatement;
|
||||||
|
|
||||||
using SQLiteInstancePtr = std::unique_ptr< SQLiteInstance >;
|
using SQLiteInstancePtr = std::unique_ptr<SQLiteInstance>;
|
||||||
using SQLiteStatementPtr = std::unique_ptr< SQLiteStatement >;
|
using SQLiteStatementPtr = std::unique_ptr<SQLiteStatement>;
|
||||||
|
|
||||||
class SQLiteStatement : boost::noncopyable
|
class SQLiteStatement : boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
friend class SQLiteInstance;
|
friend class SQLiteInstance;
|
||||||
|
|
||||||
bool execute( );
|
bool execute();
|
||||||
void reset( );
|
void reset();
|
||||||
void clear( );
|
void clear();
|
||||||
|
|
||||||
~SQLiteStatement();
|
~SQLiteStatement();
|
||||||
|
|
||||||
template<typename ... Args >
|
template<typename... Args>
|
||||||
void setBinds( Args const & ... args )
|
void setBinds(const Args &... args)
|
||||||
{
|
{
|
||||||
setBindSingle( 1, args... ); // The leftmost SQL parameter has an index of 1
|
setBindSingle(1, args...); // The leftmost SQL parameter has an index of 1
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ... Args >
|
template<typename... Args>
|
||||||
void getColumns( Args & ... args )
|
void getColumns(Args &... args)
|
||||||
{
|
{
|
||||||
getColumnSingle( 0, args... ); // The leftmost column of the result set has the index 0
|
getColumnSingle(0, args...); // The leftmost column of the result set has the index 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setBindSingle( size_t index, double const & value );
|
void setBindSingle(size_t index, const double & value);
|
||||||
void setBindSingle( size_t index, uint8_t const & value );
|
void setBindSingle(size_t index, const uint8_t & value);
|
||||||
void setBindSingle( size_t index, uint16_t const & value );
|
void setBindSingle(size_t index, const uint16_t & value);
|
||||||
void setBindSingle( size_t index, uint32_t const & value );
|
void setBindSingle(size_t index, const uint32_t & value);
|
||||||
void setBindSingle( size_t index, int32_t const & value );
|
void setBindSingle(size_t index, const int32_t & value);
|
||||||
void setBindSingle( size_t index, int64_t const & value );
|
void setBindSingle(size_t index, const int64_t & value);
|
||||||
void setBindSingle( size_t index, std::string const & value );
|
void setBindSingle(size_t index, const std::string & value);
|
||||||
void setBindSingle( size_t index, char const * value );
|
void setBindSingle(size_t index, const char * value);
|
||||||
|
|
||||||
void getColumnSingle( size_t index, double & value );
|
void getColumnSingle(size_t index, double & value);
|
||||||
void getColumnSingle( size_t index, uint8_t & value );
|
void getColumnSingle(size_t index, uint8_t & value);
|
||||||
void getColumnSingle( size_t index, uint16_t & value );
|
void getColumnSingle(size_t index, uint16_t & value);
|
||||||
void getColumnSingle( size_t index, uint32_t & value );
|
void getColumnSingle(size_t index, uint32_t & value);
|
||||||
void getColumnSingle( size_t index, int32_t & value );
|
void getColumnSingle(size_t index, int32_t & value);
|
||||||
void getColumnSingle( size_t index, int64_t & value );
|
void getColumnSingle(size_t index, int64_t & value);
|
||||||
void getColumnSingle( size_t index, std::string & value );
|
void getColumnSingle(size_t index, std::string & value);
|
||||||
|
|
||||||
template<typename Rep, typename Period>
|
template<typename Rep, typename Period>
|
||||||
void getColumnSingle( size_t index, std::chrono::duration<Rep, Period> & value )
|
void getColumnSingle(size_t index, std::chrono::duration<Rep, Period> & value)
|
||||||
{
|
{
|
||||||
int64_t durationValue = 0;
|
int64_t durationValue = 0;
|
||||||
getColumnSingle(index, durationValue);
|
getColumnSingle(index, durationValue);
|
||||||
value = std::chrono::duration<Rep, Period>(durationValue);
|
value = std::chrono::duration<Rep, Period>(durationValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
SQLiteStatement( SQLiteInstance & instance, sqlite3_stmt * statement );
|
SQLiteStatement(SQLiteInstance & instance, sqlite3_stmt * statement);
|
||||||
|
|
||||||
template<typename T, typename ... Args >
|
template<typename T, typename... Args>
|
||||||
void setBindSingle( size_t index, T const & arg, Args const & ... args )
|
void setBindSingle(size_t index, T const & arg, const Args &... args)
|
||||||
{
|
{
|
||||||
setBindSingle( index, arg );
|
setBindSingle(index, arg);
|
||||||
setBindSingle( index + 1, args... );
|
setBindSingle(index + 1, args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename ... Args >
|
template<typename T, typename... Args>
|
||||||
void getColumnSingle( size_t index, T & arg, Args & ... args )
|
void getColumnSingle(size_t index, T & arg, Args &... args)
|
||||||
{
|
{
|
||||||
getColumnSingle( index, arg );
|
getColumnSingle(index, arg);
|
||||||
getColumnSingle( index + 1, args... );
|
getColumnSingle(index + 1, args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
void getColumnBlob(size_t index, std::byte * value, size_t capacity);
|
|
||||||
|
|
||||||
SQLiteInstance & m_instance;
|
SQLiteInstance & m_instance;
|
||||||
sqlite3_stmt * m_statement;
|
sqlite3_stmt * m_statement;
|
||||||
};
|
};
|
||||||
@ -94,14 +92,14 @@ class SQLiteInstance : boost::noncopyable
|
|||||||
public:
|
public:
|
||||||
friend class SQLiteStatement;
|
friend class SQLiteStatement;
|
||||||
|
|
||||||
static SQLiteInstancePtr open(std::string const & db_path, bool allow_write );
|
static SQLiteInstancePtr open(const std::string & db_path, bool allow_write);
|
||||||
|
|
||||||
~SQLiteInstance( );
|
~SQLiteInstance();
|
||||||
|
|
||||||
SQLiteStatementPtr prepare( std::string const & statement );
|
SQLiteStatementPtr prepare(const std::string & statement);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SQLiteInstance( sqlite3 * connection );
|
SQLiteInstance(sqlite3 * connection);
|
||||||
|
|
||||||
sqlite3 * m_connection;
|
sqlite3 * m_connection;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user