diff --git a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj index 0a9046c..671e9f9 100644 --- a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj +++ b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj @@ -64,6 +64,10 @@ False C:\ProgramData\Crestron\SDK\SimplSharpReflectionInterface.dll + + False + ..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpSQLHelperInterface.dll + @@ -146,6 +150,10 @@ + + + + diff --git a/ICD.Common.Utils/Sqlite/IcdSqliteCommand.cs b/ICD.Common.Utils/Sqlite/IcdSqliteCommand.cs new file mode 100644 index 0000000..cd15a1e --- /dev/null +++ b/ICD.Common.Utils/Sqlite/IcdSqliteCommand.cs @@ -0,0 +1,54 @@ +using System; +#if SIMPLSHARP +using SqliteCommand = Crestron.SimplSharp.SQLite.SQLiteCommand; +#else +using Microsoft.Data.Sqlite; +#endif + +namespace ICD.Common.Utils.Sqlite +{ + public sealed class IcdSqliteCommand : IDisposable + { + private readonly SqliteCommand m_Command; + private readonly IcdSqliteParameterCollection m_Parameters; + + public IcdSqliteParameterCollection Parameters { get { return m_Parameters; } } + + /// + /// Constructor. + /// + /// + /// + public IcdSqliteCommand(string query, IcdSqliteConnection connection) + { + m_Command = new SqliteCommand(query, connection.WrappedConnection); + m_Parameters = new IcdSqliteParameterCollection(m_Command.Parameters); + } + + /// + /// Release resources. + /// + public void Dispose() + { + m_Command.Dispose(); + } + + /// + /// Executes the command against the database and returns a data reader. + /// + /// The data reader. + public IcdSqliteDataReader ExecuteReader() + { + return new IcdSqliteDataReader(m_Command.ExecuteReader()); + } + + /// + /// Executes the command against the database. + /// + /// The number of rows inserted, updated, or deleted. -1 for SELECT statements. + public int ExecuteNonQuery() + { + return m_Command.ExecuteNonQuery(); + } + } +} \ No newline at end of file diff --git a/ICD.Common.Utils/Sqlite/IcdSqliteConnection.cs b/ICD.Common.Utils/Sqlite/IcdSqliteConnection.cs new file mode 100644 index 0000000..ab57053 --- /dev/null +++ b/ICD.Common.Utils/Sqlite/IcdSqliteConnection.cs @@ -0,0 +1,55 @@ +using System; +using ICD.Common.Utils.IO; +#if SIMPLSHARP +using SqliteConnection = Crestron.SimplSharp.SQLite.SQLiteConnection; +#else +using Microsoft.Data.Sqlite; +#endif + +namespace ICD.Common.Utils.Sqlite +{ + public sealed class IcdSqliteConnection : IDisposable + { + private readonly SqliteConnection m_Connection; + + /// + /// Gets the wrapped connection instance. + /// + public SqliteConnection WrappedConnection { get { return m_Connection; } } + + /// + /// Constructor. + /// + /// + public IcdSqliteConnection(string connectionString) + { + m_Connection = new SqliteConnection(connectionString); + } + + /// + /// Creates a new SQLite database file at the given path. + /// + /// + public static void CreateFile(string path) + { + IcdFileStream fs = IcdFile.Create(path); + fs.Close(); + } + + /// + /// Release resources. + /// + public void Dispose() + { + m_Connection.Dispose(); + } + + /// + /// Opens a connection to the database. + /// + public void Open() + { + m_Connection.Open(); + } + } +} diff --git a/ICD.Common.Utils/Sqlite/IcdSqliteDataReader.cs b/ICD.Common.Utils/Sqlite/IcdSqliteDataReader.cs new file mode 100644 index 0000000..da59964 --- /dev/null +++ b/ICD.Common.Utils/Sqlite/IcdSqliteDataReader.cs @@ -0,0 +1,23 @@ +using System; +using Microsoft.Data.Sqlite; + +namespace ICD.Common.Utils.Sqlite +{ + public sealed class IcdSqliteDataReader : IDisposable + { + public IcdSqliteDataReader(SqliteDataReader executeReader) + { + throw new NotImplementedException(); + } + + public void Dispose() + { + throw new NotImplementedException(); + } + + public bool Read() + { + throw new NotImplementedException(); + } + } +} diff --git a/ICD.Common.Utils/Sqlite/IcdSqliteParameter.cs b/ICD.Common.Utils/Sqlite/IcdSqliteParameter.cs new file mode 100644 index 0000000..abd0179 --- /dev/null +++ b/ICD.Common.Utils/Sqlite/IcdSqliteParameter.cs @@ -0,0 +1,7 @@ +namespace ICD.Common.Utils.Sqlite +{ + public sealed class IcdSqliteParameter + { + public object Value { get; set; } + } +} diff --git a/ICD.Common.Utils/Sqlite/IcdSqliteParameterCollection.cs b/ICD.Common.Utils/Sqlite/IcdSqliteParameterCollection.cs new file mode 100644 index 0000000..1cae59c --- /dev/null +++ b/ICD.Common.Utils/Sqlite/IcdSqliteParameterCollection.cs @@ -0,0 +1,30 @@ +#if SIMPLSHARP +using SqliteParameterCollection = Crestron.SimplSharp.SQLite.SQLiteParameterCollection; +#else +using Microsoft.Data.Sqlite; +#endif + +namespace ICD.Common.Utils.Sqlite +{ + public sealed class IcdSqliteParameterCollection + { + private readonly SqliteParameterCollection m_Parameters; + + /// + /// Constructor. + /// + /// + public IcdSqliteParameterCollection(SqliteParameterCollection commandParameters) + { + m_Parameters = commandParameters; + } + + + public IcdSqliteParameter Add(string name, eDbType type) + { + SqliteType + + return new IcdSqliteParameter(m_Parameters.Add(name, type)); + } + } +} diff --git a/ICD.Common.Utils/Sqlite/eDbType.cs b/ICD.Common.Utils/Sqlite/eDbType.cs new file mode 100644 index 0000000..5031ef3 --- /dev/null +++ b/ICD.Common.Utils/Sqlite/eDbType.cs @@ -0,0 +1,112 @@ +#if SIMPLSHARP +using Crestron.SimplSharp.CrestronData; +#else +using System; +using Microsoft.Data.Sqlite; +#endif + +namespace ICD.Common.Utils.Sqlite +{ + public enum eDbType + { + AnsiString = 0, + Binary = 1, + Byte = 2, + Boolean = 3, + Currency = 4, + Date = 5, + DateTime = 6, + Decimal = 7, + Double = 8, + Guid = 9, + Int16 = 10, + Int32 = 11, + Int64 = 12, + Object = 13, + SByte = 14, + Single = 15, + String = 16, + Time = 17, + UInt16 = 18, + UInt32 = 19, + UInt64 = 20, + VarNumeric = 21, + AnsiStringFixedLength = 22, + StringFixedLength = 23, + Xml = 25, + DateTime2 = 26, + DateTimeOffset = 27 + } + + public static class DbTypeExtensions + { + public static +#if SIMPLSHARP + DbType +#else + SqliteType +#endif + ToParamType(this eDbType extends) + { +#if SIMPLSHARP + return (DbType)extends; +#else + switch (extends) + { + case eDbType.AnsiString: + break; + case eDbType.Binary: + break; + case eDbType.Byte: + break; + case eDbType.Boolean: + break; + case eDbType.Currency: + break; + case eDbType.Date: + break; + case eDbType.DateTime: + break; + case eDbType.Decimal: + case eDbType.Double: + return SqliteType.Real; + case eDbType.Guid: + break; + case eDbType.Int16: + case eDbType.Int32: + case eDbType.Int64: + case eDbType.UInt16: + case eDbType.UInt32: + case eDbType.UInt64: + case eDbType.SByte: + case eDbType.Single: + return SqliteType.Integer; + + case eDbType.Object: + break; + + break; + case eDbType.String: + break; + case eDbType.Time: + break; + + break; + case eDbType.VarNumeric: + break; + case eDbType.AnsiStringFixedLength: + case eDbType.StringFixedLength: + break; + case eDbType.Xml: + break; + case eDbType.DateTime2: + break; + case eDbType.DateTimeOffset: + break; + default: + throw new ArgumentOutOfRangeException("extends"); + } +#endif + } + } +}