From c9ca35accdf20d1436949d880b6893021a86335b Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 11 Dec 2024 13:27:57 +0100 Subject: [PATCH] Added get_last_insert_rowid() method to PreparedStatement. --- modules/database/prepared_statement.cpp | 2 ++ modules/database/prepared_statement.h | 2 ++ modules/database/query_result.h | 1 + modules/database_sqlite/sqlite3_prepared_statement.cpp | 6 ++++++ modules/database_sqlite/sqlite3_prepared_statement.h | 2 ++ 5 files changed, 13 insertions(+) diff --git a/modules/database/prepared_statement.cpp b/modules/database/prepared_statement.cpp index bf5033481..98318d6c4 100644 --- a/modules/database/prepared_statement.cpp +++ b/modules/database/prepared_statement.cpp @@ -93,6 +93,8 @@ void PreparedStatement::_bind_methods() { ClassDB::bind_method(D_METHOD("column_count"), &PreparedStatement::column_count); + ClassDB::bind_method(D_METHOD("get_last_insert_rowid"), &PreparedStatement::get_last_insert_rowid); + // Control ClassDB::bind_method(D_METHOD("prepare"), &PreparedStatement::prepare); diff --git a/modules/database/prepared_statement.h b/modules/database/prepared_statement.h index 2b324494b..d7b1ec81d 100644 --- a/modules/database/prepared_statement.h +++ b/modules/database/prepared_statement.h @@ -100,6 +100,8 @@ public: virtual int column_count() = 0; + virtual int get_last_insert_rowid() = 0; + // Control virtual Error prepare() = 0; virtual Error step() = 0; diff --git a/modules/database/query_result.h b/modules/database/query_result.h index 3e77952e1..53abb2837 100644 --- a/modules/database/query_result.h +++ b/modules/database/query_result.h @@ -41,6 +41,7 @@ class QueryResult : public Reference { public: virtual bool next_row(); + virtual String get_cell(const int index); virtual bool get_cell_bool(const int index); virtual int get_cell_int(const int index); diff --git a/modules/database_sqlite/sqlite3_prepared_statement.cpp b/modules/database_sqlite/sqlite3_prepared_statement.cpp index d90e7ecb4..85b499993 100644 --- a/modules/database_sqlite/sqlite3_prepared_statement.cpp +++ b/modules/database_sqlite/sqlite3_prepared_statement.cpp @@ -438,6 +438,12 @@ int SQLite3PreparedStatement::column_count() { return sqlite3_column_count(_prepared_statement); } +int SQLite3PreparedStatement::get_last_insert_rowid() { + ERR_FAIL_COND_V(!_connection.is_valid(), 0); + + return sqlite3_last_insert_rowid(_connection->conn); +} + // Control Error SQLite3PreparedStatement::prepare() { ERR_FAIL_COND_V(!_connection.is_valid(), FAILED); diff --git a/modules/database_sqlite/sqlite3_prepared_statement.h b/modules/database_sqlite/sqlite3_prepared_statement.h index 7fc179e29..be7e89734 100644 --- a/modules/database_sqlite/sqlite3_prepared_statement.h +++ b/modules/database_sqlite/sqlite3_prepared_statement.h @@ -84,6 +84,8 @@ public: virtual int column_count(); + virtual int get_last_insert_rowid(); + // Control virtual Error prepare(); virtual Error step();