diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | modules/extra/mysql.cpp | 2 | ||||
| -rw-r--r-- | modules/sqlite.cpp (renamed from modules/extra/sqlite.cpp) | 18 |
3 files changed, 19 insertions, 11 deletions
diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index bfd3b8e2e..4a2781caa 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -182,3 +182,13 @@ endmacro() build_modules(${CMAKE_CURRENT_SOURCE_DIR}) build_modules_dependencies(${CMAKE_CURRENT_SOURCE_DIR}) +# link sqlite to system or included libsqlite +if(TARGET anope_sqlite) + if(PREFER_EMBEDDED_SQLITE OR NOT SQLITE_FOUND) + include_directories(${Anope_SOURCE_DIR}/lib/sqlite) + target_link_libraries(anope_sqlite sqlite3) + set_target_properties(anope_sqlite PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}") + else() + target_link_libraries(anope_sqlite ${SQLITE_LIBRARIES}) + endif() +endif() diff --git a/modules/extra/mysql.cpp b/modules/extra/mysql.cpp index 389124073..a5d1ac163 100644 --- a/modules/extra/mysql.cpp +++ b/modules/extra/mysql.cpp @@ -509,7 +509,7 @@ Query MySQLService::Commit() Serialize::ID MySQLService::GetID(const Anope::string &prefix) { Query query = "SELECT `id` FROM `" + prefix + "objects` ORDER BY `id` DESC LIMIT 1"; - Serialize::ID id = 0; + Serialize::ID id = 1; Result res = RunQuery(query); if (res.Rows()) diff --git a/modules/extra/sqlite.cpp b/modules/sqlite.cpp index 881fe0b4a..b1b462357 100644 --- a/modules/extra/sqlite.cpp +++ b/modules/sqlite.cpp @@ -17,16 +17,13 @@ * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ -/* RequiredLibraries: sqlite3 */ -/* RequiredWindowsLibraries: sqlite3 */ - #include "module.h" #include "modules/sql.h" #include <sqlite3.h> using namespace SQL; -/* SQLite3 API, based from InspiRCd */ +/* SQLite3 API, based from InspIRCd */ /** A SQLite result */ @@ -243,7 +240,8 @@ std::vector<Query> SQLiteService::InitSchema(const Anope::string &prefix) queries.push_back(Query("PRAGMA foreign_keys = ON")); - Query t = "CREATE TABLE IF NOT EXISTS `" + prefix + "objects` (`id` PRIMARY KEY, `type`)"; + /* https://sqlite.org/lang_createtable.html#rowid, https://sqlite.org/autoinc.html */ + Query t = "CREATE TABLE IF NOT EXISTS `" + prefix + "objects` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `type`)"; queries.push_back(t); return queries; @@ -322,7 +320,7 @@ std::vector<Query> SQLiteService::CreateTable(const Anope::string &prefix, Seria query += ","; } - query += " `id` NOT NULL PRIMARY KEY, FOREIGN KEY (id) REFERENCES " + prefix + "objects(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED)"; + query += " `id` INTEGER PRIMARY KEY, FOREIGN KEY (id) REFERENCES " + prefix + "objects(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED)"; queries.push_back(query); active_schema[prefix + base->GetName()] = fields; @@ -397,11 +395,11 @@ Query SQLiteService::Commit() Serialize::ID SQLiteService::GetID(const Anope::string &prefix) { - Query query = "SELECT `id` FROM `" + prefix + "objects` ORDER BY `id` DESC LIMIT 1"; - Serialize::ID id = 0; + Query query = "SELECT MAX(id) AS id FROM `" + prefix + "objects`"; + Serialize::ID id = 1; Result res = RunQuery(query); - if (res.Rows()) + if (res.Rows() && !res.IsNull(0, "id")) { id = convertTo<Serialize::ID>(res.Get(0, "id")); @@ -409,7 +407,7 @@ Serialize::ID SQLiteService::GetID(const Anope::string &prefix) ++id; } - /* OnSerializableCreate is called immediately after this which does the insert */ + /* OnSerializableCreate is called immediately after this which does the insert, within the same transaction */ return id; } |
