Files
marechai/Cicm.Database/Operations/Init.cs

181 lines
7.1 KiB
C#
Raw Normal View History

2018-04-12 10:20:31 +01:00
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Init.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Contains operation to initialize a new database.
//
// --[ 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
*******************************************************************************/
2018-04-12 11:50:02 +01:00
2018-04-12 10:20:31 +01:00
using System;
2018-04-12 10:05:42 +01:00
using System.Data;
using Cicm.Database.Schemas.Sql;
namespace Cicm.Database
{
public partial class Operations
{
2018-04-12 11:50:02 +01:00
/// <summary>
/// Initializes tables in the database
/// </summary>
/// <returns><c>true</c> if initialized correctly, <c>false</c> otherwise</returns>
2018-04-12 10:05:42 +01:00
public bool InitializeNewDatabase()
{
Console.WriteLine("Creating new database version {0}", DB_VERSION);
try
{
IDbCommand dbCmd = dbCon.CreateCommand();
Console.WriteLine("Creating table `admins`");
dbCmd.CommandText = V19.Admins;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `browser_tests`");
dbCmd.CommandText = V19.BrowserTests;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `cicm_db`");
dbCmd.CommandText = V19.CicmDb;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `companies`");
dbCmd.CommandText = V19.Companies;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `machines`");
dbCmd.CommandText = V19.Machines;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `disk_formats`");
dbCmd.CommandText = V19.DiskFormats;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `forbidden`");
dbCmd.CommandText = V19.Forbidden;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `gpus`");
dbCmd.CommandText = V19.Gpus;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `log`");
dbCmd.CommandText = V19.Logs;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `money_donations`");
dbCmd.CommandText = V19.MoneyDonations;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `news`");
dbCmd.CommandText = V19.News;
2018-04-15 17:51:07 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `owned_computers`");
dbCmd.CommandText = V19.OwnedComputers;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `owned_consoles`");
dbCmd.CommandText = V19.OwnedConsoles;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_sets`");
dbCmd.CommandText = V19.InstructionSets;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_set_extensions`");
dbCmd.CommandText = V19.InstructionSetExtensions;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `processors`");
dbCmd.CommandText = V19.Processors;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_set_extensions_by_processor`");
dbCmd.CommandText = V19.InstructionSetExtensionsByProcessor;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `sound_synths`");
dbCmd.CommandText = V19.SoundSynths;
2018-04-16 03:20:18 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `iso3166_1_numeric`");
dbCmd.CommandText = V19.Iso3166Numeric;
2018-04-16 03:20:18 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Filling table `iso3166_1_numeric`");
dbCmd.CommandText = V19.Iso3166NumericValues;
2018-04-16 03:20:18 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating foreign keys for table `companies`");
dbCmd.CommandText = V19.CompaniesForeignKeys;
2018-04-16 01:40:05 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating foreign keys for table `machines`");
dbCmd.CommandText = V19.MachinesForeignKeys;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `company_logos`");
dbCmd.CommandText = V19.CompanyLogos;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `company_descriptions`");
dbCmd.CommandText = V19.CompanyDescriptions;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `processors_by_machine`");
dbCmd.CommandText = V19.ProcessorsByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `gpus_by_machine`");
dbCmd.CommandText = V19.GpusByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `sound_by_machine`");
dbCmd.CommandText = V19.SoundByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `memory_by_machine`");
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;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error creating database.");
Console.WriteLine(ex);
return false;
}
}
}
}