diff --git a/Cicm.Database/Operations/Company.cs b/Cicm.Database/Operations/Company.cs index a5358d32..7256c782 100644 --- a/Cicm.Database/Operations/Company.cs +++ b/Cicm.Database/Operations/Company.cs @@ -178,7 +178,10 @@ namespace Cicm.Database IDbTransaction trans = dbCon.BeginTransaction(); dbcmd.Transaction = trans; - const string SQL = "INSERT INTO companies (name)" + " VALUES (@name)"; + const string SQL = "INSERT INTO companies (name, founded, website, twitter, facebook, sold, sold_to, " + + "address, city, province, postal_code, country) VALUES (@name, @founded, @website, " + + "@twitter, @facebook, @sold, @sold_to, @address, @city, @province, @postal_code, " + + "@country)"; dbcmd.CommandText = SQL; @@ -210,7 +213,11 @@ namespace Cicm.Database IDbTransaction trans = dbCon.BeginTransaction(); dbcmd.Transaction = trans; - string sql = "UPDATE companies SET name = @name " + $"WHERE id = {entry.Id}"; + string sql = + "UPDATE companies SET name = @name, founded = @founded, website = @website, twitter = @twitter, " + + "facebook = @facebook, sold = @sold, sold_to = @sold_to, address = @address, city = @city, " + + "province = @province, postal_code = @postal_code, country = @country, " + + $"WHERE id = {entry.Id}"; dbcmd.CommandText = sql; @@ -251,20 +258,85 @@ namespace Cicm.Database { IDbCommand dbcmd = dbCon.CreateCommand(); - IDbDataParameter param1 = dbcmd.CreateParameter(); + IDbDataParameter param1 = dbcmd.CreateParameter(); + IDbDataParameter param2 = dbcmd.CreateParameter(); + IDbDataParameter param3 = dbcmd.CreateParameter(); + IDbDataParameter param4 = dbcmd.CreateParameter(); + IDbDataParameter param5 = dbcmd.CreateParameter(); + IDbDataParameter param6 = dbcmd.CreateParameter(); + IDbDataParameter param7 = dbcmd.CreateParameter(); + IDbDataParameter param8 = dbcmd.CreateParameter(); + IDbDataParameter param9 = dbcmd.CreateParameter(); + IDbDataParameter param10 = dbcmd.CreateParameter(); + IDbDataParameter param11 = dbcmd.CreateParameter(); + IDbDataParameter param12 = dbcmd.CreateParameter(); - param1.ParameterName = "@name"; + param1.ParameterName = "@name"; + param2.ParameterName = "@founded"; + param3.ParameterName = "@website"; + param4.ParameterName = "@twitter"; + param5.ParameterName = "@facebook"; + param6.ParameterName = "@sold"; + param7.ParameterName = "@sold_to"; + param8.ParameterName = "@address"; + param9.ParameterName = "@city"; + param10.ParameterName = "@province"; + param11.ParameterName = "@postal_code"; + param12.ParameterName = "@country"; - param1.DbType = DbType.String; + param1.DbType = DbType.String; + param2.DbType = DbType.DateTime; + param3.DbType = DbType.String; + param4.DbType = DbType.String; + param5.DbType = DbType.String; + param6.DbType = DbType.DateTime; + param7.DbType = DbType.UInt32; + param8.DbType = DbType.String; + param9.DbType = DbType.String; + param10.DbType = DbType.String; + param11.DbType = DbType.String; + param12.DbType = DbType.UInt16; param1.Value = entry.Name; + param2.Value = entry.Founded; + param3.Value = entry.Website; + param4.Value = entry.Twitter; + param5.Value = entry.Facebook; + if(entry.SoldTo != null) + { + param6.Value = entry.Sold; + param7.Value = entry.SoldTo.Id; + } + else + { + param6.Value = null; + param7.Value = null; + } + + param8.Value = entry.Address; + param9.Value = entry.City; + param10.Value = entry.Province; + param11.Value = entry.PostalCode; + if(entry.Country != null) param12.Value = entry.Country.Id; + else param12.Value = null; dbcmd.Parameters.Add(param1); + dbcmd.Parameters.Add(param2); + dbcmd.Parameters.Add(param3); + dbcmd.Parameters.Add(param4); + dbcmd.Parameters.Add(param5); + dbcmd.Parameters.Add(param6); + dbcmd.Parameters.Add(param7); + dbcmd.Parameters.Add(param8); + dbcmd.Parameters.Add(param9); + dbcmd.Parameters.Add(param10); + dbcmd.Parameters.Add(param11); + dbcmd.Parameters.Add(param12); return dbcmd; } - static List CompaniesFromDataTable(DataTable dataTable) + List CompaniesFromDataTable(DataTable dataTable) { List entries = new List(); @@ -272,10 +344,30 @@ namespace Cicm.Database { Company entry = new Company { - Id = int.Parse(dataRow["id"].ToString()), - Name = dataRow["name"].ToString() + Id = int.Parse(dataRow["id"].ToString()), + Name = dataRow["name"].ToString(), + Website = dataRow["website"].ToString(), + Twitter = dataRow["twitter"].ToString(), + Facebook = dataRow["facebook"].ToString(), + Address = dataRow["address"].ToString(), + City = dataRow["city"].ToString(), + Province = dataRow["province"].ToString(), + PostalCode = dataRow["postal_code"].ToString() }; + if(!string.IsNullOrWhiteSpace(dataRow["founded"].ToString())) + entry.Founded = Convert.ToDateTime(dataRow["founded"].ToString()); + + if(!string.IsNullOrWhiteSpace(dataRow["sold"].ToString()) && + !string.IsNullOrWhiteSpace(dataRow["sold_to"].ToString())) + { + entry.Sold = Convert.ToDateTime(dataRow["sold"].ToString()); + entry.SoldTo = GetCompany(int.Parse(dataRow["sold_to"].ToString())); + } + + if(!string.IsNullOrWhiteSpace(dataRow["country"].ToString())) + entry.Country = GetIso3166(int.Parse(dataRow["country"].ToString())); + entries.Add(entry); } diff --git a/Cicm.Database/Operations/Init.cs b/Cicm.Database/Operations/Init.cs index 0525b8bb..b171bfb7 100644 --- a/Cicm.Database/Operations/Init.cs +++ b/Cicm.Database/Operations/Init.cs @@ -49,79 +49,91 @@ namespace Cicm.Database IDbCommand dbCmd = dbCon.CreateCommand(); Console.WriteLine("Creating table `admins`"); - dbCmd.CommandText = V5.Admins; + dbCmd.CommandText = V6.Admins; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `browser_tests`"); - dbCmd.CommandText = V5.BrowserTests; + dbCmd.CommandText = V6.BrowserTests; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `cicm_db`"); - dbCmd.CommandText = V5.CicmDb; + dbCmd.CommandText = V6.CicmDb; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `companies`"); - dbCmd.CommandText = V5.Companies; + dbCmd.CommandText = V6.Companies; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `computers`"); - dbCmd.CommandText = V5.Computers; + dbCmd.CommandText = V6.Computers; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `consoles`"); - dbCmd.CommandText = V5.Consoles; + dbCmd.CommandText = V6.Consoles; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `disk_formats`"); - dbCmd.CommandText = V5.DiskFormats; + dbCmd.CommandText = V6.DiskFormats; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `forbidden`"); - dbCmd.CommandText = V5.Forbidden; + dbCmd.CommandText = V6.Forbidden; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `gpus`"); - dbCmd.CommandText = V5.Gpus; + dbCmd.CommandText = V6.Gpus; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `log`"); - dbCmd.CommandText = V5.Logs; + dbCmd.CommandText = V6.Logs; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `money_donations`"); - dbCmd.CommandText = V5.MoneyDonations; + dbCmd.CommandText = V6.MoneyDonations; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `music_synths`"); - dbCmd.CommandText = V5.MusicSynths; + dbCmd.CommandText = V6.MusicSynths; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `news`"); - dbCmd.CommandText = V5.News; + dbCmd.CommandText = V6.News; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `owned_computers`"); - dbCmd.CommandText = V5.OwnedComputers; + dbCmd.CommandText = V6.OwnedComputers; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `owned_consoles`"); - dbCmd.CommandText = V5.OwnedConsoles; + dbCmd.CommandText = V6.OwnedConsoles; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `processors`"); - dbCmd.CommandText = V5.Processors; + dbCmd.CommandText = V6.Processors; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `sound_synths`"); - dbCmd.CommandText = V5.SoundSynths; + dbCmd.CommandText = V6.SoundSynths; + dbCmd.ExecuteNonQuery(); + + Console.WriteLine("Creating table `iso3166_1_numeric`"); + dbCmd.CommandText = V6.Iso3166Numeric; + dbCmd.ExecuteNonQuery(); + + Console.WriteLine("Filling table `iso3166_1_numeric`"); + dbCmd.CommandText = V6.Iso3166NumericValues; + dbCmd.ExecuteNonQuery(); + + Console.WriteLine("Creating foreign keys for table `companies`"); + dbCmd.CommandText = V6.CompaniesForeignKeys; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating foreign keys for table `computers`"); - dbCmd.CommandText = V5.ComputersForeignKeys; + dbCmd.CommandText = V6.ComputersForeignKeys; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating foreign keys for table `consoles`"); - dbCmd.CommandText = V5.ConsolesForeignKeys; + dbCmd.CommandText = V6.ConsolesForeignKeys; dbCmd.ExecuteNonQuery(); return true; diff --git a/Cicm.Database/Operations/Iso3166.cs b/Cicm.Database/Operations/Iso3166.cs new file mode 100644 index 00000000..d217ab2e --- /dev/null +++ b/Cicm.Database/Operations/Iso3166.cs @@ -0,0 +1,285 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : Iso3166.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Contains operations to manage iso3166_1_numeric. +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Data; +using Cicm.Database.Schemas; +using Console = System.Console; + +namespace Cicm.Database +{ + public partial class Operations + { + /// + /// Gets all ISO 3166-1 codes + /// + /// All ISO 3166-1 codes + /// true if is correct, false otherwise + public bool GetIso3166(out List entries) + { + #if DEBUG + Console.WriteLine("Getting all ISO 3166-1 codes..."); + #endif + + try + { + const string SQL = "SELECT * from iso3166_1_numeric"; + + IDbCommand dbCmd = dbCon.CreateCommand(); + IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter(); + dbCmd.CommandText = SQL; + DataSet dataSet = new DataSet(); + dataAdapter.SelectCommand = dbCmd; + dataAdapter.Fill(dataSet); + + entries = Iso3166FromDataTable(dataSet.Tables[0]); + + return true; + } + catch(Exception ex) + { + Console.WriteLine("Error getting ISO 3166-1 codes."); + Console.WriteLine(ex); + entries = null; + return false; + } + } + + /// + /// Gets the specified number of ISO 3166-1 codes since the specified start + /// + /// List of ISO 3166-1 codes + /// Start of query + /// How many entries to retrieve + /// true if is correct, false otherwise + public bool GetIso3166(out List entries, ulong start, ulong count) + { + #if DEBUG + Console.WriteLine("Getting {0} ISO 3166-1 codes from {1}...", count, start); + #endif + + try + { + string sql = $"SELECT * FROM iso3166_1_numeric LIMIT {start}, {count}"; + + IDbCommand dbCmd = dbCon.CreateCommand(); + IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter(); + dbCmd.CommandText = sql; + DataSet dataSet = new DataSet(); + dataAdapter.SelectCommand = dbCmd; + dataAdapter.Fill(dataSet); + + entries = Iso3166FromDataTable(dataSet.Tables[0]); + + return true; + } + catch(Exception ex) + { + Console.WriteLine("Error getting ISO 3166-1 codes."); + Console.WriteLine(ex); + entries = null; + return false; + } + } + + /// + /// Gets ISO 3166-1 code by specified id + /// + /// Id + /// ISO 3166-1 code with specified id, null if not found or error + public Iso3166 GetIso3166(int id) + { + #if DEBUG + Console.WriteLine("Getting ISO 3166-1 code with id {0}...", id); + #endif + + try + { + string sql = $"SELECT * from iso3166_1_numeric WHERE id = '{id}'"; + + IDbCommand dbCmd = dbCon.CreateCommand(); + IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter(); + dbCmd.CommandText = sql; + DataSet dataSet = new DataSet(); + dataAdapter.SelectCommand = dbCmd; + dataAdapter.Fill(dataSet); + + List entries = Iso3166FromDataTable(dataSet.Tables[0]); + + return entries == null || entries.Count == 0 ? null : entries[0]; + } + catch(Exception ex) + { + Console.WriteLine("Error getting ISO 3166-1 code."); + Console.WriteLine(ex); + return null; + } + } + + /// + /// Counts the number of ISO 3166-1 codes in the database + /// + /// Entries in database + public long CountIso3166() + { + #if DEBUG + Console.WriteLine("Counting ISO 3166-1 codes..."); + #endif + + IDbCommand dbcmd = dbCon.CreateCommand(); + dbcmd.CommandText = "SELECT COUNT(*) FROM iso3166_1_numeric"; + object count = dbcmd.ExecuteScalar(); + dbcmd.Dispose(); + try { return Convert.ToInt64(count); } + catch { return 0; } + } + + /// + /// Adds a new ISO 3166-1 code to the database + /// + /// Entry to add + /// ID of added entry + /// true if added correctly, false otherwise + public bool AddIso3166(Iso3166 entry, out long id) + { + #if DEBUG + Console.Write("Adding ISO 3166-1 code `{0}`...", entry.Name); + #endif + + IDbCommand dbcmd = GetCommandIso3166(entry); + IDbTransaction trans = dbCon.BeginTransaction(); + dbcmd.Transaction = trans; + + const string SQL = "INSERT INTO iso3166_1_numeric (name)" + " VALUES (@name)"; + + dbcmd.CommandText = SQL; + + dbcmd.ExecuteNonQuery(); + trans.Commit(); + dbcmd.Dispose(); + + id = dbCore.LastInsertRowId; + + #if DEBUG + Console.WriteLine(" id {0}", id); + #endif + + return true; + } + + /// + /// Updates an ISO 3166-1 code in the database + /// + /// Updated entry + /// true if updated correctly, false otherwise + public bool UpdateIso3166(Iso3166 entry) + { + #if DEBUG + Console.WriteLine("Updating ISO 3166-1 code `{0}`...", entry.Name); + #endif + + IDbCommand dbcmd = GetCommandIso3166(entry); + IDbTransaction trans = dbCon.BeginTransaction(); + dbcmd.Transaction = trans; + + string sql = "UPDATE iso3166_1_numeric SET name = @name " + $"WHERE id = {entry.Id}"; + + dbcmd.CommandText = sql; + + dbcmd.ExecuteNonQuery(); + trans.Commit(); + dbcmd.Dispose(); + + return true; + } + + /// + /// Removes an ISO 3166-1 code from the database + /// + /// ID of entry to remove + /// true if removed correctly, false otherwise + public bool RemoveIso3166(long id) + { + #if DEBUG + Console.WriteLine("Removing ISO 3166-1 code `{0}`...", id); + #endif + + IDbCommand dbcmd = dbCon.CreateCommand(); + IDbTransaction trans = dbCon.BeginTransaction(); + dbcmd.Transaction = trans; + + string sql = $"DELETE FROM iso3166_1_numeric WHERE id = '{id}';"; + + dbcmd.CommandText = sql; + + dbcmd.ExecuteNonQuery(); + trans.Commit(); + dbcmd.Dispose(); + + return true; + } + + IDbCommand GetCommandIso3166(Iso3166 entry) + { + IDbCommand dbcmd = dbCon.CreateCommand(); + + IDbDataParameter param1 = dbcmd.CreateParameter(); + + param1.ParameterName = "@name"; + + param1.DbType = DbType.String; + + param1.Value = entry.Name; + + dbcmd.Parameters.Add(param1); + + return dbcmd; + } + + static List Iso3166FromDataTable(DataTable dataTable) + { + List entries = new List(); + + foreach(DataRow dataRow in dataTable.Rows) + { + Iso3166 entry = new Iso3166 + { + Id = ushort.Parse(dataRow["id"].ToString()), + Name = dataRow["name"].ToString() + }; + + entries.Add(entry); + } + + return entries; + } + } +} \ No newline at end of file diff --git a/Cicm.Database/Operations/Operations.cs b/Cicm.Database/Operations/Operations.cs index e753a3c6..2ee2052e 100644 --- a/Cicm.Database/Operations/Operations.cs +++ b/Cicm.Database/Operations/Operations.cs @@ -35,7 +35,7 @@ namespace Cicm.Database public partial class Operations { /// Last known database version - const int DB_VERSION = 5; + const int DB_VERSION = 6; readonly IDbConnection dbCon; readonly IDbCore dbCore; diff --git a/Cicm.Database/Operations/Update.cs b/Cicm.Database/Operations/Update.cs index 04b8bdce..3206d48a 100644 --- a/Cicm.Database/Operations/Update.cs +++ b/Cicm.Database/Operations/Update.cs @@ -33,7 +33,6 @@ using System.Collections.Generic; using System.Data; using System.IO; using Cicm.Database.Schemas.Sql; -using MySql.Data.MySqlClient; namespace Cicm.Database { @@ -81,17 +80,22 @@ namespace Cicm.Database { case 2: { - UpdateDatabaseV2ToV3(); + UpdateDatabaseToV3(); break; } case 3: { - UpdateDatabaseV3ToV4(); + UpdateDatabaseToV4(); break; } case 4: { - UpdateDatabaseV4ToV5(); + UpdateDatabaseToV5(); + break; + } + case 5: + { + UpdateDatabaseToV6(); break; } } @@ -100,7 +104,7 @@ namespace Cicm.Database return true; } - void UpdateDatabaseV2ToV3() + void UpdateDatabaseToV3() { Console.WriteLine("Updating database to version 3"); @@ -373,7 +377,7 @@ namespace Cicm.Database Console.WriteLine("Finished update version to 3..."); } - void UpdateDatabaseV3ToV4() + void UpdateDatabaseToV4() { Console.WriteLine("Updating database to version 4"); IDbCommand dbCmd; @@ -640,7 +644,7 @@ namespace Cicm.Database dbCmd.Dispose(); } - void UpdateDatabaseV4ToV5() + void UpdateDatabaseToV5() { Console.WriteLine("Updating database to version 5"); @@ -663,6 +667,84 @@ namespace Cicm.Database dbCmd.Dispose(); } + void UpdateDatabaseToV6() + { + Console.WriteLine("Updating database to version 6"); + + Console.WriteLine("Creating table `iso3166_1_numeric`"); + IDbCommand dbCmd = dbCon.CreateCommand(); + IDbTransaction trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = V6.Iso3166Numeric; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Filling table `iso3166_1_numeric`"); + dbCmd = dbCon.CreateCommand(); + trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = V6.Iso3166NumericValues; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Adding new columns to table `companies`"); + dbCmd = dbCon.CreateCommand(); + trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = "ALTER TABLE `companies` ADD COLUMN `founded` DATETIME NULL;\n" + + "ALTER TABLE `companies` ADD COLUMN `website` VARCHAR(255) NULL;\n" + + "ALTER TABLE `companies` ADD COLUMN `twitter` VARCHAR(45) NULL;\n" + + "ALTER TABLE `companies` ADD COLUMN `facebook` VARCHAR(45) NULL;\n" + + "ALTER TABLE `companies` ADD COLUMN `sold` DATETIME NULL;\n" + + "ALTER TABLE `companies` ADD COLUMN `sold_to` INT(11) NULL;\n" + + "ALTER TABLE `companies` ADD COLUMN `address` VARCHAR(80) NULL;\n" + + "ALTER TABLE `companies` ADD COLUMN `city` VARCHAR(80) NULL;\n" + + "ALTER TABLE `companies` ADD COLUMN `province` VARCHAR(80) NULL;\n" + + "ALTER TABLE `companies` ADD COLUMN `postal_code` VARCHAR(25) NULL;\n" + + "ALTER TABLE `companies` ADD COLUMN `country` SMALLINT(3) UNSIGNED ZEROFILL NULL;"; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Adding new indexes to table `companies`"); + dbCmd = dbCon.CreateCommand(); + trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = "CREATE INDEX `idx_companies_founded` ON `companies` (`founded`);\n" + + "CREATE INDEX `idx_companies_website` ON `companies` (`website`);\n" + + "CREATE INDEX `idx_companies_twitter` ON `companies` (`twitter`);\n" + + "CREATE INDEX `idx_companies_facebook` ON `companies` (`facebook`);\n" + + "CREATE INDEX `idx_companies_sold` ON `companies` (`sold`);\n" + + "CREATE INDEX `idx_companies_sold_to` ON `companies` (`sold_to`);\n" + + "CREATE INDEX `idx_companies_address` ON `companies` (`address`);\n" + + "CREATE INDEX `idx_companies_city` ON `companies` (`city`);\n" + + "CREATE INDEX `idx_companies_province` ON `companies` (`province`);\n" + + "CREATE INDEX `idx_companies_postal_code` ON `companies` (`postal_code`);\n" + + "CREATE INDEX `idx_companies_country` ON `companies` (`country`);"; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Adding new foreign keys to table `companies`"); + dbCmd = dbCon.CreateCommand(); + trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = + "ALTER TABLE `companies` ADD FOREIGN KEY `fk_companies_sold_to` (sold_to) REFERENCES `companies` (`id`);\n" + + "ALTER TABLE `companies` ADD FOREIGN KEY `fk_companies_country` (country) REFERENCES `iso3166_1_numeric` (`id`);"; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Setting new database version to 6..."); + dbCmd = dbCon.CreateCommand(); + dbCmd.CommandText = "INSERT INTO cicm_db (version) VALUES ('6')"; + dbCmd.ExecuteNonQuery(); + dbCmd.Dispose(); + } + void OptimizeDatabase() { IDbCommand dbCmd = dbCon.CreateCommand(); diff --git a/Cicm.Database/Schemas/Company.cs b/Cicm.Database/Schemas/Company.cs index d437d6e4..b1951dfa 100644 --- a/Cicm.Database/Schemas/Company.cs +++ b/Cicm.Database/Schemas/Company.cs @@ -28,14 +28,38 @@ // Copyright © 2003-2018 Natalia Portillo *******************************************************************************/ +using System; + namespace Cicm.Database.Schemas { /// Company public class Company { + /// Address + public string Address; + /// City + public string City; + /// Country + public Iso3166 Country; + /// Facebook account + public string Facebook; + /// Founding date + public DateTime Founded; /// ID public int Id; /// Name public string Name; + /// Postal code + public string PostalCode; + /// Province + public string Province; + /// Sold date + public DateTime Sold; + /// Company it was sold to + public Company SoldTo; + /// Twitter account + public string Twitter; + /// Website + public string Website; } } \ No newline at end of file diff --git a/Cicm.Database/Schemas/Iso3166.cs b/Cicm.Database/Schemas/Iso3166.cs new file mode 100644 index 00000000..921b0704 --- /dev/null +++ b/Cicm.Database/Schemas/Iso3166.cs @@ -0,0 +1,41 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : Iso3166.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// High level representation of a ISO 3166-1 Numeric. +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ + +namespace Cicm.Database.Schemas +{ + /// Country code from ISO 3166-1 Numeric + public class Iso3166 + { + /// ISO assigned ID + public ushort Id; + /// English name + public string Name; + } +} \ No newline at end of file diff --git a/Cicm.Database/Schemas/Sql/V6.cs b/Cicm.Database/Schemas/Sql/V6.cs new file mode 100644 index 00000000..1251060e --- /dev/null +++ b/Cicm.Database/Schemas/Sql/V6.cs @@ -0,0 +1,177 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : V6.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Contains SQL queries to create the database version 6. +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ + +namespace Cicm.Database.Schemas.Sql +{ + public static class V6 + { + public static readonly string Admins = V5.Admins; + + public static readonly string BrowserTests = V5.BrowserTests; + + public static readonly string CicmDb = "CREATE TABLE `cicm_db` (\n" + + "`id` int(11) NOT NULL AUTO_INCREMENT,\n" + + "`version` int(11) NOT NULL,\n" + + "`updated` datetime DEFAULT CURRENT_TIMESTAMP,\n" + + "PRIMARY KEY (`id`)\n" + ");\n" + + "INSERT INTO cicm_db (version) VALUES ('6');"; + + public static readonly string Companies = "CREATE TABLE `companies` (\n" + + "`id` int(11) NOT NULL AUTO_INCREMENT,\n" + + "`name` varchar(128) NOT NULL DEFAULT '',\n" + + "`founded` datetime DEFAULT NULL,\n" + + "`website` varchar(255) DEFAULT NULL,\n" + + "`twitter` varchar(45) DEFAULT NULL,\n" + + "`facebook` varchar(45) DEFAULT NULL,\n" + + "`sold` datetime DEFAULT NULL,\n" + + "`sold_to` int(11) DEFAULT NULL,\n" + + "`address` varchar(80) DEFAULT NULL,\n" + + "`city` varchar(80) DEFAULT NULL,\n" + + "`province` varchar(80) DEFAULT NULL,\n" + + "`postal_code` varchar(25) DEFAULT NULL,\n" + + "`country` smallint(3) UNSIGNED ZEROFILL DEFAULT NULL,\n" + + "PRIMARY KEY (`id`),\n" + + "KEY `idx_companies_name` (`name`),\n" + + "KEY `idx_companies_founded` (`founded`),\n" + + "KEY `idx_companies_website` (`website`),\n" + + "KEY `idx_companies_twitter` (`twitter`),\n" + + "KEY `idx_companies_facebook` (`facebook`),\n" + + "KEY `idx_companies_sold` (`sold`),\n" + + "KEY `idx_companies_sold_to` (`sold_to`),\n" + + "KEY `idx_companies_address` (`address`),\n" + + "KEY `idx_companies_city` (`city`),\n" + + "KEY `idx_companies_province` (`province`),\n" + + "KEY `idx_companies_postal_code` (`postal_code`),\n" + + "KEY `idx_companies_country` (`country`));"; + + public static readonly string Computers = V5.Computers; + + public static readonly string Consoles = V5.Consoles; + + public static readonly string DiskFormats = V5.DiskFormats; + + public static readonly string Forbidden = V5.Forbidden; + + public static readonly string Gpus = V5.Gpus; + + public static readonly string Logs = V5.Logs; + + public static readonly string MoneyDonations = V5.MoneyDonations; + + public static readonly string MusicSynths = V5.MusicSynths; + + public static readonly string News = V5.News; + + public static readonly string OwnedComputers = V5.OwnedComputers; + + public static readonly string OwnedConsoles = V5.OwnedConsoles; + + public static readonly string Processors = V5.Processors; + + public static readonly string SoundSynths = V5.SoundSynths; + + public static readonly string ComputersForeignKeys = V5.ComputersForeignKeys; + + public static readonly string ConsolesForeignKeys = V5.ConsolesForeignKeys; + + public static readonly string Iso3166Numeric = "CREATE TABLE `iso3166_1_numeric` (\n" + + "`id` SMALLINT(3) UNSIGNED ZEROFILL NOT NULL,\n" + + "`name` VARCHAR(64) NOT NULL,\n" + + "PRIMARY KEY (`id`),\n" + + "INDEX `idx_name` (`name` ASC));"; + + public static readonly string Iso3166NumericValues = + "INSERT INTO `iso3166_1_numeric` VALUES (004,'Afghanistan'),(248,'Åland Islands'),(008,'Albania')," + + "(012,'Algeria'),(016,'American Samoa'),(020,'Andorra'),(024,'Angola'),(660,'Anguilla'),(010,'Antarctica')," + + "(028,'Antigua and Barbuda'),(032,'Argentina'),(051,'Armenia'),(533,'Aruba'),(036,'Australia')," + + "(040,'Austria'),(031,'Azerbaijan'),(044,'Bahamas'),(048,'Bahrain'),(050,'Bangladesh'),(052,'Barbados')," + + "(112,'Belarus'),(056,'Belgium'),(084,'Belize'),(204,'Benin'),(060,'Bermuda'),(064,'Bhutan')," + + "(862,'Bolivarian Republic of Venezuela'),(535,'Bonaire, Sint Eustatius and Saba')," + + "(070,'Bosnia and Herzegovina'),(072,'Botswana'),(074,'Bouvet Island'),(076,'Brazil')," + + "(080,'British Antarctic Territory'),(086,'British Indian Ocean Territory'),(092,'British Virgin Islands')," + + "(096,'Brunei Darussalam'),(100,'Bulgaria'),(854,'Burkina Faso'),(108,'Burundi'),(132,'Cabo Verde')," + + "(116,'Cambodia'),(120,'Cameroon'),(124,'Canada'),(128,'Canton and Enderbury Islands')," + + "(136,'Cayman Islands'),(140,'Central African Republic'),(148,'Chad'),(830,'Channel Islands'),(152,'Chile')," + + "(156,'China'),(162,'Christmas Island'),(166,'Cocos (Keeling) Islands'),(170,'Colombia'),(174,'Comoros')," + + "(178,'Congo'),(184,'Cook Islands'),(188,'Costa Rica'),(384,'Côte d\\'Ivoire'),(191,'Croatia'),(192,'Cuba')," + + "(531,'Curaçao'),(196,'Cyprus'),(203,'Czechia'),(200,'Czechoslovakia')," + + "(408,'Democratic People\\'s Republic of Korea'),(180,'Democratic Republic of the Congo')," + + "(720,'Democratic Yemen'),(208,'Denmark'),(262,'Djibouti'),(212,'Dominica'),(214,'Dominican Republic')," + + "(216,'Dronning Maud Land'),(218,'Ecuador'),(818,'Egypt'),(222,'El Salvador'),(226,'Equatorial Guinea')," + + "(232,'Eritrea'),(233,'Estonia'),(230,'Ethiopia'),(231,'Ethiopia'),(238,'Falkland Islands (Malvinas)')," + + "(234,'Faroe Islands'),(280,'Federal Republic of Germany'),(583,'Federated States of Micronesia')," + + "(242,'Fiji'),(246,'Finland'),(250,'France'),(249,'France, Metropolitan'),(254,'French Guiana')," + + "(258,'French Polynesia'),(260,'French Southern Territories'),(266,'Gabon'),(270,'Gambia')," + + "(274,'Gaza Strip (Palestine)'),(268,'Georgia'),(278,'German Democratic Republic'),(276,'Germany')," + + "(288,'Ghana'),(292,'Gibraltar'),(300,'Greece'),(304,'Greenland'),(308,'Grenada'),(312,'Guadeloupe')," + + "(316,'Guam'),(320,'Guatemala'),(831,'Guernsey'),(324,'Guinea'),(624,'Guinea-Bissau'),(328,'Guyana')," + + "(332,'Haiti'),(334,'Heard Island and McDonald Islands'),(336,'Holy See'),(340,'Honduras')," + + "(344,'Hong Kong'),(348,'Hungary'),(352,'Iceland'),(356,'India'),(360,'Indonesia'),(368,'Iraq')," + + "(372,'Ireland'),(364,'Islamic Republic of Iran'),(833,'Isle of Man'),(376,'Israel'),(380,'Italy')," + + "(388,'Jamaica'),(392,'Japan'),(832,'Jersey'),(396,'Johnston Island'),(400,'Jordan'),(398,'Kazakhstan')," + + "(404,'Kenya'),(296,'Kiribati'),(414,'Kuwait'),(417,'Kyrgyzstan'),(418,'Lao People\\'s Democratic Republic')," + + "(428,'Latvia'),(422,'Lebanon'),(426,'Lesotho'),(430,'Liberia'),(434,'Libya'),(438,'Liechtenstein')," + + "(440,'Lithuania'),(442,'Luxembourg'),(446,'Macao'),(450,'Madagascar'),(454,'Malawi'),(458,'Malaysia')," + + "(462,'Maldives'),(466,'Mali'),(470,'Malta'),(584,'Marshall Islands'),(474,'Martinique'),(478,'Mauritania')," + + "(480,'Mauritius'),(175,'Mayotte'),(484,'Mexico'),(488,'Midway Islands'),(492,'Monaco'),(496,'Mongolia')," + + "(499,'Montenegro'),(500,'Montserrat'),(504,'Morocco'),(508,'Mozambique'),(104,'Myanmar'),(516,'Namibia')," + + "(520,'Nauru'),(524,'Nepal'),(528,'Netherlands'),(530,'Netherlands Antilles'),(532,'Netherlands Antilles')," + + "(536,'Neutral Zone'),(540,'New Caledonia'),(554,'New Zealand'),(558,'Nicaragua'),(562,'Niger')," + + "(566,'Nigeria'),(570,'Niue'),(574,'Norfolk Island'),(580,'Northern Mariana Islands'),(578,'Norway')," + + "(512,'Oman'),(586,'Pakistan'),(585,'Palau'),(590,'Panama'),(591,'Panama'),(594,'Panama Canal Zone')," + + "(598,'Papua New Guinea'),(600,'Paraguay'),(604,'Peru'),(608,'Philippines'),(612,'Pitcairn')," + + "(068,'Plurinational State of Bolivia'),(616,'Poland'),(620,'Portugal'),(630,'Puerto Rico'),(634,'Qatar')," + + "(410,'Republic of Korea'),(498,'Republic of Moldova'),(714,'Republic of Viet-Nam'),(638,'Réunion')," + + "(642,'Romania'),(643,'Russian Federation'),(646,'Rwanda'),(650,'Ryukyu Islands'),(652,'Saint Barthélemy')," + + "(654,'Saint Helena, Ascension and Tristan da Cunha'),(659,'Saint Kitts and Nevis')," + + "(658,'Saint Kitts-Nevis-Anguilla'),(662,'Saint Lucia'),(663,'Saint Martin')," + + "(666,'Saint Pierre and Miquelon'),(670,'Saint Vincent and the Grenadines'),(882,'Samoa')," + + "(674,'San Marino'),(678,'Sao Tome and Principe'),(682,'Saudi Arabia'),(686,'Senegal'),(688,'Serbia')," + + "(891,'Serbia and Montenegro'),(690,'Seychelles'),(694,'Sierra Leone'),(698,'Sikkim'),(702,'Singapore')," + + "(534,'Sint Marteen'),(703,'Slovakia'),(705,'Slovenia'),(890,'Socialist Federal Republic of Yugoslavia')," + + "(090,'Solomon Islands'),(706,'Somalia'),(710,'South Africa')," + + "(239,'South Georgia and the South Sandwich Islands'),(728,'South Sudan'),(724,'Spain'),(144,'Sri Lanka')," + + "(275,'State of Palestine'),(729,'Sudan'),(736,'Sudan'),(740,'Suriname'),(744,'Svalbard and Jan Mayen')," + + "(748,'Swaziland'),(752,'Sweden'),(756,'Switzerland'),(760,'Syrian Arab Republic')," + + "(158,'Taiwan, Province of China'),(762,'Tajikistan'),(764,'Thailand')," + + "(807,'The former Yugoslav Republic of Macedonia'),(626,'Timor-Leste'),(768,'Togo'),(772,'Tokelau')," + + "(776,'Tonga'),(780,'Trinidad and Tobago'),(582,'Trust Territory of the Pacific Islands'),(788,'Tunisia')," + + "(792,'Turkey'),(795,'Turkmenistan'),(796,'Turks and Caicos Islands'),(798,'Tuvalu')," + + "(849,'U.S. Miscellaneous Pacific Islands'),(800,'Uganda'),(804,'Ukraine'),(784,'United Arab Emirates')," + + "(826,'United Kingdom'),(834,'United Republic of Tanzania'),(581,'United States Minor Outlying Islands')," + + "(840,'United States of America'),(858,'Uruguay'),(810,'USSR'),(860,'Uzbekistan'),(548,'Vanuatu')," + + "(704,'Viet-Nam'),(850,'Virgin Islands, U.S.'),(872,'Wake Island'),(876,'Wallis and Futuna')," + + "(732,'Western Sahara'),(887,'Yemen'),(886,'Yemen Arab Republic'),(894,'Zambia'),(716,'Zimbabwe');"; + + public static readonly string CompaniesForeignKeys = + "ALTER TABLE `companies` ADD FOREIGN KEY `fk_companies_sold_to` (sold_to) REFERENCES `companies` (`id`);\n" + + "ALTER TABLE `companies` ADD FOREIGN KEY `fk_companies_country` (country) REFERENCES `iso3166_1_numeric` (`id`);"; + } +} \ No newline at end of file diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index 761c1f07..6b7c65eb 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.0 - 3.0.99.114 + 3.0.99.118 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website