From a4b18301e6ae2375d50be90ed1ff0f59bbdd359f Mon Sep 17 00:00:00 2001 From: Manuel Kamper Date: Sun, 14 Apr 2019 13:51:03 +0200 Subject: [PATCH] initial --- .gitattributes | 63 +++++++++++++ .../Mk0.Tools.SQLiteTools.sln | 25 +++++ .../Mk0.Tools.SQLiteTools.csproj | 52 +++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++ .../Mk0.Tools.SQLiteTools/SQLiteTools.cs | 92 +++++++++++++++++++ .../SQLiteToolsException.cs | 25 +++++ 6 files changed, 293 insertions(+) create mode 100644 .gitattributes create mode 100644 Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools.sln create mode 100644 Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools.csproj create mode 100644 Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/Properties/AssemblyInfo.cs create mode 100644 Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/SQLiteTools.cs create mode 100644 Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/SQLiteToolsException.cs diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools.sln b/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools.sln new file mode 100644 index 0000000..0135720 --- /dev/null +++ b/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2050 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mk0.Tools.SQLiteTools", "Mk0.Tools.SQLiteTools\Mk0.Tools.SQLiteTools.csproj", "{72CAD41F-72FA-48A8-B94D-41BCC0610414}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {72CAD41F-72FA-48A8-B94D-41BCC0610414}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {72CAD41F-72FA-48A8-B94D-41BCC0610414}.Debug|Any CPU.Build.0 = Debug|Any CPU + {72CAD41F-72FA-48A8-B94D-41BCC0610414}.Release|Any CPU.ActiveCfg = Release|Any CPU + {72CAD41F-72FA-48A8-B94D-41BCC0610414}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0919E075-88FE-4A1B-AC18-F68F7C15CDD4} + EndGlobalSection +EndGlobal diff --git a/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools.csproj b/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools.csproj new file mode 100644 index 0000000..4ac41d0 --- /dev/null +++ b/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {72CAD41F-72FA-48A8-B94D-41BCC0610414} + Library + Properties + Mk0.Tools.SQLiteTools + Mk0.Tools.SQLiteTools + v4.6.1 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + ..\..\..\System.Data.SQLite.dll + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/Properties/AssemblyInfo.cs b/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..35b79bf --- /dev/null +++ b/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("Mk0.Tools.SQLiteTools")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Mk0.Tools.SQLiteTools")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("72cad41f-72fa-48a8-b94d-41bcc0610414")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// indem Sie "*" wie unten gezeigt eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/SQLiteTools.cs b/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/SQLiteTools.cs new file mode 100644 index 0000000..e9181e9 --- /dev/null +++ b/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/SQLiteTools.cs @@ -0,0 +1,92 @@ +using System; +using System.Data.SQLite; + +namespace Mk0.Tools.SQLiteTools +{ + public static class SQLiteTools + { + /// + /// Connects to SQLite, only if sql=null + /// + /// + /// + /// + public static SQLiteConnection SQLiteConnect(this SQLiteConnection sql, string fileName) + { + if (sql == null) + { + try + { + sql = new SQLiteConnection("Data Source=" + fileName + ";Version=3;") + { + ParseViaFramework = true + }; + sql.Open(); + } + catch (Exception ex) + { + throw new SQLiteToolsException("Not connected to SQLite.", ex); + } + } + return sql; + } + + /// + /// Disconnects from SQLite (optional VACUUM before diconnection) + /// + /// + /// + public static void SQLiteDisconnect(this SQLiteConnection sql, bool vacuumBeforeClose = false) + { + if (sql != null) + { + if (vacuumBeforeClose) + { + try + { + SQLiteExecute(sql, "VACUUM;"); + } + catch (Exception ex) + { + throw new SQLiteToolsException("Could not VACUUM before closing the SQLite Connection.", ex); + } + } + try + { + sql.Close(); + sql.Dispose(); + } + catch (Exception ex) + { + throw new SQLiteToolsException("Error while closing SQLite Connection.", ex); + } + } + else + { + throw new SQLiteToolsException("SQLite Connection is NULL - so it could not be closed."); + } + } + + /// + /// Executes Queries on SQLite (no selects!) + /// + /// + /// + public static void SQLiteExecute(this SQLiteConnection sql, string query) + { + try + { + SQLiteCommand command = new SQLiteCommand(sql) + { + CommandText = query + }; + command.ExecuteNonQuery(); + command.Dispose(); + } + catch (Exception ex) + { + throw new SQLiteToolsException("Could not execute the Query \"" + query + "\".", ex); + } + } + } +} diff --git a/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/SQLiteToolsException.cs b/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/SQLiteToolsException.cs new file mode 100644 index 0000000..5ecfb0d --- /dev/null +++ b/Mk0.Tools.SQLiteTools/Mk0.Tools.SQLiteTools/SQLiteToolsException.cs @@ -0,0 +1,25 @@ +using System; +using System.Runtime.Serialization; + +namespace Mk0.Tools.SQLiteTools +{ + [Serializable] + internal class SQLiteToolsException : Exception + { + public SQLiteToolsException() + { + } + + public SQLiteToolsException(string message) : base(message) + { + } + + public SQLiteToolsException(string message, Exception innerException) : base(message, innerException) + { + } + + protected SQLiteToolsException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } +}