mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 22:45:52 +00:00
Add ripple_db module
This commit is contained in:
41
modules/ripple_db/ripple_db.cpp
Normal file
41
modules/ripple_db/ripple_db.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
/** Add this to get the @ref ripple_db module.
|
||||
|
||||
@file ripple_db.cpp
|
||||
@ingroup ripple_db
|
||||
*/
|
||||
|
||||
#include "ripple_db.h"
|
||||
|
||||
// VFALCO: TODO, fix these warnings!
|
||||
#ifdef _MSC_VER
|
||||
//#pragma warning (push) // Causes spurious C4503 "decorated name exceeds maximum length"
|
||||
//#pragma warning (disable: 4018) // signed/unsigned mismatch
|
||||
//#pragma warning (disable: 4244) // conversion, possible loss of data
|
||||
#endif
|
||||
|
||||
#include "src/cpp/database/database.cpp"
|
||||
#include "src/cpp/database/SqliteDatabase.cpp"
|
||||
#include "src/cpp/ripple/DBInit.cpp"
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
//#pragma warning (pop)
|
||||
#endif
|
||||
37
modules/ripple_db/ripple_db.h
Normal file
37
modules/ripple_db/ripple_db.h
Normal file
@@ -0,0 +1,37 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
/** Include this to get the @ref ripple_db module.
|
||||
|
||||
@file ripple_db.h
|
||||
@ingroup ripple_db
|
||||
*/
|
||||
|
||||
/** Basic classes.
|
||||
|
||||
This module provides persistent storage facilities.
|
||||
|
||||
@defgroup ripple_db
|
||||
*/
|
||||
|
||||
#ifndef RIPPLE_DB_H
|
||||
#define RIPPLE_DB_H
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -169,10 +169,21 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="modules\ripple_basics\ripple_basics.cpp" />
|
||||
<ClCompile Include="modules\ripple_client\ripple_client.cpp" />
|
||||
<ClCompile Include="modules\ripple_db\ripple_db.cpp" />
|
||||
<ClCompile Include="modules\ripple_ledger\ripple_ledger.cpp" />
|
||||
<ClCompile Include="src\cpp\database\database.cpp" />
|
||||
<ClCompile Include="src\cpp\database\database.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\database\sqlite3.c" />
|
||||
<ClCompile Include="src\cpp\database\SqliteDatabase.cpp" />
|
||||
<ClCompile Include="src\cpp\database\SqliteDatabase.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\json\json_reader.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -580,7 +591,12 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\ripple\DBInit.cpp" />
|
||||
<ClCompile Include="src\cpp\ripple\DBInit.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\ripple\DeterministicKeys.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -1015,6 +1031,7 @@
|
||||
<ClInclude Include="database\sqlite3ext.h" />
|
||||
<ClInclude Include="modules\ripple_basics\ripple_basics.h" />
|
||||
<ClInclude Include="modules\ripple_client\ripple_client.h" />
|
||||
<ClInclude Include="modules\ripple_db\ripple_db.h" />
|
||||
<ClInclude Include="modules\ripple_ledger\ripple_ledger.h" />
|
||||
<ClInclude Include="src\cpp\database\database.h" />
|
||||
<ClInclude Include="src\cpp\database\SqliteDatabase.h" />
|
||||
|
||||
@@ -98,6 +98,9 @@
|
||||
<Filter Include="1. Modules\ripple_client\rpc">
|
||||
<UniqueIdentifier>{3f351c55-360d-40bc-a136-4944ce572efd}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="1. Modules\ripple_db\storage">
|
||||
<UniqueIdentifier>{6097a179-ddad-4c69-9a34-2e3fc2c9fa1d}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\cpp\database\sqlite3.c">
|
||||
@@ -421,12 +424,6 @@
|
||||
<ClCompile Include="src\cpp\ripple\ScriptData.cpp">
|
||||
<Filter>Unsorted Sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\database\database.cpp">
|
||||
<Filter>1. Modules\ripple_db</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\database\SqliteDatabase.cpp">
|
||||
<Filter>1. Modules\ripple_db</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\websocket_core.cpp">
|
||||
<Filter>0. Third Party Code\websocket</Filter>
|
||||
</ClCompile>
|
||||
@@ -520,9 +517,6 @@
|
||||
<ClCompile Include="src\cpp\ripple\Contract.cpp">
|
||||
<Filter>1. Modules\ripple_ledger\contracts</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\ripple\DBInit.cpp">
|
||||
<Filter>1. Modules\ripple_db</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\ripple\NetworkOPs.cpp">
|
||||
<Filter>1. Modules\ripple_net</Filter>
|
||||
</ClCompile>
|
||||
@@ -703,6 +697,18 @@
|
||||
<ClCompile Include="src\cpp\ripple\ValidationCollection.cpp">
|
||||
<Filter>1. Modules\ripple_main</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="modules\ripple_db\ripple_db.cpp">
|
||||
<Filter>1. Modules\ripple_db</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\database\database.cpp">
|
||||
<Filter>1. Modules\ripple_db\storage</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\ripple\DBInit.cpp">
|
||||
<Filter>1. Modules\ripple_db\storage</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\database\SqliteDatabase.cpp">
|
||||
<Filter>1. Modules\ripple_db\storage</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="database\sqlite3ext.h">
|
||||
@@ -1056,12 +1062,6 @@
|
||||
<ClInclude Include="src\cpp\ripple\SecureAllocator.h">
|
||||
<Filter>Unsorted Sources</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\cpp\database\SqliteDatabase.h">
|
||||
<Filter>1. Modules\ripple_db</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\cpp\database\database.h">
|
||||
<Filter>1. Modules\ripple_db</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\cpp\ripple\ripple.pb.h">
|
||||
<Filter>protoc_generated</Filter>
|
||||
</ClInclude>
|
||||
@@ -1335,6 +1335,15 @@
|
||||
<ClInclude Include="src\cpp\ripple\ValidationCollection.h">
|
||||
<Filter>1. Modules\ripple_main</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="modules\ripple_db\ripple_db.h">
|
||||
<Filter>1. Modules\ripple_db</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\cpp\database\database.h">
|
||||
<Filter>1. Modules\ripple_db\storage</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\cpp\database\SqliteDatabase.h">
|
||||
<Filter>1. Modules\ripple_db\storage</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="wallet.xml" />
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
#include "../ripple/JobQueue.h"
|
||||
#include "../ripple/Log.h"
|
||||
|
||||
SETUP_NLOG("DataBase");
|
||||
|
||||
using namespace std;
|
||||
|
||||
SqliteDatabase::SqliteDatabase(const char* host) : Database(host,"",""), mWalQ(NULL), walRunning(false)
|
||||
@@ -28,7 +26,7 @@ void SqliteDatabase::connect()
|
||||
int rc = sqlite3_open(mHost.c_str(), &mConnection);
|
||||
if (rc)
|
||||
{
|
||||
cLog(lsFATAL) << "Can't open " << mHost << " " << rc;
|
||||
WriteLog (lsFATAL, SqliteDatabase) << "Can't open " << mHost << " " << rc;
|
||||
sqlite3_close(mConnection);
|
||||
assert((rc != SQLITE_BUSY) && (rc != SQLITE_LOCKED));
|
||||
}
|
||||
@@ -42,7 +40,7 @@ sqlite3* SqliteDatabase::getAuxConnection()
|
||||
int rc = sqlite3_open(mHost.c_str(), &mAuxConnection);
|
||||
if (rc)
|
||||
{
|
||||
cLog(lsFATAL) << "Can't aux open " << mHost << " " << rc;
|
||||
WriteLog (lsFATAL, SqliteDatabase) << "Can't aux open " << mHost << " " << rc;
|
||||
assert((rc != SQLITE_BUSY) && (rc != SQLITE_LOCKED));
|
||||
if (mAuxConnection != NULL)
|
||||
{
|
||||
@@ -78,9 +76,9 @@ bool SqliteDatabase::executeSQL(const char* sql, bool fail_ok)
|
||||
if (!fail_ok)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
cLog(lsWARNING) << "Perror:" << mHost << ": " << rc;
|
||||
cLog(lsWARNING) << "Statement: " << sql;
|
||||
cLog(lsWARNING) << "Error: " << sqlite3_errmsg(mConnection);
|
||||
WriteLog (lsWARNING, SqliteDatabase) << "Perror:" << mHost << ": " << rc;
|
||||
WriteLog (lsWARNING, SqliteDatabase) << "Statement: " << sql;
|
||||
WriteLog (lsWARNING, SqliteDatabase) << "Error: " << sqlite3_errmsg(mConnection);
|
||||
#endif
|
||||
}
|
||||
endIterRows();
|
||||
@@ -100,7 +98,7 @@ bool SqliteDatabase::executeSQL(const char* sql, bool fail_ok)
|
||||
{
|
||||
if ((rc != SQLITE_BUSY) && (rc != SQLITE_LOCKED))
|
||||
{
|
||||
cLog(lsFATAL) << mHost << " returns error " << rc << ": " << sqlite3_errmsg(mConnection);
|
||||
WriteLog (lsFATAL, SqliteDatabase) << mHost << " returns error " << rc << ": " << sqlite3_errmsg(mConnection);
|
||||
assert(false);
|
||||
}
|
||||
mMoreRows = false;
|
||||
@@ -108,9 +106,9 @@ bool SqliteDatabase::executeSQL(const char* sql, bool fail_ok)
|
||||
if (!fail_ok)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
cLog(lsWARNING) << "SQL Serror:" << mHost << ": " << rc;
|
||||
cLog(lsWARNING) << "Statement: " << sql;
|
||||
cLog(lsWARNING) << "Error: " << sqlite3_errmsg(mConnection);
|
||||
WriteLog (lsWARNING, SqliteDatabase) << "SQL Serror:" << mHost << ": " << rc;
|
||||
WriteLog (lsWARNING, SqliteDatabase) << "Statement: " << sql;
|
||||
WriteLog (lsWARNING, SqliteDatabase) << "Error: " << sqlite3_errmsg(mConnection);
|
||||
#endif
|
||||
}
|
||||
endIterRows();
|
||||
@@ -127,6 +125,7 @@ int SqliteDatabase::getNumRowsAffected()
|
||||
return(0);
|
||||
}
|
||||
|
||||
// VFALCO: TODO, This must be fixed!!! return value needs to be int64
|
||||
int SqliteDatabase::getLastInsertID()
|
||||
{
|
||||
return(sqlite3_last_insert_rowid(mConnection));
|
||||
@@ -164,7 +163,7 @@ bool SqliteDatabase::getNextRow(bool finalize)
|
||||
if (rc==SQLITE_ROW)
|
||||
return(true);
|
||||
assert((rc != SQLITE_BUSY) && (rc != SQLITE_LOCKED));
|
||||
tLog((rc != SQLITE_DONE), lsWARNING) << "Rerror: " << mHost << ": " << rc;
|
||||
CondLog ((rc != SQLITE_DONE), lsWARNING, SqliteDatabase) << "Rerror: " << mHost << ": " << rc;
|
||||
}
|
||||
|
||||
if (finalize)
|
||||
@@ -272,11 +271,11 @@ void SqliteDatabase::runWal()
|
||||
int ret = sqlite3_wal_checkpoint_v2(mConnection, NULL, SQLITE_CHECKPOINT_PASSIVE, &log, &ckpt);
|
||||
if (ret != SQLITE_OK)
|
||||
{
|
||||
cLog((ret == SQLITE_LOCKED) ? lsTRACE : lsWARNING) << "WAL("
|
||||
WriteLog ((ret == SQLITE_LOCKED) ? lsTRACE : lsWARNING, SqliteDatabase) << "WAL("
|
||||
<< sqlite3_db_filename(mConnection, "main") << "): error " << ret;
|
||||
}
|
||||
else
|
||||
cLog(lsTRACE) << "WAL(" << sqlite3_db_filename(mConnection, "main") <<
|
||||
WriteLog (lsTRACE, SqliteDatabase) << "WAL(" << sqlite3_db_filename(mConnection, "main") <<
|
||||
"): frames=" << log << ", written=" << ckpt;
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user