mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-12 11:15:12 +00:00
Begin writing SQLite cross-platform wrappers
This commit is contained in:
@@ -64,6 +64,10 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>C:\ProgramData\Crestron\SDK\SimplSharpReflectionInterface.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SimplSharpSQLHelperInterface, Version=1.0.92.0, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpSQLHelperInterface.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data" />
|
||||
@@ -146,6 +150,10 @@
|
||||
<Compile Include="SafeCriticalSection.SimplSharp.cs" />
|
||||
<Compile Include="SafeCriticalSection.Standard.cs" />
|
||||
<Compile Include="SafeMutex.cs" />
|
||||
<Compile Include="Sqlite\eDbType.cs" />
|
||||
<Compile Include="Sqlite\IcdSqliteCommand.cs" />
|
||||
<Compile Include="Sqlite\IcdSqliteConnection.cs" />
|
||||
<Compile Include="Sqlite\IcdSqliteDataReader.cs" />
|
||||
<Compile Include="StringUtils.cs" />
|
||||
<Compile Include="TableBuilder.cs" />
|
||||
<Compile Include="ThreadingUtils.cs" />
|
||||
|
||||
54
ICD.Common.Utils/Sqlite/IcdSqliteCommand.cs
Normal file
54
ICD.Common.Utils/Sqlite/IcdSqliteCommand.cs
Normal file
@@ -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; } }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="connection"></param>
|
||||
public IcdSqliteCommand(string query, IcdSqliteConnection connection)
|
||||
{
|
||||
m_Command = new SqliteCommand(query, connection.WrappedConnection);
|
||||
m_Parameters = new IcdSqliteParameterCollection(m_Command.Parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Release resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
m_Command.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the command against the database and returns a data reader.
|
||||
/// </summary>
|
||||
/// <returns>The data reader.</returns>
|
||||
public IcdSqliteDataReader ExecuteReader()
|
||||
{
|
||||
return new IcdSqliteDataReader(m_Command.ExecuteReader());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the command against the database.
|
||||
/// </summary>
|
||||
/// <returns>The number of rows inserted, updated, or deleted. -1 for SELECT statements.</returns>
|
||||
public int ExecuteNonQuery()
|
||||
{
|
||||
return m_Command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
55
ICD.Common.Utils/Sqlite/IcdSqliteConnection.cs
Normal file
55
ICD.Common.Utils/Sqlite/IcdSqliteConnection.cs
Normal file
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the wrapped connection instance.
|
||||
/// </summary>
|
||||
public SqliteConnection WrappedConnection { get { return m_Connection; } }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="connectionString"></param>
|
||||
public IcdSqliteConnection(string connectionString)
|
||||
{
|
||||
m_Connection = new SqliteConnection(connectionString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new SQLite database file at the given path.
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
public static void CreateFile(string path)
|
||||
{
|
||||
IcdFileStream fs = IcdFile.Create(path);
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Release resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
m_Connection.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens a connection to the database.
|
||||
/// </summary>
|
||||
public void Open()
|
||||
{
|
||||
m_Connection.Open();
|
||||
}
|
||||
}
|
||||
}
|
||||
23
ICD.Common.Utils/Sqlite/IcdSqliteDataReader.cs
Normal file
23
ICD.Common.Utils/Sqlite/IcdSqliteDataReader.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
7
ICD.Common.Utils/Sqlite/IcdSqliteParameter.cs
Normal file
7
ICD.Common.Utils/Sqlite/IcdSqliteParameter.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace ICD.Common.Utils.Sqlite
|
||||
{
|
||||
public sealed class IcdSqliteParameter
|
||||
{
|
||||
public object Value { get; set; }
|
||||
}
|
||||
}
|
||||
30
ICD.Common.Utils/Sqlite/IcdSqliteParameterCollection.cs
Normal file
30
ICD.Common.Utils/Sqlite/IcdSqliteParameterCollection.cs
Normal file
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="commandParameters"></param>
|
||||
public IcdSqliteParameterCollection(SqliteParameterCollection commandParameters)
|
||||
{
|
||||
m_Parameters = commandParameters;
|
||||
}
|
||||
|
||||
|
||||
public IcdSqliteParameter Add(string name, eDbType type)
|
||||
{
|
||||
SqliteType
|
||||
|
||||
return new IcdSqliteParameter(m_Parameters.Add(name, type));
|
||||
}
|
||||
}
|
||||
}
|
||||
112
ICD.Common.Utils/Sqlite/eDbType.cs
Normal file
112
ICD.Common.Utils/Sqlite/eDbType.cs
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user