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

185 lines
7.3 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 = V22.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 = V22.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 = V22.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 = V22.Companies;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `machine_families`");
dbCmd.CommandText = V22.MachineFamilies;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `machines`");
dbCmd.CommandText = V22.Machines;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `forbidden`");
dbCmd.CommandText = V22.Forbidden;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `gpus`");
dbCmd.CommandText = V22.Gpus;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `log`");
dbCmd.CommandText = V22.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 = V22.MoneyDonations;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `news`");
dbCmd.CommandText = V22.News;
2018-04-15 17:51:07 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `owned_computers`");
dbCmd.CommandText = V22.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 = V22.OwnedConsoles;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_sets`");
dbCmd.CommandText = V22.InstructionSets;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_set_extensions`");
dbCmd.CommandText = V22.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 = V22.Processors;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `instruction_set_extensions_by_processor`");
dbCmd.CommandText = V22.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 = V22.SoundSynths;
2018-04-16 03:20:18 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `iso3166_1_numeric`");
dbCmd.CommandText = V22.Iso3166Numeric;
2018-04-16 03:20:18 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Filling table `iso3166_1_numeric`");
dbCmd.CommandText = V22.Iso3166NumericValues;
2018-04-16 03:20:18 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating foreign keys for table `companies`");
dbCmd.CommandText = V22.CompaniesForeignKeys;
2018-04-16 01:40:05 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating foreign keys for table `machines`");
dbCmd.CommandText = V22.MachinesForeignKeys;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `company_logos`");
dbCmd.CommandText = V22.CompanyLogos;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `company_descriptions`");
dbCmd.CommandText = V22.CompanyDescriptions;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `processors_by_machine`");
dbCmd.CommandText = V22.ProcessorsByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `gpus_by_machine`");
dbCmd.CommandText = V22.GpusByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `sound_by_machine`");
dbCmd.CommandText = V22.SoundByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `memory_by_machine`");
dbCmd.CommandText = V22.MemoryByMachine;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `resolutions`");
dbCmd.CommandText = V22.Resolutions;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `resolutions_by_gpu`");
dbCmd.CommandText = V22.ResolutionsByGpu;
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `storage_by_machine`");
dbCmd.CommandText = V22.StorageByMachine;
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;
}
}
}
}