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

129 lines
4.8 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`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.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`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.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`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.CicmDb;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `companies`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.Companies;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `computers`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.Computers;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `consoles`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.Consoles;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `disk_formats`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.DiskFormats;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `forbidden`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.Forbidden;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `gpus`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.Gpus;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `log`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.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`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.MoneyDonations;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `music_synths`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.MusicSynths;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `news`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.News;
2018-04-15 17:51:07 +01:00
dbCmd.ExecuteNonQuery();
Console.WriteLine("Creating table `owned_computers`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.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`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.OwnedConsoles;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `processors`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.Processors;
2018-04-12 10:05:42 +01:00
dbCmd.ExecuteNonQuery();
2018-04-15 17:51:07 +01:00
Console.WriteLine("Creating table `sound_synths`");
2018-04-15 23:23:18 +01:00
dbCmd.CommandText = V4.SoundSynths;
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;
}
}
}
}