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
fa427d64
Commit
fa427d64
authored
10 years ago
by
sapier
Browse files
Options
Downloads
Patches
Plain Diff
Add sqlite3 backend hack for android
parent
6c5f79fe
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/database-sqlite3.cpp
+41
-3
41 additions, 3 deletions
src/database-sqlite3.cpp
src/database-sqlite3.h
+3
-0
3 additions, 0 deletions
src/database-sqlite3.h
src/subgame.cpp
+1
-6
1 addition, 6 deletions
src/subgame.cpp
with
45 additions
and
9 deletions
src/database-sqlite3.cpp
+
41
−
3
View file @
fa427d64
...
...
@@ -120,13 +120,24 @@ void Database_SQLite3::verifyDatabase() {
errorstream
<<
"SQLite3 read statment failed to prepare: "
<<
sqlite3_errmsg
(
m_database
)
<<
std
::
endl
;
throw
FileNotGoodException
(
"Cannot prepare read statement"
);
}
d
=
sqlite3_prepare
(
m_database
,
"REPLACE INTO `blocks` VALUES(?, ?)"
,
-
1
,
&
m_database_write
,
NULL
);
#ifdef __ANDROID__
d
=
sqlite3_prepare
(
m_database
,
"INSERT INTO `blocks` VALUES(?, ?);"
,
-
1
,
&
m_database_write
,
NULL
);
#else
d
=
sqlite3_prepare
(
m_database
,
"REPLACE INTO `blocks` VALUES(?, ?);"
,
-
1
,
&
m_database_write
,
NULL
);
#endif
if
(
d
!=
SQLITE_OK
)
{
errorstream
<<
"SQLite3 write statment failed to prepare: "
<<
sqlite3_errmsg
(
m_database
)
<<
std
::
endl
;
throw
FileNotGoodException
(
"Cannot prepare write statement"
);
}
#ifdef __ANDROID__
d
=
sqlite3_prepare
(
m_database
,
"DELETE FROM `blocks` WHERE `pos`=?;"
,
-
1
,
&
m_database_delete
,
NULL
);
if
(
d
!=
SQLITE_OK
)
{
infostream
<<
"WARNING: SQLite3 database delete statment failed to prepare: "
<<
sqlite3_errmsg
(
m_database
)
<<
std
::
endl
;
throw
FileNotGoodException
(
"Cannot prepare delete statement"
);
}
#endif
d
=
sqlite3_prepare
(
m_database
,
"SELECT `pos` FROM `blocks`"
,
-
1
,
&
m_database_list
,
NULL
);
if
(
d
!=
SQLITE_OK
)
{
infostream
<<
"SQLite3 list statment failed to prepare: "
<<
sqlite3_errmsg
(
m_database
)
<<
std
::
endl
;
...
...
@@ -140,6 +151,32 @@ bool Database_SQLite3::saveBlock(v3s16 blockpos, std::string &data)
{
verifyDatabase
();
#ifdef __ANDROID__
/**
* Note: For some unknown reason sqlite3 fails to REPLACE blocks on android,
* deleting them and inserting first works.
*/
if
(
sqlite3_bind_int64
(
m_database_read
,
1
,
getBlockAsInteger
(
blockpos
))
!=
SQLITE_OK
)
{
infostream
<<
"WARNING: Could not bind block position for load: "
<<
sqlite3_errmsg
(
m_database
)
<<
std
::
endl
;
}
if
(
sqlite3_step
(
m_database_read
)
==
SQLITE_ROW
)
{
if
(
sqlite3_bind_int64
(
m_database_delete
,
1
,
getBlockAsInteger
(
blockpos
))
!=
SQLITE_OK
)
{
infostream
<<
"WARNING: Could not bind block position for delete: "
<<
sqlite3_errmsg
(
m_database
)
<<
std
::
endl
;
}
if
(
sqlite3_step
(
m_database_delete
)
!=
SQLITE_DONE
)
{
errorstream
<<
"WARNING: saveBlock: Block failed to delete "
<<
PP
(
blockpos
)
<<
": "
<<
sqlite3_errmsg
(
m_database
)
<<
std
::
endl
;
return
false
;
}
sqlite3_reset
(
m_database_delete
);
}
sqlite3_reset
(
m_database_read
);
#endif
if
(
sqlite3_bind_int64
(
m_database_write
,
1
,
getBlockAsInteger
(
blockpos
))
!=
SQLITE_OK
)
{
errorstream
<<
"WARNING: saveBlock: Block position failed to bind: "
<<
PP
(
blockpos
)
<<
": "
<<
sqlite3_errmsg
(
m_database
)
<<
std
::
endl
;
...
...
@@ -162,6 +199,7 @@ bool Database_SQLite3::saveBlock(v3s16 blockpos, std::string &data)
}
sqlite3_reset
(
m_database_write
);
return
true
;
}
...
...
@@ -203,7 +241,7 @@ void Database_SQLite3::createDatabase()
"`data` BLOB"
");"
,
NULL
,
NULL
,
NULL
);
if
(
e
=
=
SQLITE_
ABORT
)
if
(
e
!
=
SQLITE_
OK
)
throw
FileNotGoodException
(
"Could not create sqlite3 database structure"
);
else
infostream
<<
"ServerMap: SQLite3 database structure was created"
;
...
...
This diff is collapsed.
Click to expand it.
src/database-sqlite3.h
+
3
−
0
View file @
fa427d64
...
...
@@ -47,6 +47,9 @@ class Database_SQLite3 : public Database
sqlite3
*
m_database
;
sqlite3_stmt
*
m_database_read
;
sqlite3_stmt
*
m_database_write
;
#ifdef __ANDROID__
sqlite3_stmt
*
m_database_delete
;
#endif
sqlite3_stmt
*
m_database_list
;
// Create the database structure
...
...
This diff is collapsed.
Click to expand it.
src/subgame.cpp
+
1
−
6
View file @
fa427d64
...
...
@@ -242,12 +242,7 @@ bool initializeWorld(const std::string &path, const std::string &gameid)
infostream
<<
"Creating world.mt ("
<<
worldmt_path
<<
")"
<<
std
::
endl
;
fs
::
CreateAllDirs
(
path
);
std
::
ostringstream
ss
(
std
::
ios_base
::
binary
);
ss
<<
"gameid = "
<<
gameid
<<
#ifdef __ANDROID__
"
\n
backend = leveldb
\n
"
;
#else
"
\n
backend = sqlite3
\n
"
;
#endif
ss
<<
"gameid = "
<<
gameid
<<
"
\n
backend = sqlite3
\n
"
;
fs
::
safeWriteToFile
(
worldmt_path
,
ss
.
str
());
}
return
true
;
...
...
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