mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Update DB to version 14: Computers and consoles are now machines with different type.
This commit is contained in:
@@ -32,7 +32,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using Cicm.Database.Schemas;
|
||||
using Console = System.Console;
|
||||
|
||||
namespace Cicm.Database
|
||||
{
|
||||
@@ -43,7 +42,7 @@ namespace Cicm.Database
|
||||
/// </summary>
|
||||
/// <param name="entries">All computers</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetComputers(out List<Computer> entries)
|
||||
public bool GetComputers(out List<Machine> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all computers...");
|
||||
@@ -51,16 +50,16 @@ namespace Cicm.Database
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from computers";
|
||||
string sql = $"SELECT * FROM machines WHERE type = '{(int)MachineType.Computer}'";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = ComputersFromDataTable(dataSet.Tables[0]);
|
||||
entries = MachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -79,7 +78,7 @@ namespace Cicm.Database
|
||||
/// <param name="entries">All computers</param>
|
||||
/// <param name="company">Company id</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetComputers(out List<Computer> entries, int company)
|
||||
public bool GetComputers(out List<Machine> entries, int company)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all computers from company id {0}...", company);
|
||||
@@ -87,16 +86,16 @@ namespace Cicm.Database
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from computers WHERE company = '{id}'";
|
||||
string sql = $"SELECT * FROM machines WHERE company = '{company}' AND type = '{(int)MachineType.Computer}'";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = ComputersFromDataTable(dataSet.Tables[0]);
|
||||
entries = MachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -116,7 +115,7 @@ namespace Cicm.Database
|
||||
/// <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 GetComputers(out List<Computer> entries, ulong start, ulong count)
|
||||
public bool GetComputers(out List<Machine> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} computers from {1}...", count, start);
|
||||
@@ -124,7 +123,7 @@ namespace Cicm.Database
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM computers LIMIT {start}, {count}";
|
||||
string sql = $"SELECT * FROM machines LIMIT {start}, {count} WHERE type = '{(int)MachineType.Computer}'";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
@@ -133,7 +132,7 @@ namespace Cicm.Database
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = ComputersFromDataTable(dataSet.Tables[0]);
|
||||
entries = MachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -151,33 +150,9 @@ namespace Cicm.Database
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Computer with specified id, <c>null</c> if not found or error</returns>
|
||||
public Computer GetComputer(int id)
|
||||
public Machine GetComputer(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting computer with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from computers 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<Computer> entries = ComputersFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting computer.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
return GetMachine(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -191,7 +166,7 @@ namespace Cicm.Database
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM computers";
|
||||
dbcmd.CommandText = $"SELECT COUNT(*) FROM computers WHERE type = '{(int)MachineType.Computer}'";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
@@ -204,33 +179,10 @@ namespace Cicm.Database
|
||||
/// <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 AddComputer(Computer entry, out long id)
|
||||
public bool AddComputer(Machine entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding computer `{0}`...", entry.Model);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandComputer(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL =
|
||||
"INSERT INTO computers (company, year, model, cpu1, mhz1, cpu2, mhz2, bits, ram, rom, gpu, vram, colors, res, sound_synth, music_synth, sound_channels, music_channels, hdd1, hdd2, hdd3, disk1, cap1, disk2, cap2)" +
|
||||
" VALUES (@company, @year, @model, @cpu1, @mhz1, @cpu2, @mhz2, @bits, @ram, @rom, @gpu, @vram, @colors, @res, @sound_synth, @music_synth, @sound_channels, @music_channels, @hdd1, @hdd2, @hdd3, @disk1, @cap1, @disk2, @cap2)";
|
||||
|
||||
dbcmd.CommandText = SQL;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
id = dbCore.LastInsertRowId;
|
||||
|
||||
#if DEBUG
|
||||
Console.WriteLine(" id {0}", id);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
entry.Type = MachineType.Computer;
|
||||
return AddMachine(entry, out id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -238,29 +190,9 @@ namespace Cicm.Database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateComputer(Computer entry)
|
||||
public bool UpdateComputer(Machine entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating computer `{0}`...", entry.Model);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandComputer(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql =
|
||||
"UPDATE computers SET company = @company, year = @year, model = @model, cpu1 = @cpu1, mhz1 = @mhz1, cpu2 = @cpu2, " +
|
||||
"mhz2 = @mhz2, bits = @bits, ram = @ram, rom = @rom, gpu = @gpu, vram = @vram, colors = @colors, res = @res, sound_synth = @sound_synth, music_synth = @music_synth " +
|
||||
"sound_channels = @sound_channels, music_channels = @music_channels, hdd1 = @hdd1, hdd2 = @hdd2, hdd3 = @hdd3, disk1 = @disk1, cap1 = @cap1, disk2 = @disk2, cap2 = @cap2 " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
return UpdateMachine(entry);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -270,202 +202,7 @@ namespace Cicm.Database
|
||||
/// <returns><c>true</c> if removed correctly, <c>false</c> otherwise</returns>
|
||||
public bool RemoveComputer(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing computer widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM computers WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandComputer(Computer 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();
|
||||
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();
|
||||
IDbDataParameter param13 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param14 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param15 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param16 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param17 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param18 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param19 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param20 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param21 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param22 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param23 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param24 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param25 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@company";
|
||||
param2.ParameterName = "@year";
|
||||
param3.ParameterName = "@model";
|
||||
param4.ParameterName = "@cpu1";
|
||||
param5.ParameterName = "@mhz1";
|
||||
param6.ParameterName = "@cpu2";
|
||||
param7.ParameterName = "@mhz2";
|
||||
param8.ParameterName = "@bits";
|
||||
param9.ParameterName = "@ram";
|
||||
param10.ParameterName = "@rom";
|
||||
param11.ParameterName = "@gpu";
|
||||
param12.ParameterName = "@vram";
|
||||
param13.ParameterName = "@colors";
|
||||
param14.ParameterName = "@res";
|
||||
param15.ParameterName = "@sound_synth";
|
||||
param16.ParameterName = "@music_synth";
|
||||
param17.ParameterName = "@sound_channels";
|
||||
param18.ParameterName = "@music_channels";
|
||||
param19.ParameterName = "@hdd1";
|
||||
param20.ParameterName = "@hdd2";
|
||||
param21.ParameterName = "@hdd3";
|
||||
param22.ParameterName = "@disk1";
|
||||
param23.ParameterName = "@cap1";
|
||||
param24.ParameterName = "@disk2";
|
||||
param25.ParameterName = "@cap2";
|
||||
|
||||
param1.DbType = DbType.Int32;
|
||||
param2.DbType = DbType.Int32;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.Int32;
|
||||
param5.DbType = DbType.Double;
|
||||
param6.DbType = DbType.Int32;
|
||||
param7.DbType = DbType.Double;
|
||||
param8.DbType = DbType.Int32;
|
||||
param9.DbType = DbType.Int32;
|
||||
param10.DbType = DbType.Int32;
|
||||
param11.DbType = DbType.Int32;
|
||||
param12.DbType = DbType.Int32;
|
||||
param13.DbType = DbType.Int32;
|
||||
param14.DbType = DbType.String;
|
||||
param15.DbType = DbType.Int32;
|
||||
param16.DbType = DbType.Int32;
|
||||
param17.DbType = DbType.Int32;
|
||||
param18.DbType = DbType.Int32;
|
||||
param19.DbType = DbType.Int32;
|
||||
param20.DbType = DbType.Int32;
|
||||
param21.DbType = DbType.Int32;
|
||||
param22.DbType = DbType.Int32;
|
||||
param23.DbType = DbType.String;
|
||||
param24.DbType = DbType.Int32;
|
||||
param25.DbType = DbType.String;
|
||||
|
||||
param1.Value = entry.Company;
|
||||
param2.Value = entry.Year;
|
||||
param3.Value = entry.Model;
|
||||
param4.Value = entry.Cpu1;
|
||||
param5.Value = entry.Mhz1;
|
||||
param6.Value = entry.Cpu2;
|
||||
param7.Value = entry.Mhz2;
|
||||
param8.Value = entry.Bits;
|
||||
param9.Value = entry.Ram;
|
||||
param10.Value = entry.Rom;
|
||||
param11.Value = entry.Gpu;
|
||||
param12.Value = entry.Vram;
|
||||
param13.Value = entry.Colors;
|
||||
param14.Value = entry.Resolution;
|
||||
param15.Value = entry.SoundSynth;
|
||||
param16.Value = entry.MusicSynth;
|
||||
param17.Value = entry.SoundChannels;
|
||||
param18.Value = entry.MusicChannels;
|
||||
param19.Value = entry.Hdd1;
|
||||
param20.Value = entry.Hdd2;
|
||||
param21.Value = entry.Hdd3;
|
||||
param22.Value = entry.Disk1;
|
||||
param23.Value = entry.Cap1;
|
||||
param24.Value = entry.Disk2;
|
||||
param25.Value = entry.Cap2;
|
||||
|
||||
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);
|
||||
dbcmd.Parameters.Add(param13);
|
||||
dbcmd.Parameters.Add(param14);
|
||||
dbcmd.Parameters.Add(param15);
|
||||
dbcmd.Parameters.Add(param16);
|
||||
dbcmd.Parameters.Add(param17);
|
||||
dbcmd.Parameters.Add(param18);
|
||||
dbcmd.Parameters.Add(param19);
|
||||
dbcmd.Parameters.Add(param20);
|
||||
dbcmd.Parameters.Add(param21);
|
||||
dbcmd.Parameters.Add(param22);
|
||||
dbcmd.Parameters.Add(param23);
|
||||
dbcmd.Parameters.Add(param24);
|
||||
dbcmd.Parameters.Add(param25);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<Computer> ComputersFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<Computer> entries = new List<Computer>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
Computer entry = new Computer
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
Company = (int)dataRow["company"],
|
||||
Year = (int)dataRow["year"],
|
||||
Model = (string)dataRow["model"],
|
||||
Cpu1 = dataRow["cpu1"] == DBNull.Value ? 0 : (int)dataRow["cpu1"],
|
||||
Mhz1 = dataRow["mhz1"] == DBNull.Value ? 0 : float.Parse(dataRow["mhz1"].ToString()),
|
||||
Cpu2 = dataRow["cpu2"] == DBNull.Value ? 0 : (int)dataRow["cpu2"],
|
||||
Mhz2 = dataRow["mhz2"] == DBNull.Value ? 0 : float.Parse(dataRow["mhz2"].ToString()),
|
||||
Bits = (int)dataRow["bits"],
|
||||
Ram = (int)dataRow["ram"],
|
||||
Rom = (int)dataRow["rom"],
|
||||
Gpu = dataRow["gpu"] == DBNull.Value ? 0 : (int)dataRow["gpu"],
|
||||
Vram = (int)dataRow["vram"],
|
||||
Colors = (int)dataRow["colors"],
|
||||
Resolution = (string)dataRow["res"],
|
||||
SoundSynth = (int)dataRow["sound_synth"],
|
||||
MusicSynth = (int)dataRow["music_synth"],
|
||||
SoundChannels = (int)dataRow["sound_channels"],
|
||||
MusicChannels = (int)dataRow["music_channels"],
|
||||
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"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
return RemoveMachine(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using Console = Cicm.Database.Schemas.Console;
|
||||
using Cicm.Database.Schemas;
|
||||
|
||||
namespace Cicm.Database
|
||||
{
|
||||
@@ -42,31 +42,31 @@ namespace Cicm.Database
|
||||
/// </summary>
|
||||
/// <param name="entries">All consoles</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetConsoles(out List<Console> entries)
|
||||
public bool GetConsoles(out List<Machine> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
System.Console.WriteLine("Getting all consoles...");
|
||||
Console.WriteLine("Getting all consoles...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from consoles";
|
||||
string sql = $"SELECT * FROM machines WHERE type = '{(int)MachineType.Console}'";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = ConsolesFromDataTable(dataSet.Tables[0]);
|
||||
entries = MachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
System.Console.WriteLine("Error getting consoles.");
|
||||
System.Console.WriteLine(ex);
|
||||
Console.WriteLine("Error getting consoles.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
@@ -78,31 +78,31 @@ namespace Cicm.Database
|
||||
/// <param name="entries">All consoles</param>
|
||||
/// <param name="company">Company id</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetConsoles(out List<Console> entries, int company)
|
||||
public bool GetConsoles(out List<Machine> entries, int company)
|
||||
{
|
||||
#if DEBUG
|
||||
System.Console.WriteLine("Getting all consoles from company id {0}...", company);
|
||||
Console.WriteLine("Getting all consoles from company id {0}...", company);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from consoles WHERE company = '{id}'";
|
||||
string sql = $"SELECT * FROM machines WHERE company = '{company}' AND type = '{(int)MachineType.Console}'";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
dbCmd.CommandText = sql;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = ConsolesFromDataTable(dataSet.Tables[0]);
|
||||
entries = MachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
System.Console.WriteLine("Error getting consoles.");
|
||||
System.Console.WriteLine(ex);
|
||||
Console.WriteLine("Error getting consoles.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
@@ -115,15 +115,15 @@ namespace Cicm.Database
|
||||
/// <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 GetConsoles(out List<Console> entries, ulong start, ulong count)
|
||||
public bool GetConsoles(out List<Machine> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
System.Console.WriteLine("Getting {0} consoles from {1}...", count, start);
|
||||
Console.WriteLine("Getting {0} consoles from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM consoles LIMIT {start}, {count}";
|
||||
string sql = $"SELECT * FROM machines WHERE type = '{(int)MachineType.Console}' LIMIT {start}, {count}";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
@@ -132,14 +132,14 @@ namespace Cicm.Database
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = ConsolesFromDataTable(dataSet.Tables[0]);
|
||||
entries = MachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
System.Console.WriteLine("Error getting consoles.");
|
||||
System.Console.WriteLine(ex);
|
||||
Console.WriteLine("Error getting consoles.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
@@ -150,33 +150,9 @@ namespace Cicm.Database
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Videogame console with specified id, <c>null</c> if not found or error</returns>
|
||||
public Console GetConsole(int id)
|
||||
public Machine GetConsole(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
System.Console.WriteLine("Getting console with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from consoles 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<Console> entries = ConsolesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
System.Console.WriteLine("Error getting console.");
|
||||
System.Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
return GetMachine(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -186,11 +162,11 @@ namespace Cicm.Database
|
||||
public long CountConsoles()
|
||||
{
|
||||
#if DEBUG
|
||||
System.Console.WriteLine("Counting consoles...");
|
||||
Console.WriteLine("Counting consoles...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM consoles";
|
||||
dbcmd.CommandText = $"SELECT COUNT(*) FROM consoles WHERE type = '{(int)MachineType.Console}'";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
@@ -203,33 +179,10 @@ namespace Cicm.Database
|
||||
/// <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 AddConsole(Console entry, out long id)
|
||||
public bool AddConsole(Machine entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
System.Console.Write("Adding console `{0}`...", entry.Model);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandConsole(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL =
|
||||
"INSERT INTO consoles (company, year, model, cpu1, mhz1, cpu2, mhz2, bits, ram, rom, gpu, vram, colors, res, sound_synth, music_synth, schannels, mchannels, palette, format, cap)" +
|
||||
" VALUES (@company, @year, @model, @cpu1, @mhz1, @cpu2, @mhz2, @bits, @ram, @rom, @gpu, @vram, @colors, @res, @sound_synth, @music_synth, @schannels, @mchannels, @palette, @format, @cap)";
|
||||
|
||||
dbcmd.CommandText = SQL;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
id = dbCore.LastInsertRowId;
|
||||
|
||||
#if DEBUG
|
||||
System.Console.WriteLine(" id {0}", id);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
entry.Type = MachineType.Console;
|
||||
return AddMachine(entry, out id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -237,29 +190,9 @@ namespace Cicm.Database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateConsole(Console entry)
|
||||
public bool UpdateConsole(Machine entry)
|
||||
{
|
||||
#if DEBUG
|
||||
System.Console.WriteLine("Updating console `{0}`...", entry.Model);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandConsole(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql =
|
||||
"UPDATE consoles SET company = @company, year = @year, model = @model, cpu1 = @cpu1, mhz1 = @mhz1, cpu2 = @cpu2, " +
|
||||
"mhz2 = @mhz2, bits = @bits, ram = @ram, rom = @rom, gpu = @gpu, vram = @vram, colors = @colors, res = @res, sound_synth = @sound_synth, music_synth = @music_synth " +
|
||||
"schannels = @schannels, mchannels = @mchannels, palette = @palette, format = @format, cap = @cap " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
return UpdateMachine(entry);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -269,178 +202,7 @@ namespace Cicm.Database
|
||||
/// <returns><c>true</c> if removed correctly, <c>false</c> otherwise</returns>
|
||||
public bool RemoveConsole(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
System.Console.WriteLine("Removing console widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM consoles WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandConsole(Console 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();
|
||||
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();
|
||||
IDbDataParameter param13 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param14 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param15 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param16 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param17 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param18 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param19 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param20 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param21 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@company";
|
||||
param2.ParameterName = "@year";
|
||||
param3.ParameterName = "@model";
|
||||
param4.ParameterName = "@cpu1";
|
||||
param5.ParameterName = "@mhz1";
|
||||
param6.ParameterName = "@cpu2";
|
||||
param7.ParameterName = "@mhz2";
|
||||
param8.ParameterName = "@bits";
|
||||
param9.ParameterName = "@ram";
|
||||
param10.ParameterName = "@rom";
|
||||
param11.ParameterName = "@gpu";
|
||||
param12.ParameterName = "@vram";
|
||||
param13.ParameterName = "@colors";
|
||||
param14.ParameterName = "@res";
|
||||
param15.ParameterName = "@sound_synth";
|
||||
param16.ParameterName = "@music_synth";
|
||||
param17.ParameterName = "@schannels";
|
||||
param18.ParameterName = "@mchannels";
|
||||
param19.ParameterName = "@palette";
|
||||
param20.ParameterName = "@format";
|
||||
param21.ParameterName = "@cap";
|
||||
|
||||
param1.DbType = DbType.Int32;
|
||||
param2.DbType = DbType.Int32;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.Int32;
|
||||
param5.DbType = DbType.Double;
|
||||
param6.DbType = DbType.Int32;
|
||||
param7.DbType = DbType.Double;
|
||||
param8.DbType = DbType.Int32;
|
||||
param9.DbType = DbType.Int32;
|
||||
param10.DbType = DbType.Int32;
|
||||
param11.DbType = DbType.Int32;
|
||||
param12.DbType = DbType.Int32;
|
||||
param13.DbType = DbType.Int32;
|
||||
param14.DbType = DbType.String;
|
||||
param15.DbType = DbType.Int32;
|
||||
param16.DbType = DbType.Int32;
|
||||
param17.DbType = DbType.Int32;
|
||||
param18.DbType = DbType.Int32;
|
||||
param19.DbType = DbType.Int32;
|
||||
param20.DbType = DbType.Int32;
|
||||
param21.DbType = DbType.Int32;
|
||||
|
||||
param1.Value = entry.Company;
|
||||
param2.Value = entry.Year;
|
||||
param3.Value = entry.Model;
|
||||
param4.Value = entry.Cpu1;
|
||||
param5.Value = entry.Mhz1;
|
||||
param6.Value = entry.Cpu2;
|
||||
param7.Value = entry.Mhz2;
|
||||
param8.Value = entry.Bits;
|
||||
param9.Value = entry.Ram;
|
||||
param10.Value = entry.Rom;
|
||||
param11.Value = entry.Gpu;
|
||||
param12.Value = entry.Vram;
|
||||
param13.Value = entry.Colors;
|
||||
param14.Value = entry.Resolution;
|
||||
param15.Value = entry.SoundSynth;
|
||||
param16.Value = entry.MusicSynth;
|
||||
param17.Value = entry.SoundChannels;
|
||||
param18.Value = entry.MusicChannels;
|
||||
param19.Value = entry.Palette;
|
||||
param20.Value = entry.Format;
|
||||
param21.Value = entry.Cap;
|
||||
|
||||
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);
|
||||
dbcmd.Parameters.Add(param13);
|
||||
dbcmd.Parameters.Add(param14);
|
||||
dbcmd.Parameters.Add(param15);
|
||||
dbcmd.Parameters.Add(param16);
|
||||
dbcmd.Parameters.Add(param17);
|
||||
dbcmd.Parameters.Add(param18);
|
||||
dbcmd.Parameters.Add(param19);
|
||||
dbcmd.Parameters.Add(param20);
|
||||
dbcmd.Parameters.Add(param21);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<Console> ConsolesFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<Console> entries = new List<Console>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
Console entry = new Console
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
Company = (int)dataRow["company"],
|
||||
Year = (int)dataRow["year"],
|
||||
Model = (string)dataRow["model"],
|
||||
Cpu1 = dataRow["cpu1"] == DBNull.Value ? 0 : (int)dataRow["cpu1"],
|
||||
Mhz1 = dataRow["mhz1"] == DBNull.Value ? 0 : float.Parse(dataRow["mhz1"].ToString()),
|
||||
Cpu2 = dataRow["cpu2"] == DBNull.Value ? 0 : (int)dataRow["cpu2"],
|
||||
Mhz2 = dataRow["mhz2"] == DBNull.Value ? 0 : float.Parse(dataRow["mhz2"].ToString()),
|
||||
Bits = (int)dataRow["bits"],
|
||||
Ram = (int)dataRow["ram"],
|
||||
Rom = (int)dataRow["rom"],
|
||||
Gpu = dataRow["gpu"] == DBNull.Value ? 0 : (int)dataRow["gpu"],
|
||||
Vram = (int)dataRow["vram"],
|
||||
Colors = (int)dataRow["colors"],
|
||||
Resolution = (string)dataRow["res"],
|
||||
SoundSynth = (int)dataRow["sound_synth"],
|
||||
MusicSynth = (int)dataRow["music_synth"],
|
||||
SoundChannels = (int)dataRow["schannels"],
|
||||
MusicChannels = (int)dataRow["mchannels"],
|
||||
Palette = (int)dataRow["palette"],
|
||||
Format = (int)dataRow["format"],
|
||||
Cap = (int)dataRow["cap"]
|
||||
};
|
||||
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
return entries;
|
||||
return RemoveMachine(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,107 +49,99 @@ namespace Cicm.Database
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
|
||||
Console.WriteLine("Creating table `admins`");
|
||||
dbCmd.CommandText = V13.Admins;
|
||||
dbCmd.CommandText = V14.Admins;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `browser_tests`");
|
||||
dbCmd.CommandText = V13.BrowserTests;
|
||||
dbCmd.CommandText = V14.BrowserTests;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `cicm_db`");
|
||||
dbCmd.CommandText = V13.CicmDb;
|
||||
dbCmd.CommandText = V14.CicmDb;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `companies`");
|
||||
dbCmd.CommandText = V13.Companies;
|
||||
dbCmd.CommandText = V14.Companies;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `computers`");
|
||||
dbCmd.CommandText = V13.Computers;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `consoles`");
|
||||
dbCmd.CommandText = V13.Consoles;
|
||||
Console.WriteLine("Creating table `machines`");
|
||||
dbCmd.CommandText = V14.Machines;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `disk_formats`");
|
||||
dbCmd.CommandText = V13.DiskFormats;
|
||||
dbCmd.CommandText = V14.DiskFormats;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `forbidden`");
|
||||
dbCmd.CommandText = V13.Forbidden;
|
||||
dbCmd.CommandText = V14.Forbidden;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `gpus`");
|
||||
dbCmd.CommandText = V13.Gpus;
|
||||
dbCmd.CommandText = V14.Gpus;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `log`");
|
||||
dbCmd.CommandText = V13.Logs;
|
||||
dbCmd.CommandText = V14.Logs;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `money_donations`");
|
||||
dbCmd.CommandText = V13.MoneyDonations;
|
||||
dbCmd.CommandText = V14.MoneyDonations;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `news`");
|
||||
dbCmd.CommandText = V13.News;
|
||||
dbCmd.CommandText = V14.News;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `owned_computers`");
|
||||
dbCmd.CommandText = V13.OwnedComputers;
|
||||
dbCmd.CommandText = V14.OwnedComputers;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `owned_consoles`");
|
||||
dbCmd.CommandText = V13.OwnedConsoles;
|
||||
dbCmd.CommandText = V14.OwnedConsoles;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `instruction_sets`");
|
||||
dbCmd.CommandText = V13.InstructionSets;
|
||||
dbCmd.CommandText = V14.InstructionSets;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `instruction_set_extensions`");
|
||||
dbCmd.CommandText = V13.InstructionSetExtensions;
|
||||
dbCmd.CommandText = V14.InstructionSetExtensions;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `processors`");
|
||||
dbCmd.CommandText = V13.Processors;
|
||||
dbCmd.CommandText = V14.Processors;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `instruction_set_extensions_by_processor`");
|
||||
dbCmd.CommandText = V13.InstructionSetExtensionsByProcessor;
|
||||
dbCmd.CommandText = V14.InstructionSetExtensionsByProcessor;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `sound_synths`");
|
||||
dbCmd.CommandText = V13.SoundSynths;
|
||||
dbCmd.CommandText = V14.SoundSynths;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `iso3166_1_numeric`");
|
||||
dbCmd.CommandText = V13.Iso3166Numeric;
|
||||
dbCmd.CommandText = V14.Iso3166Numeric;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Filling table `iso3166_1_numeric`");
|
||||
dbCmd.CommandText = V13.Iso3166NumericValues;
|
||||
dbCmd.CommandText = V14.Iso3166NumericValues;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating foreign keys for table `companies`");
|
||||
dbCmd.CommandText = V13.CompaniesForeignKeys;
|
||||
dbCmd.CommandText = V14.CompaniesForeignKeys;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating foreign keys for table `computers`");
|
||||
dbCmd.CommandText = V13.ComputersForeignKeys;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating foreign keys for table `consoles`");
|
||||
dbCmd.CommandText = V13.ConsolesForeignKeys;
|
||||
Console.WriteLine("Creating foreign keys for table `machines`");
|
||||
dbCmd.CommandText = V14.MachinesForeignKeys;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `company_logos`");
|
||||
dbCmd.CommandText = V13.CompanyLogos;
|
||||
dbCmd.CommandText = V14.CompanyLogos;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("Creating table `company_descriptions`");
|
||||
dbCmd.CommandText = V13.CompanyDescriptions;
|
||||
dbCmd.CommandText = V14.CompanyDescriptions;
|
||||
dbCmd.ExecuteNonQuery();
|
||||
|
||||
return true;
|
||||
|
||||
470
Cicm.Database/Operations/Machine.cs
Normal file
470
Cicm.Database/Operations/Machine.cs
Normal file
@@ -0,0 +1,470 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Machine.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Contains operations to manage machines.
|
||||
//
|
||||
// --[ 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 machines
|
||||
/// </summary>
|
||||
/// <param name="entries">All machines</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetMachines(out List<Machine> entries)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all machines...");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from machines";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = MachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting machines.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all machines from specified company
|
||||
/// </summary>
|
||||
/// <param name="entries">All machines</param>
|
||||
/// <param name="company">Company id</param>
|
||||
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
|
||||
public bool GetMachines(out List<Machine> entries, int company)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting all machines from company id {0}...", company);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
const string SQL = "SELECT * from machines WHERE company = '{id}'";
|
||||
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = SQL;
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
entries = MachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting machines.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified number of machines since the specified start
|
||||
/// </summary>
|
||||
/// <param name="entries">List of machines</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 GetMachines(out List<Machine> entries, ulong start, ulong count)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting {0} machines from {1}...", count, start);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * FROM machines 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 = MachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting machines.");
|
||||
Console.WriteLine(ex);
|
||||
entries = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets machine by specified id
|
||||
/// </summary>
|
||||
/// <param name="id">Id</param>
|
||||
/// <returns>Machine with specified id, <c>null</c> if not found or error</returns>
|
||||
public Machine GetMachine(int id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Getting machine with id {0}...", id);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
string sql = $"SELECT * from machines 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<Machine> entries = MachinesFromDataTable(dataSet.Tables[0]);
|
||||
|
||||
return entries == null || entries.Count == 0 ? null : entries[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error getting machine.");
|
||||
Console.WriteLine(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of machines in the database
|
||||
/// </summary>
|
||||
/// <returns>Entries in database</returns>
|
||||
public long CountMachines()
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Counting machines...");
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
dbcmd.CommandText = "SELECT COUNT(*) FROM machines";
|
||||
object count = dbcmd.ExecuteScalar();
|
||||
dbcmd.Dispose();
|
||||
try { return Convert.ToInt64(count); }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new administrator 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 AddMachine(Machine entry, out long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Write("Adding machine `{0}`...", entry.Model);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandMachine(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
const string SQL =
|
||||
"INSERT INTO machines (company, year, model, cpu1, mhz1, cpu2, mhz2, ram, rom, gpu, vram, colors, res, sound_synth, music_synth, sound_channels, music_channels, hdd1, hdd2, hdd3, disk1, cap1, disk2, cap2, type)" +
|
||||
" VALUES (@company, @year, @model, @cpu1, @mhz1, @cpu2, @mhz2, @ram, @rom, @gpu, @vram, @colors, @res, @sound_synth, @music_synth, @sound_channels, @music_channels, @hdd1, @hdd2, @hdd3, @disk1, @cap1, @disk2, @cap2, @type)";
|
||||
|
||||
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 machine in the database
|
||||
/// </summary>
|
||||
/// <param name="entry">Updated entry</param>
|
||||
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
|
||||
public bool UpdateMachine(Machine entry)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Updating machine `{0}`...", entry.Model);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = GetCommandMachine(entry);
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql =
|
||||
"UPDATE machines SET company = @company, year = @year, model = @model, cpu1 = @cpu1, mhz1 = @mhz1, cpu2 = @cpu2, " +
|
||||
"mhz2 = @mhz2, ram = @ram, rom = @rom, gpu = @gpu, vram = @vram, colors = @colors, res = @res, sound_synth = @sound_synth, music_synth = @music_synth " +
|
||||
"sound_channels = @sound_channels, music_channels = @music_channels, hdd1 = @hdd1, hdd2 = @hdd2, hdd3 = @hdd3, disk1 = @disk1, cap1 = @cap1, disk2 = @disk2, cap2 = @cap2, type = @type " +
|
||||
$"WHERE id = {entry.Id}";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a machine 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 RemoveMachine(long id)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Removing machine widh id `{0}`...", id);
|
||||
#endif
|
||||
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
string sql = $"DELETE FROM machines WHERE id = '{id}';";
|
||||
|
||||
dbcmd.CommandText = sql;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IDbCommand GetCommandMachine(Machine 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();
|
||||
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();
|
||||
IDbDataParameter param13 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param14 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param15 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param16 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param17 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param18 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param19 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param20 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param21 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param22 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param23 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param24 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param25 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@company";
|
||||
param2.ParameterName = "@year";
|
||||
param3.ParameterName = "@model";
|
||||
param4.ParameterName = "@cpu1";
|
||||
param5.ParameterName = "@mhz1";
|
||||
param6.ParameterName = "@cpu2";
|
||||
param7.ParameterName = "@mhz2";
|
||||
param8.ParameterName = "@ram";
|
||||
param9.ParameterName = "@rom";
|
||||
param10.ParameterName = "@gpu";
|
||||
param11.ParameterName = "@vram";
|
||||
param12.ParameterName = "@colors";
|
||||
param13.ParameterName = "@res";
|
||||
param14.ParameterName = "@sound_synth";
|
||||
param15.ParameterName = "@music_synth";
|
||||
param16.ParameterName = "@sound_channels";
|
||||
param17.ParameterName = "@music_channels";
|
||||
param18.ParameterName = "@hdd1";
|
||||
param19.ParameterName = "@hdd2";
|
||||
param20.ParameterName = "@hdd3";
|
||||
param21.ParameterName = "@disk1";
|
||||
param22.ParameterName = "@cap1";
|
||||
param23.ParameterName = "@disk2";
|
||||
param24.ParameterName = "@cap2";
|
||||
param25.ParameterName = "@type";
|
||||
|
||||
param1.DbType = DbType.Int32;
|
||||
param2.DbType = DbType.Int32;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.Int32;
|
||||
param5.DbType = DbType.Double;
|
||||
param6.DbType = DbType.Int32;
|
||||
param7.DbType = DbType.Double;
|
||||
param8.DbType = DbType.Int32;
|
||||
param9.DbType = DbType.Int32;
|
||||
param10.DbType = DbType.Int32;
|
||||
param11.DbType = DbType.Int32;
|
||||
param12.DbType = DbType.Int32;
|
||||
param13.DbType = DbType.String;
|
||||
param14.DbType = DbType.Int32;
|
||||
param15.DbType = DbType.Int32;
|
||||
param16.DbType = DbType.Int32;
|
||||
param17.DbType = DbType.Int32;
|
||||
param18.DbType = DbType.Int32;
|
||||
param19.DbType = DbType.Int32;
|
||||
param20.DbType = DbType.Int32;
|
||||
param21.DbType = DbType.Int32;
|
||||
param22.DbType = DbType.String;
|
||||
param23.DbType = DbType.Int32;
|
||||
param24.DbType = DbType.String;
|
||||
param25.DbType = DbType.Int32;
|
||||
|
||||
param1.Value = entry.Company;
|
||||
param2.Value = entry.Year;
|
||||
param3.Value = entry.Model;
|
||||
param4.Value = entry.Cpu1;
|
||||
param5.Value = entry.Mhz1;
|
||||
param6.Value = entry.Cpu2;
|
||||
param7.Value = entry.Mhz2;
|
||||
param8.Value = entry.Ram;
|
||||
param9.Value = entry.Rom;
|
||||
param10.Value = entry.Gpu;
|
||||
param11.Value = entry.Vram;
|
||||
param12.Value = entry.Colors;
|
||||
param13.Value = entry.Resolution;
|
||||
param14.Value = entry.SoundSynth;
|
||||
param15.Value = entry.MusicSynth;
|
||||
param16.Value = entry.SoundChannels;
|
||||
param17.Value = entry.MusicChannels;
|
||||
param18.Value = entry.Hdd1;
|
||||
param19.Value = entry.Hdd2;
|
||||
param20.Value = entry.Hdd3;
|
||||
param21.Value = entry.Disk1;
|
||||
param22.Value = entry.Cap1;
|
||||
param23.Value = entry.Disk2;
|
||||
param24.Value = entry.Cap2;
|
||||
param25.Value = entry.Type;
|
||||
|
||||
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);
|
||||
dbcmd.Parameters.Add(param13);
|
||||
dbcmd.Parameters.Add(param14);
|
||||
dbcmd.Parameters.Add(param15);
|
||||
dbcmd.Parameters.Add(param16);
|
||||
dbcmd.Parameters.Add(param17);
|
||||
dbcmd.Parameters.Add(param18);
|
||||
dbcmd.Parameters.Add(param19);
|
||||
dbcmd.Parameters.Add(param20);
|
||||
dbcmd.Parameters.Add(param21);
|
||||
dbcmd.Parameters.Add(param22);
|
||||
dbcmd.Parameters.Add(param23);
|
||||
dbcmd.Parameters.Add(param24);
|
||||
dbcmd.Parameters.Add(param25);
|
||||
|
||||
return dbcmd;
|
||||
}
|
||||
|
||||
static List<Machine> MachinesFromDataTable(DataTable dataTable)
|
||||
{
|
||||
List<Machine> entries = new List<Machine>();
|
||||
|
||||
foreach(DataRow dataRow in dataTable.Rows)
|
||||
{
|
||||
Machine entry = new Machine
|
||||
{
|
||||
Id = (int)dataRow["id"],
|
||||
Company = (int)dataRow["company"],
|
||||
Year = (int)dataRow["year"],
|
||||
Model = (string)dataRow["model"],
|
||||
Cpu1 = dataRow["cpu1"] == DBNull.Value ? 0 : (int)dataRow["cpu1"],
|
||||
Mhz1 = dataRow["mhz1"] == DBNull.Value ? 0 : float.Parse(dataRow["mhz1"].ToString()),
|
||||
Cpu2 = dataRow["cpu2"] == DBNull.Value ? 0 : (int)dataRow["cpu2"],
|
||||
Mhz2 = dataRow["mhz2"] == DBNull.Value ? 0 : float.Parse(dataRow["mhz2"].ToString()),
|
||||
Ram = (int)dataRow["ram"],
|
||||
Rom = (int)dataRow["rom"],
|
||||
Gpu = dataRow["gpu"] == DBNull.Value ? 0 : (int)dataRow["gpu"],
|
||||
Vram = (int)dataRow["vram"],
|
||||
Colors = (int)dataRow["colors"],
|
||||
Resolution = (string)dataRow["res"],
|
||||
SoundSynth = (int)dataRow["sound_synth"],
|
||||
MusicSynth = (int)dataRow["music_synth"],
|
||||
SoundChannels = (int)dataRow["sound_channels"],
|
||||
MusicChannels = (int)dataRow["music_channels"],
|
||||
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);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace Cicm.Database
|
||||
public partial class Operations
|
||||
{
|
||||
/// <summary>Last known database version</summary>
|
||||
const int DB_VERSION = 13;
|
||||
const int DB_VERSION = 14;
|
||||
/// <summary>The column with this value indicates there is no item of this type.</summary>
|
||||
public const int DB_NONE = -1;
|
||||
/// <summary>This value indicates there's no GPU, but a direct memory->display connection (a framebuffer).</summary>
|
||||
|
||||
@@ -32,6 +32,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using Cicm.Database.Schemas;
|
||||
using Cicm.Database.Schemas.Sql;
|
||||
|
||||
namespace Cicm.Database
|
||||
@@ -133,6 +134,11 @@ namespace Cicm.Database
|
||||
UpdateDatabaseToV13();
|
||||
break;
|
||||
}
|
||||
case 13:
|
||||
{
|
||||
UpdateDatabaseToV14();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
OptimizeDatabase();
|
||||
@@ -1290,6 +1296,281 @@ namespace Cicm.Database
|
||||
dbCmd.Dispose();
|
||||
}
|
||||
|
||||
void UpdateDatabaseToV14()
|
||||
{
|
||||
Console.WriteLine("Updating database to version 14");
|
||||
|
||||
Console.WriteLine("Renaming table `computers` to `machines`");
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
IDbTransaction trans = dbCon.BeginTransaction();
|
||||
dbCmd.Transaction = trans;
|
||||
dbCmd.CommandText = "ALTER TABLE `computers` RENAME TO `machines`;";
|
||||
dbCmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbCmd.Dispose();
|
||||
|
||||
Console.WriteLine("Removing column `bits` from table `machines`");
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
trans = dbCon.BeginTransaction();
|
||||
dbCmd.Transaction = trans;
|
||||
dbCmd.CommandText = "ALTER TABLE `machines` DROP COLUMN `bits`;";
|
||||
dbCmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbCmd.Dispose();
|
||||
|
||||
Console.WriteLine("Creating column `type` in table `machines`");
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
trans = dbCon.BeginTransaction();
|
||||
dbCmd.Transaction = trans;
|
||||
dbCmd.CommandText =
|
||||
$"ALTER TABLE `machines` ADD COLUMN `type` INT NOT NULL DEFAULT '{(int)MachineType.Unknown}';";
|
||||
dbCmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbCmd.Dispose();
|
||||
|
||||
Console.WriteLine("Updating all entries in table `machines`");
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
trans = dbCon.BeginTransaction();
|
||||
dbCmd.Transaction = trans;
|
||||
dbCmd.CommandText = $"UPDATE `machines` SET `type` = '{(int)MachineType.Computer}';";
|
||||
dbCmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbCmd.Dispose();
|
||||
|
||||
Console.WriteLine("Renaming all indexes on table `machines`");
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
trans = dbCon.BeginTransaction();
|
||||
dbCmd.Transaction = trans;
|
||||
dbCmd.CommandText =
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_company`, ADD INDEX `idx_machines_company` (`company`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_year`, ADD INDEX `idx_machines_year` (`year`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_model`, ADD INDEX `idx_machines_model` (`model`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_cpu1`, ADD INDEX `idx_machines_cpu1` (`cpu1`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_cpu2`, ADD INDEX `idx_machines_cpu2` (`cpu2`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_mhz1`, ADD INDEX `idx_machines_mhz1` (`mhz1`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_mhz2`, ADD INDEX `idx_machines_mhz2` (`mhz2`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_ram`, ADD INDEX `idx_machines_ram` (`ram`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_rom`, ADD INDEX `idx_machines_rom` (`rom`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_gpu`, ADD INDEX `idx_machines_gpu` (`gpu`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_vram`, ADD INDEX `idx_machines_vram` (`vram`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_colors`, ADD INDEX `idx_machines_colors` (`colors`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_res`, ADD INDEX `idx_machines_res` (`res`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_sound_synth`, ADD INDEX `idx_machines_sound_synth` (`sound_synth`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_music_synth`, ADD INDEX `idx_machines_music_synth` (`music_synth`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_hdd1`, ADD INDEX `idx_machines_hdd1` (`hdd1`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_hdd2`, ADD INDEX `idx_machines_hdd2` (`hdd2`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_hdd3`, ADD INDEX `idx_machines_hdd3` (`hdd3`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_disk1`, ADD INDEX `idx_machines_disk1` (`disk1`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_disk2`, ADD INDEX `idx_machines_disk2` (`disk2`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_cap1`, ADD INDEX `idx_machines_cap1` (`cap1`);\n" +
|
||||
"ALTER TABLE `machines` DROP INDEX `idx_computers_cap2`, ADD INDEX `idx_machines_cap2` (`cap2`);";
|
||||
dbCmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbCmd.Dispose();
|
||||
|
||||
Console.WriteLine("Removing old foreign keys from table `machines`");
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
trans = dbCon.BeginTransaction();
|
||||
dbCmd.Transaction = trans;
|
||||
dbCmd.CommandText = "ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_company`;\n" +
|
||||
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_cpu1`;\n" +
|
||||
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_cpu2`;\n" +
|
||||
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_disk1`;\n" +
|
||||
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_disk2`;\n" +
|
||||
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_gpu`;\n" +
|
||||
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_hdd1`;\n" +
|
||||
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_hdd2`;\n" +
|
||||
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_hdd3`;\n" +
|
||||
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_music_synth`;\n" +
|
||||
"ALTER TABLE `machines` DROP FOREIGN KEY `fk_computers_sound_synth`;";
|
||||
dbCmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbCmd.Dispose();
|
||||
|
||||
Console.WriteLine("Adding foreign keys in table `machines`");
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
trans = dbCon.BeginTransaction();
|
||||
dbCmd.Transaction = trans;
|
||||
dbCmd.CommandText =
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_company` (company) REFERENCES `companies` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_cpu1` (cpu1) REFERENCES `processors` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_cpu2` (cpu2) REFERENCES `processors` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_disk1` (disk1) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_disk2` (disk2) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_gpu` (gpu) REFERENCES `gpus` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_hdd1` (hdd1) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_hdd2` (hdd2) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_hdd3` (hdd3) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_music_synth` (music_synth) REFERENCES `sound_synths` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_sound_synth` (sound_synth) REFERENCES `sound_synths` (`id`) ON UPDATE CASCADE;";
|
||||
dbCmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbCmd.Dispose();
|
||||
|
||||
Console.WriteLine("Adding new index for `type` in table `machines`");
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
trans = dbCon.BeginTransaction();
|
||||
dbCmd.Transaction = trans;
|
||||
dbCmd.CommandText = "CREATE INDEX `idx_machines_type` ON `machines` (`type`);";
|
||||
dbCmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbCmd.Dispose();
|
||||
|
||||
Console.WriteLine("Getting all items from `consoles`");
|
||||
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
|
||||
dbCmd.CommandText = "SELECT * from consoles";
|
||||
DataSet dataSet = new DataSet();
|
||||
dataAdapter.SelectCommand = dbCmd;
|
||||
dataAdapter.Fill(dataSet);
|
||||
|
||||
foreach(DataRow dataRow in dataSet.Tables[0].Rows)
|
||||
{
|
||||
IDbCommand dbcmd = dbCon.CreateCommand();
|
||||
|
||||
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();
|
||||
IDbDataParameter param13 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param14 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param15 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param16 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param17 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param18 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param19 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param20 = dbcmd.CreateParameter();
|
||||
IDbDataParameter param21 = dbcmd.CreateParameter();
|
||||
|
||||
param1.ParameterName = "@company";
|
||||
param2.ParameterName = "@year";
|
||||
param3.ParameterName = "@model";
|
||||
param4.ParameterName = "@cpu1";
|
||||
param5.ParameterName = "@mhz1";
|
||||
param6.ParameterName = "@cpu2";
|
||||
param7.ParameterName = "@mhz2";
|
||||
param8.ParameterName = "@ram";
|
||||
param9.ParameterName = "@rom";
|
||||
param10.ParameterName = "@gpu";
|
||||
param11.ParameterName = "@vram";
|
||||
param12.ParameterName = "@colors";
|
||||
param13.ParameterName = "@res";
|
||||
param14.ParameterName = "@sound_synth";
|
||||
param15.ParameterName = "@music_synth";
|
||||
param16.ParameterName = "@sound_channels";
|
||||
param17.ParameterName = "@music_channels";
|
||||
param18.ParameterName = "@type";
|
||||
param19.ParameterName = "@hdd1";
|
||||
param20.ParameterName = "@disk1";
|
||||
param21.ParameterName = "@cap1";
|
||||
|
||||
param1.DbType = DbType.Int32;
|
||||
param2.DbType = DbType.Int32;
|
||||
param3.DbType = DbType.String;
|
||||
param4.DbType = DbType.Int32;
|
||||
param5.DbType = DbType.Double;
|
||||
param6.DbType = DbType.Int32;
|
||||
param7.DbType = DbType.Double;
|
||||
param8.DbType = DbType.Int32;
|
||||
param9.DbType = DbType.Int32;
|
||||
param10.DbType = DbType.Int32;
|
||||
param11.DbType = DbType.Int32;
|
||||
param12.DbType = DbType.Int32;
|
||||
param13.DbType = DbType.String;
|
||||
param14.DbType = DbType.Int32;
|
||||
param15.DbType = DbType.Int32;
|
||||
param16.DbType = DbType.Int32;
|
||||
param17.DbType = DbType.Int32;
|
||||
param18.DbType = DbType.Int32;
|
||||
param19.DbType = DbType.Int32;
|
||||
param20.DbType = DbType.Int32;
|
||||
param21.DbType = DbType.Int32;
|
||||
|
||||
param1.Value = (int)dataRow["company"];
|
||||
param2.Value = (int)dataRow["year"];
|
||||
param3.Value = (string)dataRow["model"];
|
||||
param4.Value = dataRow["cpu1"] == DBNull.Value ? (object)null : (int)dataRow["cpu1"];
|
||||
param5.Value = dataRow["mhz1"] == DBNull.Value ? (object)null : float.Parse(dataRow["mhz1"].ToString());
|
||||
param6.Value = dataRow["cpu2"] == DBNull.Value ? (object)null : (int)dataRow["cpu2"];
|
||||
param7.Value = dataRow["mhz2"] == DBNull.Value ? (object)null : float.Parse(dataRow["mhz2"].ToString());
|
||||
param8.Value = (int)dataRow["ram"];
|
||||
param9.Value = (int)dataRow["rom"];
|
||||
param10.Value = dataRow["gpu"] == DBNull.Value ? (object)null : (int)dataRow["gpu"];
|
||||
param11.Value = (int)dataRow["vram"];
|
||||
param12.Value = (int)dataRow["colors"];
|
||||
param13.Value = (string)dataRow["res"];
|
||||
param14.Value = (int)dataRow["sound_synth"];
|
||||
param15.Value = (int)dataRow["music_synth"];
|
||||
param16.Value = (int)dataRow["schannels"];
|
||||
param17.Value = (int)dataRow["mchannels"];
|
||||
param18.Value = MachineType.Console;
|
||||
param19.Value = 30;
|
||||
param20.Value = 30;
|
||||
param21.Value = 0;
|
||||
|
||||
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);
|
||||
dbcmd.Parameters.Add(param13);
|
||||
dbcmd.Parameters.Add(param14);
|
||||
dbcmd.Parameters.Add(param15);
|
||||
dbcmd.Parameters.Add(param16);
|
||||
dbcmd.Parameters.Add(param17);
|
||||
dbcmd.Parameters.Add(param18);
|
||||
dbcmd.Parameters.Add(param19);
|
||||
dbcmd.Parameters.Add(param20);
|
||||
dbcmd.Parameters.Add(param21);
|
||||
|
||||
trans = dbCon.BeginTransaction();
|
||||
dbcmd.Transaction = trans;
|
||||
|
||||
Console.WriteLine("Converting console \"{0}\" to machine", (string)param3.Value);
|
||||
|
||||
const string SQL =
|
||||
"INSERT INTO machines (company, year, model, cpu1, mhz1, cpu2, mhz2, ram, rom, gpu, vram, colors, res, sound_synth, music_synth, sound_channels, music_channels, type, hdd1, disk1, cap1)" +
|
||||
" VALUES (@company, @year, @model, @cpu1, @mhz1, @cpu2, @mhz2, @ram, @rom, @gpu, @vram, @colors, @res, @sound_synth, @music_synth, @sound_channels, @music_channels, @type, @hdd1, @disk1, @cap1)";
|
||||
|
||||
dbcmd.CommandText = SQL;
|
||||
|
||||
dbcmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbcmd.Dispose();
|
||||
}
|
||||
|
||||
Console.WriteLine("Dropping table `consoles`");
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
trans = dbCon.BeginTransaction();
|
||||
dbCmd.Transaction = trans;
|
||||
dbCmd.CommandText = "DROP TABLE `consoles`;";
|
||||
dbCmd.ExecuteNonQuery();
|
||||
trans.Commit();
|
||||
dbCmd.Dispose();
|
||||
|
||||
Console.WriteLine("Setting new database version to 14...");
|
||||
dbCmd = dbCon.CreateCommand();
|
||||
dbCmd.CommandText = "INSERT INTO cicm_db (version) VALUES ('14')";
|
||||
dbCmd.ExecuteNonQuery();
|
||||
dbCmd.Dispose();
|
||||
}
|
||||
|
||||
void OptimizeDatabase()
|
||||
{
|
||||
IDbCommand dbCmd = dbCon.CreateCommand();
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Console.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// High level representation of a videogame console.
|
||||
//
|
||||
// --[ 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
|
||||
{
|
||||
public class Console
|
||||
{
|
||||
/// <summary>Bits of GPRs of primary CPU</summary>
|
||||
public int Bits;
|
||||
/// <summary>Capacity in kibibytes of storage format</summary>
|
||||
public int Cap;
|
||||
/// <summary>Maximum colors on screen</summary>
|
||||
public int Colors;
|
||||
/// <summary>Manufacturer's company ID</summary>
|
||||
public int Company;
|
||||
/// <summary>Primary CPU</summary>
|
||||
public int Cpu1;
|
||||
/// <summary>Secondary CPU</summary>
|
||||
public int Cpu2;
|
||||
/// <summary>ID of storage format</summary>
|
||||
public int Format;
|
||||
/// <summary>ID of GPU</summary>
|
||||
public int Gpu;
|
||||
/// <summary>ID</summary>
|
||||
public int Id;
|
||||
/// <summary>Frequency in MHz of primary CPU</summary>
|
||||
public float Mhz1;
|
||||
/// <summary>Frequency in MHz of secondary CPU</summary>
|
||||
public float Mhz2;
|
||||
/// <summary>Model name</summary>
|
||||
public string Model;
|
||||
/// <summary>Audio channels supported by the MPU</summary>
|
||||
public int MusicChannels;
|
||||
/// <summary>ID of MPU</summary>
|
||||
public int MusicSynth;
|
||||
/// <summary>Colors on palette</summary>
|
||||
public int Palette;
|
||||
/// <summary>Size in kibibytes of program RAM</summary>
|
||||
public int Ram;
|
||||
/// <summary>Resolution in WxH pixels</summary>
|
||||
public string Resolution;
|
||||
/// <summary>Size in kibibytes of firmware</summary>
|
||||
public int Rom;
|
||||
/// <summary>Audio channels supported by the DSP</summary>
|
||||
public int SoundChannels;
|
||||
/// <summary>ID of DSP</summary>
|
||||
public int SoundSynth;
|
||||
/// <summary>Size in kibibytes for video RAM</summary>
|
||||
public int Vram;
|
||||
/// <summary>Introduction date, 0 if unknown, 1000 if prototype</summary>
|
||||
public int Year;
|
||||
}
|
||||
}
|
||||
@@ -67,4 +67,14 @@ namespace Cicm.Database.Schemas
|
||||
/// <summary>Company renamed possibly with a change of intentions</summary>
|
||||
Renamed = 6
|
||||
}
|
||||
|
||||
public enum MachineType
|
||||
{
|
||||
/// <summary>Unknown machine type, should not happen</summary>
|
||||
Unknown = 0,
|
||||
/// <summary>Computer</summary>
|
||||
Computer = 1,
|
||||
/// <summary>Videogame console</summary>
|
||||
Console = 2
|
||||
}
|
||||
}
|
||||
@@ -31,10 +31,8 @@
|
||||
namespace Cicm.Database.Schemas
|
||||
{
|
||||
/// <summary>Computer</summary>
|
||||
public class Computer
|
||||
public class Machine
|
||||
{
|
||||
/// <summary>Bits of GPRs of primary CPU</summary>
|
||||
public int Bits;
|
||||
/// <summary>Capacity of first removable disk format</summary>
|
||||
public string Cap1;
|
||||
/// <summary>Capacity of second removable disk format</summary>
|
||||
@@ -81,6 +79,8 @@ namespace Cicm.Database.Schemas
|
||||
public int SoundChannels;
|
||||
/// <summary>ID of DSP</summary>
|
||||
public int SoundSynth;
|
||||
/// <summary>Machine type</summary>
|
||||
public MachineType Type;
|
||||
/// <summary>Size in kibibytes for video RAM</summary>
|
||||
public int Vram;
|
||||
/// <summary>Introduction date, 0 if unknown, 1000 if prototype</summary>
|
||||
149
Cicm.Database/Schemas/Sql/V14.cs
Normal file
149
Cicm.Database/Schemas/Sql/V14.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
/******************************************************************************
|
||||
// Canary Islands Computer Museum Website
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : V14.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 V14
|
||||
{
|
||||
public static readonly string Admins = V13.Admins;
|
||||
|
||||
public static readonly string BrowserTests = V13.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 ('14');";
|
||||
|
||||
public static readonly string Companies = V13.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" +
|
||||
"`cpu1` int(11) DEFAULT NULL,;\n" +
|
||||
"`mhz1` int(11) DEFAULT NULL,;\n" +
|
||||
"`cpu2` int(11) DEFAULT NULL,;\n" +
|
||||
"`mhz2` decimal(11,2) DEFAULT NULL,;\n" +
|
||||
"`ram` int(11) NOT NULL DEFAULT '0',;\n" +
|
||||
"`rom` int(11) NOT NULL DEFAULT '0',;\n" +
|
||||
"`gpu` int(11) DEFAULT NULL,;\n" +
|
||||
"`vram` int(11) NOT NULL DEFAULT '0',;\n" +
|
||||
"`colors` int(11) NOT NULL DEFAULT '0',;\n" +
|
||||
"`res` char(10) NOT NULL DEFAULT '',;\n" +
|
||||
"`sound_synth` int(11) NOT NULL DEFAULT '0',;\n" +
|
||||
"`music_synth` int(11) NOT NULL DEFAULT '0',;\n" +
|
||||
"`sound_channels` int(11) NOT NULL DEFAULT '0',;\n" +
|
||||
"`music_channels` int(11) NOT NULL DEFAULT '0',;\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_cpu1` (`cpu1`),;\n" +
|
||||
"KEY `idx_machines_cpu2` (`cpu2`),;\n" +
|
||||
"KEY `idx_machines_mhz1` (`mhz1`),;\n" +
|
||||
"KEY `idx_machines_mhz2` (`mhz2`),;\n" +
|
||||
"KEY `idx_machines_ram` (`ram`),;\n" +
|
||||
"KEY `idx_machines_rom` (`rom`),;\n" +
|
||||
"KEY `idx_machines_gpu` (`gpu`),;\n" +
|
||||
"KEY `idx_machines_vram` (`vram`),;\n" +
|
||||
"KEY `idx_machines_colors` (`colors`),;\n" +
|
||||
"KEY `idx_machines_res` (`res`),;\n" +
|
||||
"KEY `idx_machines_sound_synth` (`sound_synth`),;\n" +
|
||||
"KEY `idx_machines_music_synth` (`music_synth`),;\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 = V13.DiskFormats;
|
||||
|
||||
public static readonly string Forbidden = V13.Forbidden;
|
||||
|
||||
public static readonly string Gpus = V13.Gpus;
|
||||
|
||||
public static readonly string Logs = V13.Logs;
|
||||
|
||||
public static readonly string MoneyDonations = V13.MoneyDonations;
|
||||
|
||||
public static readonly string News = V13.News;
|
||||
|
||||
public static readonly string OwnedComputers = V13.OwnedComputers;
|
||||
|
||||
public static readonly string OwnedConsoles = V13.OwnedConsoles;
|
||||
|
||||
public static readonly string Processors = V13.Processors;
|
||||
|
||||
public static readonly string SoundSynths = V13.SoundSynths;
|
||||
|
||||
public static readonly string MachinesForeignKeys = V13.ComputersForeignKeys;
|
||||
|
||||
public static readonly string Iso3166Numeric = V13.Iso3166Numeric;
|
||||
|
||||
public static readonly string Iso3166NumericValues = V13.Iso3166NumericValues;
|
||||
|
||||
public static readonly string CompaniesForeignKeys =
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_company` (company) REFERENCES `companies` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_cpu1` (cpu1) REFERENCES `processors` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_cpu2` (cpu2) REFERENCES `processors` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_disk1` (disk1) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_disk2` (disk2) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_gpu` (gpu) REFERENCES `gpus` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_hdd1` (hdd1) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_hdd2` (hdd2) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_hdd3` (hdd3) REFERENCES `disk_formats` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_music_synth` (music_synth) REFERENCES `sound_synths` (`id`) ON UPDATE CASCADE;\n" +
|
||||
"ALTER TABLE `machines` ADD FOREIGN KEY `fk_machines_sound_synth` (sound_synth) REFERENCES `sound_synths` (`id`) ON UPDATE CASCADE;";
|
||||
|
||||
public static readonly string CompanyLogos = V13.CompanyLogos;
|
||||
|
||||
public static readonly string CompanyDescriptions = V13.CompanyDescriptions;
|
||||
|
||||
public static readonly string InstructionSets = V13.InstructionSets;
|
||||
|
||||
public static readonly string InstructionSetExtensions = V13.InstructionSetExtensions;
|
||||
|
||||
public static readonly string InstructionSetExtensionsByProcessor = V13.InstructionSetExtensionsByProcessor;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user