Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using MySql.Data.MySqlClient;
- namespace eddb
- {
- public abstract class SQLTable
- {
- abstract public string table_name
- {
- get;
- }
- public bool debug_console = false;
- public const int INVALID_ID = SQLTypes.SQLId.INVALID;
- public const string ID_STRING = "Id";
- protected SQLTypes.SQLId id = INVALID_ID;
- /*Create the table, returns true on success*/
- public virtual bool CreateTable(MySqlConnection conn)
- {
- bool retval = false;
- MySqlCommand cmd = new MySqlCommand();
- Entry table_entry = GetNewEntry();
- if (conn.State != System.Data.ConnectionState.Open)
- return false;
- cmd.Connection = conn;
- cmd.CommandText = "CREATE TABLE IF NOT EXISTS "+ table_name + " (";
- cmd.CommandText += id.GetCreationString(ID_STRING) + " PRIMARY KEY";
- foreach (KeyValuePair<string, SQLTypes.SQLObject> obj in table_entry.Columns)
- {
- cmd.CommandText += ", " + obj.Value.GetCreationString(obj.Key);
- }
- cmd.CommandText += ") ENGINE=INNODB;";
- try
- {
- cmd.Prepare();
- cmd.ExecuteNonQuery();
- retval = true;
- }
- catch
- {
- retval = false;
- }
- Console.Write(cmd.CommandText + "\n");
- return retval;
- }
- public abstract Entry GetNewEntry();
- public abstract class Entry
- {
- public Dictionary<string, SQLTypes.SQLObject> Columns;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement