Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
8ba6d9f2
Commit
8ba6d9f2
authored
8 years ago
by
Loïc Blot
Browse files
Options
Downloads
Patches
Plain Diff
Implement DatabaseException for databases
parent
8b940c00
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/database-leveldb.cpp
+1
-1
1 addition, 1 deletion
src/database-leveldb.cpp
src/database-redis.cpp
+10
-10
10 additions, 10 deletions
src/database-redis.cpp
src/database-sqlite3.cpp
+1
-1
1 addition, 1 deletion
src/database-sqlite3.cpp
src/exceptions.h
+5
-0
5 additions, 0 deletions
src/exceptions.h
with
17 additions
and
12 deletions
src/database-leveldb.cpp
+
1
−
1
View file @
8ba6d9f2
...
...
@@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define ENSURE_STATUS_OK(s) \
if (!(s).ok()) { \
throw
FileNotGood
Exception(std::string("LevelDB error: ") + \
throw
Database
Exception(std::string("LevelDB error: ") + \
(s).ToString()); \
}
...
...
This diff is collapsed.
Click to expand it.
src/database-redis.cpp
+
10
−
10
View file @
8ba6d9f2
...
...
@@ -46,11 +46,11 @@ Database_Redis::Database_Redis(Settings &conf)
int
port
=
conf
.
exists
(
"redis_port"
)
?
conf
.
getU16
(
"redis_port"
)
:
6379
;
ctx
=
redisConnect
(
addr
,
port
);
if
(
!
ctx
)
{
throw
FileNotGood
Exception
(
"Cannot allocate redis context"
);
throw
Database
Exception
(
"Cannot allocate redis context"
);
}
else
if
(
ctx
->
err
)
{
std
::
string
err
=
std
::
string
(
"Connection error: "
)
+
ctx
->
errstr
;
redisFree
(
ctx
);
throw
FileNotGood
Exception
(
err
);
throw
Database
Exception
(
err
);
}
}
...
...
@@ -62,7 +62,7 @@ Database_Redis::~Database_Redis()
void
Database_Redis
::
beginSave
()
{
redisReply
*
reply
=
static_cast
<
redisReply
*>
(
redisCommand
(
ctx
,
"MULTI"
));
if
(
!
reply
)
{
throw
FileNotGood
Exception
(
std
::
string
(
throw
Database
Exception
(
std
::
string
(
"Redis command 'MULTI' failed: "
)
+
ctx
->
errstr
);
}
freeReplyObject
(
reply
);
...
...
@@ -71,7 +71,7 @@ void Database_Redis::beginSave() {
void
Database_Redis
::
endSave
()
{
redisReply
*
reply
=
static_cast
<
redisReply
*>
(
redisCommand
(
ctx
,
"EXEC"
));
if
(
!
reply
)
{
throw
FileNotGood
Exception
(
std
::
string
(
throw
Database
Exception
(
std
::
string
(
"Redis command 'EXEC' failed: "
)
+
ctx
->
errstr
);
}
freeReplyObject
(
reply
);
...
...
@@ -108,7 +108,7 @@ void Database_Redis::loadBlock(const v3s16 &pos, std::string *block)
"HGET %s %s"
,
hash
.
c_str
(),
tmp
.
c_str
()));
if
(
!
reply
)
{
throw
FileNotGood
Exception
(
std
::
string
(
throw
Database
Exception
(
std
::
string
(
"Redis command 'HGET %s %s' failed: "
)
+
ctx
->
errstr
);
}
...
...
@@ -124,7 +124,7 @@ void Database_Redis::loadBlock(const v3s16 &pos, std::string *block)
freeReplyObject
(
reply
);
errorstream
<<
"loadBlock: loading block "
<<
PP
(
pos
)
<<
" failed: "
<<
errstr
<<
std
::
endl
;
throw
FileNotGood
Exception
(
std
::
string
(
throw
Database
Exception
(
std
::
string
(
"Redis command 'HGET %s %s' errored: "
)
+
errstr
);
}
case
REDIS_REPLY_NIL
:
{
...
...
@@ -139,7 +139,7 @@ void Database_Redis::loadBlock(const v3s16 &pos, std::string *block)
<<
" returned invalid reply type "
<<
reply
->
type
<<
": "
<<
std
::
string
(
reply
->
str
,
reply
->
len
)
<<
std
::
endl
;
freeReplyObject
(
reply
);
throw
FileNotGood
Exception
(
std
::
string
(
throw
Database
Exception
(
std
::
string
(
"Redis command 'HGET %s %s' gave invalid reply."
));
}
...
...
@@ -150,7 +150,7 @@ bool Database_Redis::deleteBlock(const v3s16 &pos)
redisReply
*
reply
=
static_cast
<
redisReply
*>
(
redisCommand
(
ctx
,
"HDEL %s %s"
,
hash
.
c_str
(),
tmp
.
c_str
()));
if
(
!
reply
)
{
throw
FileNotGood
Exception
(
std
::
string
(
throw
Database
Exception
(
std
::
string
(
"Redis command 'HDEL %s %s' failed: "
)
+
ctx
->
errstr
);
}
else
if
(
reply
->
type
==
REDIS_REPLY_ERROR
)
{
warningstream
<<
"deleteBlock: deleting block "
<<
PP
(
pos
)
...
...
@@ -167,7 +167,7 @@ void Database_Redis::listAllLoadableBlocks(std::vector<v3s16> &dst)
{
redisReply
*
reply
=
static_cast
<
redisReply
*>
(
redisCommand
(
ctx
,
"HKEYS %s"
,
hash
.
c_str
()));
if
(
!
reply
)
{
throw
FileNotGood
Exception
(
std
::
string
(
throw
Database
Exception
(
std
::
string
(
"Redis command 'HKEYS %s' failed: "
)
+
ctx
->
errstr
);
}
switch
(
reply
->
type
)
{
...
...
@@ -179,7 +179,7 @@ void Database_Redis::listAllLoadableBlocks(std::vector<v3s16> &dst)
}
break
;
case
REDIS_REPLY_ERROR
:
throw
FileNotGood
Exception
(
std
::
string
(
throw
Database
Exception
(
std
::
string
(
"Failed to get keys from database: "
)
+
std
::
string
(
reply
->
str
,
reply
->
len
));
}
...
...
This diff is collapsed.
Click to expand it.
src/database-sqlite3.cpp
+
1
−
1
View file @
8ba6d9f2
...
...
@@ -47,7 +47,7 @@ SQLite format specification:
#define SQLRES(s, r, m) \
if ((s) != (r)) { \
throw
FileNotGood
Exception(std::string(m) + ": " +\
throw
Database
Exception(std::string(m) + ": " +\
sqlite3_errmsg(m_database)); \
}
#define SQLOK(s, m) SQLRES(s, SQLITE_OK, m)
...
...
This diff is collapsed.
Click to expand it.
src/exceptions.h
+
5
−
0
View file @
8ba6d9f2
...
...
@@ -65,6 +65,11 @@ class FileNotGoodException : public BaseException {
FileNotGoodException
(
const
std
::
string
&
s
)
:
BaseException
(
s
)
{}
};
class
DatabaseException
:
public
BaseException
{
public:
DatabaseException
(
const
std
::
string
&
s
)
:
BaseException
(
s
)
{}
};
class
SerializationError
:
public
BaseException
{
public:
SerializationError
(
const
std
::
string
&
s
)
:
BaseException
(
s
)
{}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment