ace/Source/ACE.Database/SQLFormatters/World/EventSQLWriter.cs
Mag-nus 3c46c07ffe
This moves the .sql file generation code that Ripley has been using into ACE.Database (#889)
* This moves the .sql file generation code that Ripley has been using into ACE.Database

This will help us import data from any source into ACE EF objects, and then use these SQLWriters to create a unified output.

* Weenie and LandblockInstances SQL Writers added + Enums

Some styling and comments added to the other SQL Writer classes.

Still need to do the treasure tables, as well as recipe/cook books.

Also need to confirm SQL output is well formed and accurate.

* CookBookSQLWriter and RecipeSQLWriter

Writers that still aren't implemented:
PointsOfInterest
TreasureDeath
TreasureWielded

Also, still need to test the output of these writers to make sure it's correct.

* Formatting tweaked a little bit, much closer to the final product

This creates scripts that import.
Still need to verify a couple of data mismatches.

* This moves the Int/Did property decoder to ACE.Entity.Enum.Properties

This code will likely be used to help UI content editors and database viewers.

* This fixes float output where precision was lost. Woops.

* Fat fingered a variable in the weenie SQL writer

This concludes all the testing for the SQL Writers.

They all test OK and produce the same results as the code Ripley was using to generate the .sql files.
2018-07-28 21:01:19 -05:00

44 lines
1.6 KiB
C#

using System;
using System.Globalization;
using System.IO;
using ACE.Database.Models.World;
namespace ACE.Database.SQLFormatters.World
{
public class EventSQLWriter : SQLWriter
{
/// <summary>
/// Default is formed from: input.name
/// </summary>
public string GetDefaultFileName(Event input)
{
string fileName = input.Name;
fileName = IllegalInFileName.Replace(fileName, "_");
fileName += ".sql";
return fileName;
}
public void CreateSQLDELETEStatement(Event input, StreamWriter writer)
{
writer.WriteLine($"DELETE FROM `event` WHERE `name` = {GetSQLString(input.Name)};");
}
public void CreateSQLINSERTStatement(Event input, StreamWriter writer)
{
writer.WriteLine("INSERT INTO `event` (`name`, `start_Time`, `end_Time`, `state`)");
var output = "VALUES (" +
$"{GetSQLString(input.Name)}, " +
$"{(input.StartTime == -1 ? $"{input.StartTime}" : $"{input.StartTime} /* {DateTimeOffset.FromUnixTimeSeconds(input.StartTime).DateTime.ToUniversalTime().ToString(CultureInfo.InvariantCulture)} */")}, " +
$"{(input.EndTime == -1 ? $"{input.EndTime}" : $"{input.EndTime} /* {DateTimeOffset.FromUnixTimeSeconds(input.EndTime).DateTime.ToUniversalTime().ToString(CultureInfo.InvariantCulture)} */")}, " +
$"{input.State}" +
");";
output = FixNullFields(output);
writer.WriteLine(output);
}
}
}