mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-02-11 10:30:06 +01:00
Added next_column*() helper methods to PreparedStatement.
This commit is contained in:
parent
9da9dbc14c
commit
fe7f931dc8
@ -40,7 +40,57 @@ void PreparedStatement::set_sql(const String &p_sql) {
|
||||
_sql = p_sql;
|
||||
}
|
||||
|
||||
int PreparedStatement::get_current_column_index() const {
|
||||
return _current_column_index;
|
||||
}
|
||||
void PreparedStatement::set_current_column_index(const int p_index) {
|
||||
_current_column_index = p_index;
|
||||
}
|
||||
|
||||
String PreparedStatement::next_column_name() {
|
||||
return column_name(_current_column_index++);
|
||||
}
|
||||
String PreparedStatement::next_column_decltype() {
|
||||
return column_decltype(_current_column_index++);
|
||||
}
|
||||
PreparedStatement::Type PreparedStatement::next_column_type() {
|
||||
return column_type(_current_column_index++);
|
||||
}
|
||||
|
||||
String PreparedStatement::next_column_database_name() {
|
||||
return column_database_name(_current_column_index++);
|
||||
}
|
||||
String PreparedStatement::next_column_table_name() {
|
||||
return column_table_name(_current_column_index++);
|
||||
}
|
||||
String PreparedStatement::next_column_origin_name() {
|
||||
return column_origin_name(_current_column_index++);
|
||||
}
|
||||
|
||||
Vector<uint8_t> PreparedStatement::next_column_blob() {
|
||||
return column_blob(_current_column_index++);
|
||||
}
|
||||
float PreparedStatement::next_column_float() {
|
||||
return column_float(_current_column_index++);
|
||||
}
|
||||
double PreparedStatement::next_column_double() {
|
||||
return column_double(_current_column_index++);
|
||||
}
|
||||
int64_t PreparedStatement::next_column_int() {
|
||||
return column_int(_current_column_index++);
|
||||
}
|
||||
int PreparedStatement::next_column_int64() {
|
||||
return column_int64(_current_column_index++);
|
||||
}
|
||||
String PreparedStatement::next_column_text() {
|
||||
return column_text(_current_column_index++);
|
||||
}
|
||||
Variant PreparedStatement::next_column_value() {
|
||||
return column_value(_current_column_index++);
|
||||
}
|
||||
|
||||
PreparedStatement::PreparedStatement() {
|
||||
_current_column_index = 0;
|
||||
}
|
||||
|
||||
PreparedStatement::~PreparedStatement() {
|
||||
@ -95,6 +145,27 @@ void PreparedStatement::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_last_insert_rowid"), &PreparedStatement::get_last_insert_rowid);
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_current_column_index"), &PreparedStatement::get_current_column_index);
|
||||
ClassDB::bind_method(D_METHOD("set_current_column_index", "index"), &PreparedStatement::set_current_column_index);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_column_index"), "set_current_column_index", "get_current_column_index");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("next_column_name"), &PreparedStatement::next_column_name);
|
||||
ClassDB::bind_method(D_METHOD("next_column_decltype"), &PreparedStatement::next_column_decltype);
|
||||
ClassDB::bind_method(D_METHOD("next_column_type"), &PreparedStatement::next_column_type);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("next_column_database_name"), &PreparedStatement::next_column_database_name);
|
||||
ClassDB::bind_method(D_METHOD("next_column_table_name"), &PreparedStatement::next_column_table_name);
|
||||
ClassDB::bind_method(D_METHOD("next_column_origin_name"), &PreparedStatement::next_column_origin_name);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("next_column_blob"), &PreparedStatement::next_column_blob);
|
||||
ClassDB::bind_method(D_METHOD("next_column_float"), &PreparedStatement::next_column_float);
|
||||
ClassDB::bind_method(D_METHOD("next_column_double"), &PreparedStatement::next_column_double);
|
||||
ClassDB::bind_method(D_METHOD("next_column_int"), &PreparedStatement::next_column_int);
|
||||
ClassDB::bind_method(D_METHOD("next_column_int64"), &PreparedStatement::next_column_int64);
|
||||
ClassDB::bind_method(D_METHOD("next_column_text"), &PreparedStatement::next_column_text);
|
||||
ClassDB::bind_method(D_METHOD("next_column_value"), &PreparedStatement::next_column_value);
|
||||
|
||||
// Control
|
||||
|
||||
ClassDB::bind_method(D_METHOD("prepare"), &PreparedStatement::prepare);
|
||||
|
@ -102,6 +102,25 @@ public:
|
||||
|
||||
virtual int get_last_insert_rowid() = 0;
|
||||
|
||||
int get_current_column_index() const;
|
||||
void set_current_column_index(const int p_index);
|
||||
|
||||
String next_column_name();
|
||||
String next_column_decltype();
|
||||
Type next_column_type();
|
||||
|
||||
String next_column_database_name();
|
||||
String next_column_table_name();
|
||||
String next_column_origin_name();
|
||||
|
||||
Vector<uint8_t> next_column_blob();
|
||||
float next_column_float();
|
||||
double next_column_double();
|
||||
int64_t next_column_int();
|
||||
int next_column_int64();
|
||||
String next_column_text();
|
||||
Variant next_column_value();
|
||||
|
||||
// Control
|
||||
virtual Error prepare() = 0;
|
||||
virtual Error step() = 0;
|
||||
@ -118,6 +137,7 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
String _sql;
|
||||
int _current_column_index;
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(PreparedStatement::Type);
|
||||
|
@ -448,6 +448,8 @@ int SQLite3PreparedStatement::get_last_insert_rowid() {
|
||||
Error SQLite3PreparedStatement::prepare() {
|
||||
ERR_FAIL_COND_V(!_connection.is_valid(), FAILED);
|
||||
|
||||
_current_column_index = 0;
|
||||
|
||||
CharString cs = _sql.utf8();
|
||||
|
||||
int res = sqlite3_prepare_v2(_connection->conn, cs.get_data(), cs.size(), &_prepared_statement, NULL);
|
||||
@ -463,6 +465,8 @@ Error SQLite3PreparedStatement::step() {
|
||||
return ERR_UNCONFIGURED;
|
||||
}
|
||||
|
||||
_current_column_index = 0;
|
||||
|
||||
int res = sqlite3_step(_prepared_statement);
|
||||
|
||||
if (res == SQLITE_ROW) {
|
||||
@ -487,6 +491,8 @@ Error SQLite3PreparedStatement::reset() {
|
||||
return ERR_UNCONFIGURED;
|
||||
}
|
||||
|
||||
_current_column_index = 0;
|
||||
|
||||
int res = sqlite3_reset(_prepared_statement);
|
||||
|
||||
if (res != SQLITE_OK) {
|
||||
@ -500,6 +506,8 @@ Error SQLite3PreparedStatement::finalize() {
|
||||
return OK;
|
||||
}
|
||||
|
||||
_current_column_index = 0;
|
||||
|
||||
sqlite3_finalize(_prepared_statement);
|
||||
|
||||
_prepared_statement = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user