From 44b79ea7eea3baa0c9f6e69483fc32c751078d0d Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Sat, 27 Jan 2018 22:39:19 -0500 Subject: [PATCH] Implementing sqlite data reader --- .../ICD.Common.Utils_NetStandard.csproj | 1 + ICD.Common.Utils/Sqlite/IIcdDataReader.cs | 9 +++++++ ICD.Common.Utils/Sqlite/IIcdDataRecord.cs | 7 ++++++ ICD.Common.Utils/Sqlite/IcdDbDataReader.cs | 14 +++++++++++ ICD.Common.Utils/Sqlite/IcdSqliteCommand.cs | 5 ++++ .../Sqlite/IcdSqliteDataReader.cs | 25 +++++++++++++------ 6 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 ICD.Common.Utils/Sqlite/IIcdDataReader.cs create mode 100644 ICD.Common.Utils/Sqlite/IIcdDataRecord.cs create mode 100644 ICD.Common.Utils/Sqlite/IcdDbDataReader.cs diff --git a/ICD.Common.Utils/ICD.Common.Utils_NetStandard.csproj b/ICD.Common.Utils/ICD.Common.Utils_NetStandard.csproj index fa2a59d..3b89663 100644 --- a/ICD.Common.Utils/ICD.Common.Utils_NetStandard.csproj +++ b/ICD.Common.Utils/ICD.Common.Utils_NetStandard.csproj @@ -43,6 +43,7 @@ + diff --git a/ICD.Common.Utils/Sqlite/IIcdDataReader.cs b/ICD.Common.Utils/Sqlite/IIcdDataReader.cs new file mode 100644 index 0000000..009d913 --- /dev/null +++ b/ICD.Common.Utils/Sqlite/IIcdDataReader.cs @@ -0,0 +1,9 @@ +using System; + +namespace ICD.Common.Utils.Sqlite +{ + public interface IIcdDataReader : IDisposable, IIcdDataRecord + { + bool Read(); + } +} diff --git a/ICD.Common.Utils/Sqlite/IIcdDataRecord.cs b/ICD.Common.Utils/Sqlite/IIcdDataRecord.cs new file mode 100644 index 0000000..91f7485 --- /dev/null +++ b/ICD.Common.Utils/Sqlite/IIcdDataRecord.cs @@ -0,0 +1,7 @@ +namespace ICD.Common.Utils.Sqlite +{ + public interface IIcdDataRecord + { + object this[string columnId] { get; } + } +} diff --git a/ICD.Common.Utils/Sqlite/IcdDbDataReader.cs b/ICD.Common.Utils/Sqlite/IcdDbDataReader.cs new file mode 100644 index 0000000..59fee5d --- /dev/null +++ b/ICD.Common.Utils/Sqlite/IcdDbDataReader.cs @@ -0,0 +1,14 @@ +namespace ICD.Common.Utils.Sqlite +{ + public abstract class IcdDbDataReader : IIcdDataReader + { + /// + /// Release resources. + /// + public abstract void Dispose(); + + public abstract bool Read(); + + public abstract object this[string columnId] { get; } + } +} diff --git a/ICD.Common.Utils/Sqlite/IcdSqliteCommand.cs b/ICD.Common.Utils/Sqlite/IcdSqliteCommand.cs index cd15a1e..1d7e95b 100644 --- a/ICD.Common.Utils/Sqlite/IcdSqliteCommand.cs +++ b/ICD.Common.Utils/Sqlite/IcdSqliteCommand.cs @@ -50,5 +50,10 @@ namespace ICD.Common.Utils.Sqlite { return m_Command.ExecuteNonQuery(); } + + public object ExecuteScalar() + { + return m_Command.ExecuteScalar(); + } } } \ No newline at end of file diff --git a/ICD.Common.Utils/Sqlite/IcdSqliteDataReader.cs b/ICD.Common.Utils/Sqlite/IcdSqliteDataReader.cs index da59964..acc14c2 100644 --- a/ICD.Common.Utils/Sqlite/IcdSqliteDataReader.cs +++ b/ICD.Common.Utils/Sqlite/IcdSqliteDataReader.cs @@ -3,21 +3,32 @@ using Microsoft.Data.Sqlite; namespace ICD.Common.Utils.Sqlite { - public sealed class IcdSqliteDataReader : IDisposable + public sealed class IcdSqliteDataReader : IcdDbDataReader { - public IcdSqliteDataReader(SqliteDataReader executeReader) + private readonly SqliteDataReader m_Reader; + + /// + /// Constructor. + /// + /// + public IcdSqliteDataReader(SqliteDataReader reader) { - throw new NotImplementedException(); + m_Reader = reader; } - public void Dispose() + /// + /// Release resources. + /// + public override void Dispose() { - throw new NotImplementedException(); + m_Reader.Dispose(); } - public bool Read() + public override bool Read() { - throw new NotImplementedException(); + return m_Reader.Read(); } + + public override object this[string columnId] { get { return m_Reader[columnId]; } } } }