Update DB to version 19: Resolutions are gpu dependant,

move to separate table and use an interconnection table, `resolution_by_gpu`.
This commit is contained in:
2018-04-28 18:39:09 +01:00
parent 95de473054
commit 04c0e47d9c
13 changed files with 921 additions and 119 deletions

View File

@@ -32,7 +32,6 @@ using System;
using System.Collections.Generic;
using System.Data;
using Cicm.Database.Schemas;
using Console = System.Console;
namespace Cicm.Database
{
@@ -300,6 +299,14 @@ namespace Cicm.Database
param9.Value = entry.Transistors;
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);
return dbcmd;
}

View File

@@ -49,115 +49,123 @@ namespace Cicm.Database
IDbCommand dbCmd = dbCon.CreateCommand();
Console.WriteLine("Creating table `admins`");
dbCmd.CommandText = V18.Admins;
dbCmd.CommandText = V19.Admins;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `browser_tests`");
dbCmd.CommandText = V18.BrowserTests;
dbCmd.CommandText = V19.BrowserTests;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `cicm_db`");
dbCmd.CommandText = V18.CicmDb;
dbCmd.CommandText = V19.CicmDb;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `companies`");
dbCmd.CommandText = V18.Companies;
dbCmd.CommandText = V19.Companies;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `machines`");
dbCmd.CommandText = V18.Machines;
dbCmd.CommandText = V19.Machines;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `disk_formats`");
dbCmd.CommandText = V18.DiskFormats;
dbCmd.CommandText = V19.DiskFormats;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `forbidden`");
dbCmd.CommandText = V18.Forbidden;
dbCmd.CommandText = V19.Forbidden;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `gpus`");
dbCmd.CommandText = V18.Gpus;
dbCmd.CommandText = V19.Gpus;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `log`");
dbCmd.CommandText = V18.Logs;
dbCmd.CommandText = V19.Logs;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `money_donations`");
dbCmd.CommandText = V18.MoneyDonations;
dbCmd.CommandText = V19.MoneyDonations;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `news`");
dbCmd.CommandText = V18.News;
dbCmd.CommandText = V19.News;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `owned_computers`");
dbCmd.CommandText = V18.OwnedComputers;
dbCmd.CommandText = V19.OwnedComputers;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `owned_consoles`");
dbCmd.CommandText = V18.OwnedConsoles;
dbCmd.CommandText = V19.OwnedConsoles;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_sets`");
dbCmd.CommandText = V18.InstructionSets;
dbCmd.CommandText = V19.InstructionSets;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_set_extensions`");
dbCmd.CommandText = V18.InstructionSetExtensions;
dbCmd.CommandText = V19.InstructionSetExtensions;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `processors`");
dbCmd.CommandText = V18.Processors;
dbCmd.CommandText = V19.Processors;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_set_extensions_by_processor`");
dbCmd.CommandText = V18.InstructionSetExtensionsByProcessor;
dbCmd.CommandText = V19.InstructionSetExtensionsByProcessor;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `sound_synths`");
dbCmd.CommandText = V18.SoundSynths;
dbCmd.CommandText = V19.SoundSynths;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `iso3166_1_numeric`");
dbCmd.CommandText = V18.Iso3166Numeric;
dbCmd.CommandText = V19.Iso3166Numeric;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Filling table `iso3166_1_numeric`");
dbCmd.CommandText = V18.Iso3166NumericValues;
dbCmd.CommandText = V19.Iso3166NumericValues;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating foreign keys for table `companies`");
dbCmd.CommandText = V18.CompaniesForeignKeys;
dbCmd.CommandText = V19.CompaniesForeignKeys;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating foreign keys for table `machines`");
dbCmd.CommandText = V18.MachinesForeignKeys;
dbCmd.CommandText = V19.MachinesForeignKeys;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `company_logos`");
dbCmd.CommandText = V18.CompanyLogos;
dbCmd.CommandText = V19.CompanyLogos;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `company_descriptions`");
dbCmd.CommandText = V18.CompanyDescriptions;
dbCmd.CommandText = V19.CompanyDescriptions;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `processors_by_machine`");
dbCmd.CommandText = V18.ProcessorsByMachine;
dbCmd.CommandText = V19.ProcessorsByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `gpus_by_machine`");
dbCmd.CommandText = V18.GpusByMachine;
dbCmd.CommandText = V19.GpusByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `sound_by_machine`");
dbCmd.CommandText = V18.SoundByMachine;
dbCmd.CommandText = V19.SoundByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `memory_by_machine`");
dbCmd.CommandText = V18.MemoryByMachine;
dbCmd.CommandText = V19.MemoryByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `resolutions`");
dbCmd.CommandText = V19.Resolutions;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `resolutions_by_gpu`");
dbCmd.CommandText = V19.ResolutionsByGpu;
dbCmd.ExecuteNonQuery();
return true;

View File

@@ -215,7 +215,7 @@ namespace Cicm.Database
const string SQL =
"INSERT INTO machines (company, year, model, colors, res, hdd1, hdd2, hdd3, disk1, cap1, disk2, cap2, " +
"type) VALUES (@company, @year, @model, @colors, @res, @hdd1, @hdd2, @hdd3, @disk1, @cap1, @disk2, " +
"type) VALUES (@company, @year, @model, @colors, @res, @hdd1, @hdd2, @hdd3, @disk1, @cap1, @disk2, " +
"@cap2, @type)";
dbcmd.CommandText = SQL;
@@ -299,55 +299,47 @@ namespace Cicm.Database
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 param7 = dbcmd.CreateParameter();
IDbDataParameter param8 = dbcmd.CreateParameter();
IDbDataParameter param9 = dbcmd.CreateParameter();
IDbDataParameter param10 = dbcmd.CreateParameter();
IDbDataParameter param11 = dbcmd.CreateParameter();
IDbDataParameter param12 = dbcmd.CreateParameter();
IDbDataParameter param13 = dbcmd.CreateParameter();
param1.ParameterName = "@company";
param2.ParameterName = "@year";
param3.ParameterName = "@model";
param4.ParameterName = "@colors";
param5.ParameterName = "@res";
param6.ParameterName = "@hdd1";
param7.ParameterName = "@hdd2";
param8.ParameterName = "@hdd3";
param9.ParameterName = "@disk1";
param10.ParameterName = "@cap1";
param11.ParameterName = "@disk2";
param12.ParameterName = "@cap2";
param13.ParameterName = "@type";
param4.ParameterName = "@hdd1";
param5.ParameterName = "@hdd2";
param6.ParameterName = "@hdd3";
param7.ParameterName = "@disk1";
param8.ParameterName = "@cap1";
param9.ParameterName = "@disk2";
param10.ParameterName = "@cap2";
param11.ParameterName = "@type";
param1.DbType = DbType.Int32;
param2.DbType = DbType.Int32;
param3.DbType = DbType.String;
param4.DbType = DbType.Int32;
param5.DbType = DbType.String;
param5.DbType = DbType.Int32;
param6.DbType = DbType.Int32;
param7.DbType = DbType.Int32;
param8.DbType = DbType.Int32;
param9.DbType = DbType.Int32;
param7.DbType = DbType.Int32;
param8.DbType = DbType.String;
param9.DbType = DbType.Int32;
param10.DbType = DbType.String;
param11.DbType = DbType.Int32;
param12.DbType = DbType.String;
param13.DbType = DbType.Int32;
param1.Value = entry.Company;
param2.Value = entry.Year;
param3.Value = entry.Model;
param4.Value = entry.Colors;
param5.Value = entry.Resolution;
param6.Value = entry.Hdd1;
param7.Value = entry.Hdd2;
param8.Value = entry.Hdd3;
param9.Value = entry.Disk1;
param10.Value = entry.Cap1;
param11.Value = entry.Disk2;
param12.Value = entry.Cap2;
param13.Value = entry.Type;
param4.Value = entry.Hdd1;
param5.Value = entry.Hdd2;
param6.Value = entry.Hdd3;
param7.Value = entry.Disk1;
param8.Value = entry.Cap1;
param9.Value = entry.Disk2;
param10.Value = entry.Cap2;
param11.Value = entry.Type;
dbcmd.Parameters.Add(param1);
dbcmd.Parameters.Add(param2);
@@ -360,8 +352,6 @@ namespace Cicm.Database
dbcmd.Parameters.Add(param9);
dbcmd.Parameters.Add(param10);
dbcmd.Parameters.Add(param11);
dbcmd.Parameters.Add(param12);
dbcmd.Parameters.Add(param13);
return dbcmd;
}
@@ -374,20 +364,18 @@ namespace Cicm.Database
{
Machine entry = new Machine
{
Id = (int)dataRow["id"],
Company = (int)dataRow["company"],
Year = (int)dataRow["year"],
Model = (string)dataRow["model"],
Colors = (int)dataRow["colors"],
Resolution = (string)dataRow["res"],
Hdd1 = (int)dataRow["hdd1"],
Hdd2 = dataRow["hdd2"] == DBNull.Value ? 0 : (int)dataRow["hdd2"],
Hdd3 = dataRow["hdd3"] == DBNull.Value ? 0 : (int)dataRow["hdd3"],
Disk1 = (int)dataRow["disk1"],
Cap1 = (string)dataRow["cap1"],
Disk2 = dataRow["disk2"] == DBNull.Value ? 0 : (int)dataRow["disk2"],
Cap2 = dataRow["cap2"] == DBNull.Value ? null : (string)dataRow["cap2"],
Type = (MachineType)dataRow["type"]
Id = (int)dataRow["id"],
Company = (int)dataRow["company"],
Year = (int)dataRow["year"],
Model = (string)dataRow["model"],
Hdd1 = (int)dataRow["hdd1"],
Hdd2 = dataRow["hdd2"] == DBNull.Value ? 0 : (int)dataRow["hdd2"],
Hdd3 = dataRow["hdd3"] == DBNull.Value ? 0 : (int)dataRow["hdd3"],
Disk1 = (int)dataRow["disk1"],
Cap1 = (string)dataRow["cap1"],
Disk2 = dataRow["disk2"] == DBNull.Value ? 0 : (int)dataRow["disk2"],
Cap2 = dataRow["cap2"] == DBNull.Value ? null : (string)dataRow["cap2"],
Type = (MachineType)dataRow["type"]
};
entries.Add(entry);

View File

@@ -35,7 +35,7 @@ namespace Cicm.Database
public partial class Operations
{
/// <summary>Last known database version</summary>
const int DB_VERSION = 18;
const int DB_VERSION = 19;
/// <summary>The column with this value indicates there is no item of this type.</summary>
public const int DB_NONE = -1;
/// <summary>

View File

@@ -0,0 +1,418 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Resolution.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Contains operations to manage Resolutions.
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using Cicm.Database.Schemas;
namespace Cicm.Database
{
public partial class Operations
{
/// <summary>
/// Gets all Resolutions
/// </summary>
/// <param name="entries">All Resolutions</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetResolutions(out List<Resolution> entries)
{
#if DEBUG
Console.WriteLine("Getting all Resolutions...");
#endif
try
{
const string SQL = "SELECT * from resolutions";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = SQL;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = ResolutionsFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting Resolutions.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets the specified number of Resolutions since the specified start
/// </summary>
/// <param name="entries">List of Resolutions</param>
/// <param name="start">Start of query</param>
/// <param name="count">How many entries to retrieve</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetResolutions(out List<Resolution> entries, ulong start, ulong count)
{
#if DEBUG
Console.WriteLine("Getting {0} Resolutions from {1}...", count, start);
#endif
try
{
string sql = $"SELECT * FROM resolutions 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 = ResolutionsFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting Resolutions.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets Resolution by specified id
/// </summary>
/// <param name="id">Id</param>
/// <returns>Resolution with specified id, <c>null</c> if not found or error</returns>
public Resolution GetResolution(int id)
{
#if DEBUG
Console.WriteLine("Getting Resolution with id {0}...", id);
#endif
try
{
string sql = $"SELECT * from resolutions 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<Resolution> entries = ResolutionsFromDataTable(dataSet.Tables[0]);
return entries == null || entries.Count == 0 ? null : entries[0];
}
catch(Exception ex)
{
Console.WriteLine("Error getting Resolution.");
Console.WriteLine(ex);
return null;
}
}
/// <summary>
/// Gets Resolution by specified id
/// </summary>
/// <param name="id">Id</param>
/// <returns>Resolution with specified id, <c>null</c> if not found or error</returns>
public Resolution GetResolution(int width, int height)
{
#if DEBUG
Console.WriteLine("Getting first resolution of {0}x{1}...", width, height);
#endif
try
{
string sql = $"SELECT * from resolutions WHERE width = {width} AND height = {height}";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
List<Resolution> entries = ResolutionsFromDataTable(dataSet.Tables[0]);
return entries == null || entries.Count == 0 ? null : entries[0];
}
catch(Exception ex)
{
Console.WriteLine("Error getting Resolution.");
Console.WriteLine(ex);
return null;
}
}
/// <summary>
/// Gets Resolution by specified id
/// </summary>
/// <param name="id">Id</param>
/// <returns>Resolution with specified id, <c>null</c> if not found or error</returns>
public Resolution GetResolution(int width, int height, long colors)
{
#if DEBUG
Console.WriteLine("Getting first resolution of {0}x{1} with {2} colors...", width, height, colors);
#endif
try
{
string sql =
$"SELECT * from resolutions WHERE width = {width} AND height = {height} AND colors = {colors}";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
List<Resolution> entries = ResolutionsFromDataTable(dataSet.Tables[0]);
return entries == null || entries.Count == 0 ? null : entries[0];
}
catch(Exception ex)
{
Console.WriteLine("Error getting Resolution.");
Console.WriteLine(ex);
return null;
}
}
/// <summary>
/// Gets Resolution by specified id
/// </summary>
/// <param name="id">Id</param>
/// <returns>Resolution with specified id, <c>null</c> if not found or error</returns>
public Resolution GetResolution(int width, int height, long colors, long palette)
{
#if DEBUG
Console.WriteLine("Getting first resolution of {0}x{1} with {2} colors from a palette of {3} colors...",
width, height, colors, palette);
#endif
try
{
string sql =
$"SELECT * from resolutions WHERE width = {width} AND height = {height} AND colors = {colors} AND palette = {palette}";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
List<Resolution> entries = ResolutionsFromDataTable(dataSet.Tables[0]);
return entries == null || entries.Count == 0 ? null : entries[0];
}
catch(Exception ex)
{
Console.WriteLine("Error getting Resolution.");
Console.WriteLine(ex);
return null;
}
}
/// <summary>
/// Counts the number of Resolutions in the database
/// </summary>
/// <returns>Entries in database</returns>
public long CountResolutions()
{
#if DEBUG
Console.WriteLine("Counting resolutions...");
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
dbcmd.CommandText = "SELECT COUNT(*) FROM resolutions";
object count = dbcmd.ExecuteScalar();
dbcmd.Dispose();
try { return Convert.ToInt64(count); }
catch { return 0; }
}
/// <summary>
/// Adds a new Resolution to the database
/// </summary>
/// <param name="entry">Entry to add</param>
/// <param name="id">ID of added entry</param>
/// <returns><c>true</c> if added correctly, <c>false</c> otherwise</returns>
public bool AddResolution(Resolution entry, out long id)
{
#if DEBUG
Console.Write("Adding Resolution...");
#endif
IDbCommand dbcmd = GetCommandResolution(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
const string SQL =
"INSERT INTO resolutions (width, height, colors, palette, chars) VALUES (@width, @height, @colors, " +
"@palette, @chars)";
dbcmd.CommandText = SQL;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
id = dbCore.LastInsertRowId;
#if DEBUG
Console.WriteLine(" id {0}", id);
#endif
return true;
}
/// <summary>
/// Updated a Resolution in the database
/// </summary>
/// <param name="entry">Updated entry</param>
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
public bool UpdateResolution(Resolution entry)
{
#if DEBUG
Console.WriteLine("Updating Resolution `{0}`...", entry.Id);
#endif
IDbCommand dbcmd = GetCommandResolution(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql =
"UPDATE resolutions SET width = @width, height = @height, colors = @colors, palette = @palette, " +
"chars = @chars " +
$"WHERE id = {entry.Id}";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
/// <summary>
/// Removes a Resolution from the database
/// </summary>
/// <param name="id">ID of entry to remove</param>
/// <returns><c>true</c> if removed correctly, <c>false</c> otherwise</returns>
public bool RemoveResolution(long id)
{
#if DEBUG
Console.WriteLine("Removing Resolution widh id `{0}`...", id);
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql = $"DELETE FROM resolutions WHERE id = '{id}';";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
IDbCommand GetCommandResolution(Resolution entry)
{
IDbCommand dbcmd = dbCon.CreateCommand();
IDbDataParameter param1 = dbcmd.CreateParameter();
IDbDataParameter param2 = dbcmd.CreateParameter();
IDbDataParameter param3 = dbcmd.CreateParameter();
IDbDataParameter param4 = dbcmd.CreateParameter();
IDbDataParameter param5 = dbcmd.CreateParameter();
param1.ParameterName = "@width";
param2.ParameterName = "@height";
param3.ParameterName = "@colors";
param4.ParameterName = "@palette";
param5.ParameterName = "@chars";
param1.DbType = DbType.Int32;
param2.DbType = DbType.Int32;
param3.DbType = DbType.Int64;
param4.DbType = DbType.Int64;
param5.DbType = DbType.Boolean;
param1.Value = entry.Width;
param2.Value = entry.Height;
param3.Value = entry.Colors == 0 ? (object)null : entry.Colors;
param4.Value = entry.Palette == 0 ? (object)null : entry.Palette;
param5.Value = entry.Chars;
dbcmd.Parameters.Add(param1);
dbcmd.Parameters.Add(param2);
dbcmd.Parameters.Add(param3);
dbcmd.Parameters.Add(param4);
dbcmd.Parameters.Add(param5);
return dbcmd;
}
static List<Resolution> ResolutionsFromDataTable(DataTable dataTable)
{
List<Resolution> entries = new List<Resolution>();
foreach(DataRow dataRow in dataTable.Rows)
{
Resolution entry = new Resolution
{
Id = (int)dataRow["id"],
Width = (int)dataRow["width"],
Height = (int)dataRow["height"],
Colors = dataRow["colors"] == DBNull.Value ? 0 : (long)dataRow["colors"],
Palette = dataRow["palette"] == DBNull.Value ? 0 : (long)dataRow["palette"],
Chars = (bool)dataRow["chars"]
};
entries.Add(entry);
}
return entries;
}
}
}

View File

@@ -0,0 +1,80 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Resolution.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Contains operations to manage Resolutions.
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using Cicm.Database.Schemas;
namespace Cicm.Database
{
public partial class Operations
{
/// <summary>
/// Gets all Resolutions
/// </summary>
/// <param name="entries">All Resolutions</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetResolutions(out List<Resolution> entries, int gpuId)
{
#if DEBUG
Console.WriteLine("Getting all resolutions for GPU {0}...", gpuId);
#endif
try
{
string sql = $"SELECT * FROM resolutions_by_gpu WHERE gpu = {gpuId}";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = new List<Resolution>();
foreach(DataRow dataRow in dataSet.Tables[0].Rows)
entries.Add(GetResolution((int)dataRow["resolution"]));
if(entries.Count != 0) return true;
entries = null;
return false;
}
catch(Exception ex)
{
Console.WriteLine("Error getting Resolutions.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
}
}

View File

@@ -159,6 +159,11 @@ namespace Cicm.Database
UpdateDatabaseToV18();
break;
}
case 18:
{
UpdateDatabaseToV19();
break;
}
}
OptimizeDatabase();
@@ -2026,6 +2031,147 @@ namespace Cicm.Database
dbCmd.Dispose();
}
void UpdateDatabaseToV19()
{
Console.WriteLine("Updating database to version 19");
Console.WriteLine("Creating table `resolutions`");
IDbCommand dbCmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = V19.Resolutions;
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Creating table `resolutions_by_gpu`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = V19.ResolutionsByGpu;
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Getting all items from `machines`");
dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = "SELECT * from machines";
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
foreach(DataRow dataRow in dataSet.Tables[0].Rows)
{
if(dataRow["colors"] == DBNull.Value || dataRow["res"] == DBNull.Value ||
(int)dataRow["colors"] == 0 ||
(string)dataRow["res"] == "???") continue;
dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter2 = dbCore.GetNewDataAdapter();
dbCmd.CommandText = $"SELECT * FROM gpus_by_machine WHERE machine = {(int)dataRow["id"]}";
DataSet dataSet2 = new DataSet();
dataAdapter2.SelectCommand = dbCmd;
dataAdapter2.Fill(dataSet2);
if(dataSet2.Tables[0].Rows.Count == 0) continue;
int gpuId = (int)dataSet2.Tables[0].Rows[0]["gpu"];
string[] resPieces = ((string)dataRow["res"]).Split('x');
if(!int.TryParse(resPieces[0], out int width)) continue;
if(!int.TryParse(resPieces[1], out int height)) continue;
dbCmd = dbCon.CreateCommand();
dataAdapter2 = dbCore.GetNewDataAdapter();
dbCmd.CommandText =
$"SELECT * FROM resolutions WHERE width = {width} AND height = {height} AND colors = {(int)dataRow["colors"]}";
dataSet2 = new DataSet();
dataAdapter2.SelectCommand = dbCmd;
dataAdapter2.Fill(dataSet2);
int resId;
string sql;
IDbCommand dbcmd = dbCon.CreateCommand();
IDbDataParameter param1 = dbcmd.CreateParameter();
IDbDataParameter param2 = dbcmd.CreateParameter();
IDbDataParameter param3 = dbcmd.CreateParameter();
if(dataSet2.Tables[0].Rows.Count == 0)
{
param1.ParameterName = "@width";
param2.ParameterName = "@height";
param3.ParameterName = "@colors";
param1.DbType = DbType.Int32;
param2.DbType = DbType.Int32;
param3.DbType = DbType.Int64;
param1.Value = width;
param2.Value = height;
param3.Value = (int)dataRow["colors"];
sql = "INSERT INTO `resolutions` (`width`, `height`, `colors`) VALUES (@width, @height, @colors)";
dbcmd.Parameters.Add(param1);
dbcmd.Parameters.Add(param2);
dbcmd.Parameters.Add(param3);
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
dbcmd.Dispose();
resId = (int)dbCore.LastInsertRowId;
}
else resId = (int)dataSet2.Tables[0].Rows[0]["id"];
dbcmd = dbCon.CreateCommand();
param1 = dbcmd.CreateParameter();
param2 = dbcmd.CreateParameter();
param1.ParameterName = "@gpu";
param2.ParameterName = "@resolution";
param1.DbType = DbType.Int32;
param2.DbType = DbType.Int32;
param1.Value = gpuId;
param2.Value = resId;
sql = "INSERT INTO `resolutions_by_gpu` (`gpu`, `resolution`) VALUES (@gpu, @resolution)";
dbcmd.Parameters.Add(param1);
dbcmd.Parameters.Add(param2);
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
dbcmd.Dispose();
}
Console.WriteLine("Removing resolution columns from table `machines`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = "ALTER TABLE `machines` DROP COLUMN `res`;\n" +
"ALTER TABLE `machines` DROP COLUMN `colors`;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Setting new database version to 19...");
dbCmd = dbCon.CreateCommand();
dbCmd.CommandText = "INSERT INTO cicm_db (version) VALUES ('19')";
dbCmd.ExecuteNonQuery();
dbCmd.Dispose();
}
void OptimizeDatabase()
{
IDbCommand dbCmd = dbCon.CreateCommand();

View File

@@ -37,8 +37,6 @@ namespace Cicm.Database.Schemas
public string Cap1;
/// <summary>Capacity of second removable disk format</summary>
public string Cap2;
/// <summary>Maximum colors on screen</summary>
public int Colors;
/// <summary>Manufacturer's company ID</summary>
public int Company;
/// <summary>ID of first removable disk format</summary>
@@ -55,8 +53,6 @@ namespace Cicm.Database.Schemas
public int Id;
/// <summary>Model name</summary>
public string Model;
/// <summary>Resolution in WxH pixels</summary>
public string Resolution;
/// <summary>Machine type</summary>
public MachineType Type;
/// <summary>Introduction date, 0 if unknown, 1000 if prototype</summary>

View File

@@ -0,0 +1,49 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Processor.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// High level representation of a processor .
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
namespace Cicm.Database.Schemas
{
/// <summary>Processor</summary>
public class Resolution
{
/// <summary>If <c>true</c> width and height indicate characters, else they indicate pixels</summary>
public bool Chars;
/// <summary>Colors</summary>
public long Colors;
/// <summary>Height</summary>
public int Height;
/// <summary>Resolution ID</summary>
public int Id;
/// <summary>Palette, 0 if same as <see cref="Colors" /></summary>
public long Palette;
/// <summary>Width</summary>
public int Width;
}
}

View File

@@ -0,0 +1,145 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : V19.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Contains SQL queries to create the database version 7.
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
namespace Cicm.Database.Schemas.Sql
{
public static class V19
{
public static readonly string Admins = V18.Admins;
public static readonly string BrowserTests = V18.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" +
"INSERT INTO cicm_db (version) VALUES ('19');";
public static readonly string Companies = V18.Companies;
public static readonly string Machines = "CREATE TABLE `machines` (;\n" +
"`id` int(11) NOT NULL AUTO_INCREMENT,;\n" +
"`company` int(11) NOT NULL DEFAULT '0',;\n" +
"`year` int(11) NOT NULL DEFAULT '0',;\n" +
"`model` char(50) NOT NULL DEFAULT '',;\n" +
"`hdd1` int(11) NOT NULL DEFAULT '0',;\n" +
"`hdd2` int(11) DEFAULT NULL,;\n" +
"`hdd3` int(11) DEFAULT NULL,;\n" +
"`disk1` int(11) NOT NULL DEFAULT '0',;\n" +
"`cap1` char(25) NOT NULL DEFAULT '0',;\n" +
"`disk2` int(11) DEFAULT NULL,;\n" +
"`cap2` char(25) DEFAULT NULL,;\n" +
"`type` int(11) NOT NULL DEFAULT '0',;\n" +
"PRIMARY KEY (`id`),;\n" +
"KEY `idx_machines_company` (`company`),;\n" +
"KEY `idx_machines_year` (`year`),;\n" +
"KEY `idx_machines_model` (`model`),;\n" +
"KEY `idx_machines_hdd1` (`hdd1`),;\n" +
"KEY `idx_machines_hdd2` (`hdd2`),;\n" +
"KEY `idx_machines_hdd3` (`hdd3`),;\n" +
"KEY `idx_machines_disk1` (`disk1`),;\n" +
"KEY `idx_machines_disk2` (`disk2`),;\n" +
"KEY `idx_machines_cap1` (`cap1`),;\n" +
"KEY `idx_machines_cap2` (`cap2`),;\n" +
"KEY `idx_machines_type` (`type`));";
public static readonly string DiskFormats = V18.DiskFormats;
public static readonly string Forbidden = V18.Forbidden;
public static readonly string Gpus = V18.Gpus;
public static readonly string Logs = V18.Logs;
public static readonly string MoneyDonations = V18.MoneyDonations;
public static readonly string News = V18.News;
public static readonly string OwnedComputers = V18.OwnedComputers;
public static readonly string OwnedConsoles = V18.OwnedConsoles;
public static readonly string Processors = V18.Processors;
public static readonly string SoundSynths = V18.SoundSynths;
public static readonly string MachinesForeignKeys = V18.MachinesForeignKeys;
public static readonly string Iso3166Numeric = V18.Iso3166Numeric;
public static readonly string Iso3166NumericValues = V18.Iso3166NumericValues;
public static readonly string CompaniesForeignKeys = V18.CompaniesForeignKeys;
public static readonly string CompanyLogos = V18.CompanyLogos;
public static readonly string CompanyDescriptions = V18.CompanyDescriptions;
public static readonly string InstructionSets = V18.InstructionSets;
public static readonly string InstructionSetExtensions = V18.InstructionSetExtensions;
public static readonly string InstructionSetExtensionsByProcessor = V18.InstructionSetExtensionsByProcessor;
public static readonly string ProcessorsByMachine = V18.ProcessorsByMachine;
public static readonly string GpusByMachine = V18.GpusByMachine;
public static readonly string SoundByMachine = V18.SoundByMachine;
public static readonly string MemoryByMachine = V18.MemoryByMachine;
public static readonly string Resolutions =
"CREATE TABLE `resolutions` (\n" +
"`id` INT NOT NULL AUTO_INCREMENT,\n" +
"`width` INT NOT NULL DEFAULT 0,\n" +
"`height` INT NOT NULL DEFAULT 0,\n" +
"`colors` BIGINT DEFAULT NULL,\n" +
"`palette` BIGINT DEFAULT NULL,\n" +
"`chars` BOOL NOT NULL DEFAULT 0,\n" + "PRIMARY KEY (`id`),\n" +
"KEY `idx_resolutions_width` (`width`),\n" +
"KEY `idx_resolutions_height` (`height`),\n" +
"KEY `idx_resolutions_colors` (`colors`),\n" +
"KEY `idx_resolutions_palette` (`palette`),\n" +
"INDEX `idx_resolutions_resolution` (`width`,`height`),\n" +
"INDEX `idx_resolutions_resolution_with_color` (`width`,`height`,`colors`),\n" +
"INDEX `idx_resolutions_resolution_with_color_and_palette` (`width`,`height`,`colors`,`palette`));";
public static readonly string ResolutionsByGpu =
"CREATE TABLE `resolutions_by_gpu` (\n" +
"`gpu` INT NOT NULL,\n" +
"`resolution` INT NOT NULL,\n" +
"KEY `idx_resolutions_by_gpu_gpu` (`gpu`),\n" +
"KEY `idx_resolutions_by_gpu_resolution` (`resolution`),\n" +
"CONSTRAINT `fk_resolutions_by_gpu_gpu` FOREIGN KEY (`gpu`) REFERENCES `gpus` (`id`) ON UPDATE CASCADE ON DELETE CASCADE,\n" +
"CONSTRAINT `fk_resolutions_by_gpu_resolution` FOREIGN KEY (`resolution`) REFERENCES `resolutions` (`id`) ON UPDATE CASCADE ON DELETE CASCADE);";
}
}

View File

@@ -39,7 +39,6 @@ namespace cicm_web.Models
{
public string Cap1;
public string Cap2;
public int Colors;
public Company Company;
public DiskFormat Disk1;
public DiskFormat Disk2;
@@ -51,7 +50,6 @@ namespace cicm_web.Models
public MemoryByMachine[] Memories;
public string Model;
public ProcessorByMachine[] Processors;
public string Resolution;
public SoundByMachine[] SoundSynths;
public MachineType Type;
public int Year;
@@ -87,7 +85,6 @@ namespace cicm_web.Models
{
Machine item = new Machine
{
Colors = dbItem.Colors,
Company = Company.GetItem(dbItem.Company),
Gpus = GpuByMachine.GetAllItems(dbItem.Id),
Hdd1 = DiskFormat.GetItem(dbItem.Hdd1),
@@ -95,7 +92,6 @@ namespace cicm_web.Models
Hdd3 = DiskFormat.GetItem(dbItem.Hdd3),
Id = dbItem.Id,
Model = dbItem.Model,
Resolution = dbItem.Resolution,
Year = dbItem.Year,
Type = dbItem.Type,
Processors = ProcessorByMachine.GetAllItems(dbItem.Id),

View File

@@ -28,7 +28,7 @@
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
// TODO: Resolutions
ViewData["Title"] = "Computer";
}
@using System.IO
@@ -489,37 +489,6 @@
</td>
</tr>
}
<tr>
<th scope=row>
<div align=right>
Video resolution
</div>
</th>
@if(Model.Resolution != "???")
{
<td>@Model.Resolution</td>
}
else
{
<td>Unknown data</td>
}
</tr>
<tr>
<th scope=row>
<div align=right>
Colors
</div>
</th>
@if(Model.Colors > 0)
{
<td>@Model.Colors</td>
}
else
{
<td>Unknown data</td>
}
</tr>
@if(Model.SoundSynths != null && Model.SoundSynths.Length > 0)
{
<tr>

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<Version>3.0.99.215</Version>
<Version>3.0.99.220</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>