diff --git a/modules/database/table_builder.cpp b/modules/database/table_builder.cpp index e0dd2b3e1..7f83c34d4 100644 --- a/modules/database/table_builder.cpp +++ b/modules/database/table_builder.cpp @@ -1,12 +1,16 @@ #include "table_builder.h" +#include "core/print_string.h" #include "query_result.h" -TableBuilder *TableBuilder::create_table(const String &name) { - return this; +String TableBuilder::get_result() { + return result; +} +void TableBuilder::set_result(const String &val) { + result = val; } -TableBuilder *TableBuilder::integer(const String &name) { +TableBuilder *TableBuilder::create_table(const String &name) { return this; } @@ -14,38 +18,22 @@ TableBuilder *TableBuilder::integer(const String &name, const int length) { return this; } -TableBuilder *TableBuilder::tiny_integer(const String &name) { - return this; -} TableBuilder *TableBuilder::tiny_integer(const String &name, const int length) { return this; } -TableBuilder *TableBuilder::small_integer(const String &name) { - return this; -} TableBuilder *TableBuilder::small_integer(const String &name, const int length) { return this; } -TableBuilder *TableBuilder::real_float(const String &name) { - return this; -} TableBuilder *TableBuilder::real_float(const String &name, const int size, const int d) { return this; } -TableBuilder *TableBuilder::real_double(const String &name) { - return this; -} TableBuilder *TableBuilder::real_double(const String &name, const int size, const int d) { return this; } -TableBuilder *TableBuilder::date(const String &name) { - return this; -} - TableBuilder *TableBuilder::varchar(const String &name, const int length) { return this; } @@ -74,10 +62,6 @@ TableBuilder *TableBuilder::primary_key(const String &name) { return this; } -TableBuilder *TableBuilder::primary_key() { - return this; -} - TableBuilder *TableBuilder::next_row() { return this; } @@ -86,9 +70,6 @@ TableBuilder *TableBuilder::ccreate_table() { return this; } -TableBuilder *TableBuilder::drop_table() { - return this; -} TableBuilder *TableBuilder::drop_table_if_exists() { return this; } @@ -117,11 +98,115 @@ void TableBuilder::run_query() { } void TableBuilder::print() { - printf("%s\n", result.c_str()); + //printf("%s\n", result.c_str()); + print_error(result); } TableBuilder::TableBuilder() { } TableBuilder::~TableBuilder() { -} \ No newline at end of file +} + +void TableBuilder::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_result"), &TableBuilder::get_result); + ClassDB::bind_method(D_METHOD("set_result", "value"), &TableBuilder::set_result); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "result"), "set_result", "get_result"); + + ClassDB::bind_method(D_METHOD("create_table", "value"), &TableBuilder::_create_table_bind); + + ClassDB::bind_method(D_METHOD("integer", "name", "length"), &TableBuilder::_integer_bind); + ClassDB::bind_method(D_METHOD("tiny_integer", "name", "length"), &TableBuilder::_tiny_integer_bind, -1); + ClassDB::bind_method(D_METHOD("small_integer", "name", "length"), &TableBuilder::_small_integer_bind, -1); + ClassDB::bind_method(D_METHOD("real_float", "name", "size", "d"), &TableBuilder::_real_float_bind, -1, -1); + ClassDB::bind_method(D_METHOD("real_double", "name", "size", "d"), &TableBuilder::_real_double_bind, -1, -1); + + ClassDB::bind_method(D_METHOD("date", "name"), &TableBuilder::_date_bind); + ClassDB::bind_method(D_METHOD("varchar", "name", "length"), &TableBuilder::_varchar_bind, -1); + ClassDB::bind_method(D_METHOD("text", "name"), &TableBuilder::_text_bind); + + ClassDB::bind_method(D_METHOD("not_null"), &TableBuilder::_not_null_bind); + ClassDB::bind_method(D_METHOD("null"), &TableBuilder::_null_bind); + ClassDB::bind_method(D_METHOD("defval", "val"), &TableBuilder::_defval_bind); + ClassDB::bind_method(D_METHOD("auto_increment"), &TableBuilder::_auto_increment_bind); + ClassDB::bind_method(D_METHOD("primary_key", "name"), &TableBuilder::_primary_key_bind, ""); + ClassDB::bind_method(D_METHOD("next_row"), &TableBuilder::_next_row_bind); + ClassDB::bind_method(D_METHOD("ccreate_table"), &TableBuilder::_ccreate_table_bind); + + ClassDB::bind_method(D_METHOD("drop_table", "name"), &TableBuilder::_drop_table_bind, ""); + ClassDB::bind_method(D_METHOD("drop_table_if_exists", "name"), &TableBuilder::_drop_table_if_exists_bind, ""); + ClassDB::bind_method(D_METHOD("cdrop_table"), &TableBuilder::_cdrop_table_bind); + + ClassDB::bind_method(D_METHOD("foreign_key", "name"), &TableBuilder::_foreign_key_bind); + ClassDB::bind_method(D_METHOD("references", "table", "name"), &TableBuilder::_references_bind); +} + +Ref TableBuilder::_create_table_bind(const String &name) { + return Ref(create_table(name)); +} + +Ref TableBuilder::_integer_bind(const String &name, const int length) { + return Ref(integer(name, length)); +} +Ref TableBuilder::_tiny_integer_bind(const String &name, const int length) { + return Ref(tiny_integer(name, length)); +} +Ref TableBuilder::_small_integer_bind(const String &name, const int length) { + return Ref(small_integer(name, length)); +} +Ref TableBuilder::_real_float_bind(const String &name, const int size, const int d) { + return Ref(real_float(name, size, d)); +} +Ref TableBuilder::_real_double_bind(const String &name, const int size, const int d) { + return Ref(real_double(name, size, d)); +} + +Ref TableBuilder::_date_bind(const String &name) { + return Ref(date(name)); +} + +Ref TableBuilder::_varchar_bind(const String &name, const int length) { + return Ref(varchar(name)); +} +Ref TableBuilder::_text_bind(const String &name) { + return Ref(text(name)); +} + +Ref TableBuilder::_not_null_bind() { + return Ref(not_null()); +} +Ref TableBuilder::_null_bind() { + return Ref(null()); +} +Ref TableBuilder::_defval_bind(const String &val) { + return Ref(defval(val)); +} +Ref TableBuilder::_auto_increment_bind() { + return Ref(auto_increment()); +} +Ref TableBuilder::_primary_key_bind(const String &name) { + return Ref(primary_key(name)); +} +Ref TableBuilder::_next_row_bind() { + return Ref(next_row()); +} +Ref TableBuilder::_ccreate_table_bind() { + return Ref(ccreate_table()); +} + +Ref TableBuilder::_drop_table_bind(const String &name) { + return Ref(drop_table(name)); +} +Ref TableBuilder::_drop_table_if_exists_bind(const String &name) { + return Ref(drop_table_if_exists(name)); +} +Ref TableBuilder::_cdrop_table_bind() { + return Ref(cdrop_table()); +} + +Ref TableBuilder::_foreign_key_bind(const String &name) { + return Ref(foreign_key(name)); +} +Ref TableBuilder::_references_bind(const String &table, const String &name) { + return Ref(references(table, name)); +} diff --git a/modules/database/table_builder.h b/modules/database/table_builder.h index 45407f764..7e52bb3a2 100644 --- a/modules/database/table_builder.h +++ b/modules/database/table_builder.h @@ -1,50 +1,42 @@ #ifndef TABLE_BUILDER_H #define TABLE_BUILDER_H -#include "core/string.h" +#include "core/ustring.h" #include "core/reference.h" class QueryResult; class TableBuilder : public Reference { - RCPP_OBJECT(TableBuilder, Reference); - + GDCLASS(TableBuilder, Reference); + public: + String get_result(); + void set_result(const String &val); + virtual TableBuilder *create_table(const String &name); - - virtual TableBuilder *integer(const String &name); - virtual TableBuilder *integer(const String &name, const int length); - virtual TableBuilder *tiny_integer(const String &name); - virtual TableBuilder *tiny_integer(const String &name, const int length); - - virtual TableBuilder *small_integer(const String &name); - virtual TableBuilder *small_integer(const String &name, const int length); - - virtual TableBuilder *real_float(const String &name); - virtual TableBuilder *real_float(const String &name, const int size, const int d); - - virtual TableBuilder *real_double(const String &name); - virtual TableBuilder *real_double(const String &name, const int size, const int d); + virtual TableBuilder *integer(const String &name, const int length = -1); + virtual TableBuilder *tiny_integer(const String &name, const int length = -1); + virtual TableBuilder *small_integer(const String &name, const int length = -1); + virtual TableBuilder *real_float(const String &name, const int size = -1, const int d = -1); + virtual TableBuilder *real_double(const String &name, const int size = -1, const int d = -1); virtual TableBuilder *date(const String &name); - virtual TableBuilder *varchar(const String &name, const int length); + virtual TableBuilder *varchar(const String &name, const int length = -1); virtual TableBuilder *text(const String &name); virtual TableBuilder *not_null(); virtual TableBuilder *null(); virtual TableBuilder *defval(const String &val); virtual TableBuilder *auto_increment(); - virtual TableBuilder *primary_key(const String &name); - virtual TableBuilder *primary_key(); + virtual TableBuilder *primary_key(const String &name = ""); virtual TableBuilder *next_row(); virtual TableBuilder *ccreate_table(); - virtual TableBuilder *drop_table(); virtual TableBuilder *drop_table_if_exists(); - virtual TableBuilder *drop_table(const String &name); + virtual TableBuilder *drop_table(const String &name = ""); virtual TableBuilder *drop_table_if_exists(const String &name); virtual TableBuilder *cdrop_table(); @@ -60,6 +52,37 @@ public: virtual ~TableBuilder(); String result; + +protected: + static void _bind_methods(); + + Ref _create_table_bind(const String &name); + + Ref _integer_bind(const String &name, const int length = -1); + Ref _tiny_integer_bind(const String &name, const int length = -1); + Ref _small_integer_bind(const String &name, const int length = -1); + Ref _real_float_bind(const String &name, const int size = -1, const int d = -1); + Ref _real_double_bind(const String &name, const int size = -1, const int d = -1); + + Ref _date_bind(const String &name); + + Ref _varchar_bind(const String &name, const int length = -1); + Ref _text_bind(const String &name); + + Ref _not_null_bind(); + Ref _null_bind(); + Ref _defval_bind(const String &val); + Ref _auto_increment_bind(); + Ref _primary_key_bind(const String &name = ""); + Ref _next_row_bind(); + Ref _ccreate_table_bind(); + + Ref _drop_table_bind(const String &name = ""); + Ref _drop_table_if_exists_bind(const String &name); + Ref _cdrop_table_bind(); + + Ref _foreign_key_bind(const String &name); + Ref _references_bind(const String &table, const String &name); }; -#endif \ No newline at end of file +#endif