mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-20 19:06:53 +01:00
203 lines
4.0 KiB
C++
203 lines
4.0 KiB
C++
#include "sqlite3_table_builder.h"
|
|
|
|
#include "database/query_result.h"
|
|
|
|
#include "sqlite3_database.h"
|
|
|
|
TableBuilder *SQLite3TableBuilder::create_table(const String &name) {
|
|
result += "CREATE TABLE " + name + " ( ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::integer(const String &name) {
|
|
result += name + " INTEGER ";
|
|
|
|
return this;
|
|
}
|
|
TableBuilder *SQLite3TableBuilder::integer(const String &name, const int length) {
|
|
result += name + " INTEGER(";
|
|
result += String::num(length);
|
|
result += ") ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::tiny_integer(const String &name) {
|
|
result += name + " INTEGER(4) ";
|
|
|
|
return this;
|
|
}
|
|
TableBuilder *SQLite3TableBuilder::tiny_integer(const String &name, const int length) {
|
|
result += name + " INTEGER(";
|
|
result += String::num(length);
|
|
result += ") ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::small_integer(const String &name) {
|
|
result += name + " INTEGER(6) ";
|
|
|
|
return this;
|
|
}
|
|
TableBuilder *SQLite3TableBuilder::small_integer(const String &name, const int length) {
|
|
result += name + " INTEGER(";
|
|
result += String::num(length);
|
|
result += ") ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::real_float(const String &name) {
|
|
result += name + " FLOAT ";
|
|
|
|
return this;
|
|
}
|
|
TableBuilder *SQLite3TableBuilder::real_float(const String &name, const int size, const int d) {
|
|
result += name + " FLOAT ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::real_double(const String &name) {
|
|
result += name + " DOUBLE ";
|
|
|
|
return this;
|
|
}
|
|
TableBuilder *SQLite3TableBuilder::real_double(const String &name, const int size, const int d) {
|
|
result += name + " DOUBLE ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::date(const String &name) {
|
|
result += name + " DATE ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::varchar(const String &name, const int length) {
|
|
result += name + " VARCHAR(" + std::to_string(length) + ") ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::text(const String &name) {
|
|
result += name + " TEXT ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::not_null() {
|
|
//result += "NOT NULL ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::null() {
|
|
result += "NULL ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::defval(const String &val) {
|
|
result += "DEFAULT '";
|
|
result += val;
|
|
result += "'";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::auto_increment() {
|
|
//result += "AUTO_INCREMENT ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::primary_key(const String &name) {
|
|
result += "PRIMARY KEY (" + name + ") ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::primary_key() {
|
|
result += "PRIMARY KEY ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::next_row() {
|
|
result += ", ";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::ccreate_table() {
|
|
result += ");";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::drop_table() {
|
|
result += "DROP TABLE ";
|
|
|
|
return this;
|
|
}
|
|
TableBuilder *SQLite3TableBuilder::drop_table_if_exists() {
|
|
result += "DROP TABLE IF EXISTS ";
|
|
|
|
return this;
|
|
}
|
|
TableBuilder *SQLite3TableBuilder::drop_table(const String &name) {
|
|
result += "DROP TABLE " + name + ";";
|
|
|
|
return this;
|
|
}
|
|
TableBuilder *SQLite3TableBuilder::drop_table_if_exists(const String &name) {
|
|
result += "DROP TABLE IF EXISTS " + name + ";";
|
|
|
|
return this;
|
|
}
|
|
TableBuilder *SQLite3TableBuilder::cdrop_table() {
|
|
result += ";";
|
|
|
|
return this;
|
|
}
|
|
|
|
TableBuilder *SQLite3TableBuilder::foreign_key(const String &name) {
|
|
result += "FOREIGN KEY (" + name + ") ";
|
|
|
|
return this;
|
|
}
|
|
TableBuilder *SQLite3TableBuilder::references(const String &table, const String &name) {
|
|
result += "REFERENCES " + table + " (" + name + ") ";
|
|
|
|
return this;
|
|
}
|
|
|
|
Ref<QueryResult> SQLite3TableBuilder::run() {
|
|
if (!_db) {
|
|
printf("SQLite3TableBuilder::run !db!\n");
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
return _db->query(result);
|
|
}
|
|
|
|
void SQLite3TableBuilder::run_query() {
|
|
if (!_db) {
|
|
printf("SQLite3TableBuilder::run_query !db!\n");
|
|
|
|
return;
|
|
}
|
|
|
|
_db->query_run(result);
|
|
}
|
|
|
|
SQLite3TableBuilder::SQLite3TableBuilder() {
|
|
}
|
|
|
|
SQLite3TableBuilder::~SQLite3TableBuilder() {
|
|
} |