working on supporting more database dataformats

This commit is contained in:
Michael Becker 2020-10-12 22:19:40 -04:00
parent 7c5967ab43
commit 3a2711c70a
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7
7 changed files with 386 additions and 0 deletions

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<UniversalEditor Version="4.0">
<Associations>
<Association>
<Filters>
<Filter Title="Structured Query Language (SQL) script" ContentType="application/sql" HintComparison="FilterOnly">
<FileNameFilters>
<FileNameFilter>*.sql</FileNameFilter>
</FileNameFilters>
</Filter>
</Filters>
<ObjectModels>
<ObjectModel TypeName="UniversalEditor.ObjectModels.Database.DatabaseObjectModel" />
</ObjectModels>
<DataFormats>
<DataFormat TypeName="UniversalEditor.Plugins.Database.DataFormats.SQL.SQLDataFormat" />
</DataFormats>
</Association>
</Associations>
</UniversalEditor>

View File

@ -0,0 +1,190 @@
//
// MyClass.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// 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/>.
using System;
using System.Collections.Generic;
using System.Text;
using UniversalEditor.DataFormats.Text.Plain;
using UniversalEditor.IO;
using UniversalEditor.ObjectModels.Database;
using UniversalEditor.ObjectModels.Text.Plain;
namespace UniversalEditor.Plugins.Database.DataFormats.SQL
{
public class SQLDataFormat : DataFormat
{
private static DataFormatReference _dfr = null;
protected override DataFormatReference MakeReferenceInternal()
{
if (_dfr == null)
{
_dfr = new DataFormatReference(GetType());
_dfr.Capabilities.Add(typeof(DatabaseObjectModel), DataFormatCapabilities.All);
}
return _dfr;
}
public SQLSettings Settings { get; set; } = new SQLSettings();
public SQLQuotingCharacter QuotingCharacter { get; set; } = SQLQuotingCharacter.Brackets;
protected override void LoadInternal(ref ObjectModel objectModel)
{
DatabaseObjectModel db = (objectModel as DatabaseObjectModel);
if (db == null) throw new ObjectModelNotSupportedException();
Reader reader = Accessor.Reader;
while (!reader.EndOfStream)
{
string token = ReadToken(reader).Trim();
if (token.StartsWith("/*") && token.EndsWith("*/"))
{
// is comment
continue;
}
switch (token.ToLower())
{
case "use":
{
string dbName = ReadToken(reader);
db.Name = dbName;
break;
}
case "go":
{
break;
}
case "set":
{
StringBuilder sbVariableName = new StringBuilder();
string variableName = ReadToken(reader);
string value = ReadToken(reader);
break;
}
case "create":
{
string objectType = ReadToken(reader).ToLower();
switch (objectType)
{
case "table":
{
DatabaseTable table = new DatabaseTable();
string tableName = ReadToken(reader, out string rest);
table.Name = tableName;
List<string> fullyQualifiedTableName = new List<string>();
fullyQualifiedTableName.Add(tableName);
while (rest == ".")
{
tableName = ReadToken(reader, out rest);
fullyQualifiedTableName.Add(tableName);
}
if (rest == "(")
{
do
{
DatabaseField field = new DatabaseField();
string columnName = ReadToken(reader);
field.Name = columnName;
string dataType = ReadToken(reader, out rest);
if (rest == "(")
{
// next token is dataLength
string dataLength = ReadToken(reader);
}
string paramz = ReadToken(reader, out rest);
if (paramz.ToLower() == "not")
{
// not what?
paramz = ReadToken(reader, out rest);
if (paramz.ToLower() == "null")
{
}
}
table.Fields.Add(field);
}
while (rest == ",");
}
db.Tables.Add(table);
break;
}
}
break;
}
}
}
}
private string ReadToken(Reader reader)
{
string rest = null;
return ReadToken(reader, out rest);
}
private string ReadToken(Reader reader, out string rest)
{
string[] tokenDelimiters = new string[] { " ", "\n", ".", "(", ")" };
string token = reader.ReadUntil(tokenDelimiters, out rest).Trim();
while (String.IsNullOrEmpty(token))
token = reader.ReadUntil(tokenDelimiters, out rest).Trim();
if (token.StartsWith("/*"))
{
rest = reader.ReadUntil("*/", true);
string cmntend = reader.ReadFixedLengthString(2);
token += rest + cmntend;
return token;
}
if (token.StartsWith(Settings.QuotingCharacterStart) && !token.EndsWith(Settings.QuotingCharacterEnd))
{
StringBuilder sbWholeToken = new StringBuilder();
sbWholeToken.Append(token);
while (!token.Contains(Settings.QuotingCharacterEnd))
{
token = ReadToken(reader);
sbWholeToken.Append(' ');
sbWholeToken.Append(token);
}
token = sbWholeToken.ToString();
}
if (token.StartsWith(Settings.QuotingCharacterStart) && token.Contains(Settings.QuotingCharacterEnd))
{
token = token.Substring(Settings.QuotingCharacterStart.Length, token.IndexOf(Settings.QuotingCharacterEnd) - Settings.QuotingCharacterStart.Length);
}
if (token.EndsWith("\r"))
token = token.Trim();
return token;
}
protected override void SaveInternal(ObjectModel objectModel)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,35 @@
//
// SQLQuotingCharacter.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// 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/>.
using System;
namespace UniversalEditor.Plugins.Database.DataFormats.SQL
{
public enum SQLQuotingCharacter
{
/// <summary>
/// Brackets (used in Microsoft SQL Server)
/// </summary>
Brackets,
/// <summary>
/// Backticks (used in MySQL)
/// </summary>
Backticks
}
}

View File

@ -0,0 +1,29 @@
//
// SQLSettings.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// 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/>.
using System;
namespace UniversalEditor.Plugins.Database.DataFormats.SQL
{
public class SQLSettings
{
public string QuotingCharacterStart { get; set; } = "[";
public string QuotingCharacterEnd { get; set; } = "]";
}
}

View File

@ -0,0 +1,46 @@
//
// AssemblyInfo.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// 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/>.
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("UniversalEditor.Plugins.Database")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Mike Becker's Software")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Mike Becker's Software")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2EDA483D-E413-4CC5-A944-EBB898611268}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>UniversalEditor.Plugins.Database</RootNamespace>
<AssemblyName>UniversalEditor.Plugins.Database</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<ReleaseVersion>4.0.2019.12</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Output\Debug\Plugins</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>..\..\Output\Release\Plugins</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="DataFormats\SQL\SQLDataFormat.cs" />
<Compile Include="DataFormats\SQL\SQLQuotingCharacter.cs" />
<Compile Include="DataFormats\SQL\SQLSettings.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Core\UniversalEditor.Core.csproj">
<Project>{2D4737E6-6D95-408A-90DB-8DFF38147E85}</Project>
<Name>UniversalEditor.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Essential\UniversalEditor.Essential.csproj">
<Project>{30467E5C-05BC-4856-AADC-13906EF4CADD}</Project>
<Name>UniversalEditor.Essential</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="DataFormats\" />
<Folder Include="DataFormats\SQL\" />
<Folder Include="Associations\" />
<Folder Include="Associations\Database\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Associations\Database\SQL.uexml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -203,6 +203,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MBS.Framework.UserInterface
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Lighting.UserInterface", "Plugins.UserInterface\UniversalEditor.Plugins.Lighting.UserInterface\UniversalEditor.Plugins.Lighting.UserInterface.csproj", "{77C96685-268E-4CAD-867E-C19BBBEB1F3F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Database", "Plugins\UniversalEditor.Plugins.Database\UniversalEditor.Plugins.Database.csproj", "{2EDA483D-E413-4CC5-A944-EBB898611268}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Surodoine", "..\Surodoine\Surodoine\Surodoine.csproj", "{E0897B7B-617A-4709-A4C6-FC0F6B441B2A}"
EndProject
Global
@ -585,6 +587,10 @@ Global
{77C96685-268E-4CAD-867E-C19BBBEB1F3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77C96685-268E-4CAD-867E-C19BBBEB1F3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77C96685-268E-4CAD-867E-C19BBBEB1F3F}.Release|Any CPU.Build.0 = Release|Any CPU
{2EDA483D-E413-4CC5-A944-EBB898611268}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2EDA483D-E413-4CC5-A944-EBB898611268}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2EDA483D-E413-4CC5-A944-EBB898611268}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2EDA483D-E413-4CC5-A944-EBB898611268}.Release|Any CPU.Build.0 = Release|Any CPU
{E0897B7B-617A-4709-A4C6-FC0F6B441B2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E0897B7B-617A-4709-A4C6-FC0F6B441B2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0897B7B-617A-4709-A4C6-FC0F6B441B2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -684,6 +690,7 @@ Global
{63E2F10F-27A6-4BAA-BF4A-4422D0934E91} = {20F315E0-52AE-479F-AF43-3402482C1FC8}
{FAE48F29-DB35-4CD6-8A55-6C1FDDFBE6AF} = {63E2F10F-27A6-4BAA-BF4A-4422D0934E91}
{77C96685-268E-4CAD-867E-C19BBBEB1F3F} = {7B535D74-5496-4802-B809-89ED88274A91}
{2EDA483D-E413-4CC5-A944-EBB898611268} = {2ED32D16-6C06-4450-909A-40D32DA67FB4}
{E0897B7B-617A-4709-A4C6-FC0F6B441B2A} = {20F315E0-52AE-479F-AF43-3402482C1FC8}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution