--- /dev/null
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>netstandard2.0</TargetFramework>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\Tizen.Data.Tdbc\Tizen.Data.Tdbc.csproj" />
+ </ItemGroup>
+
+</Project>
--- /dev/null
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.5.33530.505
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Data.Tdbc.Driver.Sqlite", "Tizen.Data.Tdbc.Driver.Sqlite.csproj", "{FC293D2D-CA32-4AD3-A56C-48E1FF0555D5}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Data.Tdbc", "..\Tizen.Data.Tdbc\Tizen.Data.Tdbc.csproj", "{8D78BBA7-929D-49BC-B9A4-9CCCAE0F575D}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {FC293D2D-CA32-4AD3-A56C-48E1FF0555D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FC293D2D-CA32-4AD3-A56C-48E1FF0555D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FC293D2D-CA32-4AD3-A56C-48E1FF0555D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FC293D2D-CA32-4AD3-A56C-48E1FF0555D5}.Release|Any CPU.Build.0 = Release|Any CPU
+ {8D78BBA7-929D-49BC-B9A4-9CCCAE0F575D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {8D78BBA7-929D-49BC-B9A4-9CCCAE0F575D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {8D78BBA7-929D-49BC-B9A4-9CCCAE0F575D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {8D78BBA7-929D-49BC-B9A4-9CCCAE0F575D}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {94BD2441-EBE3-471F-B231-B14EED0514A5}
+ EndGlobalSection
+EndGlobal
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.ComponentModel;
+using System.Linq;
+
+namespace Tizen.Data.Tdbc.Driver.Sqlite
+{
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ internal class Connection : IConnection
+ {
+ private bool _opened;
+ private IntPtr _db;
+ private bool disposedValue;
+ private readonly object _lock = new object();
+ private EventHandler<RecordChangedEventArgs> _recordChanged;
+
+
+ static Connection()
+ {
+ Interop.Sqlite.Init();
+ }
+
+ public Connection()
+ {
+ }
+
+ public event EventHandler<RecordChangedEventArgs> RecordChanged
+ {
+ add
+ {
+ lock (_lock)
+ {
+ _recordChanged += value;
+ }
+ }
+
+ remove
+ {
+ lock (_lock)
+ {
+ _recordChanged -= value;
+ }
+ }
+ }
+
+ public void Open(String openString)
+ {
+ Open(new Uri(openString));
+ }
+
+ public void Close()
+ {
+ if (_opened)
+ {
+ Interop.Sqlite.UpdateHook(_db, null, IntPtr.Zero);
+ Interop.Sqlite.Close(_db);
+ _opened = false;
+ }
+ }
+
+ private void UpdateHookCallback(IntPtr data, int action, string db_name, string table_name, long rowid)
+ {
+ OperationType operationType = OperationType.None;
+ switch (((Interop.Sqlite.UpdateHookAction)action))
+ {
+ case Interop.Sqlite.UpdateHookAction.SQLITE_UPDATE:
+ operationType = OperationType.Update;
+ break;
+ case Interop.Sqlite.UpdateHookAction.SQLITE_INSERT:
+ operationType = OperationType.Insert;
+ break;
+ case Interop.Sqlite.UpdateHookAction.SQLITE_DELETE:
+ operationType = OperationType.Delete;
+ break;
+ }
+
+ Sql sql = new Sql(string.Format("SELECT * from {0} WHERE rowid = {1}", table_name, rowid));
+ IRecord record = CreateStatement().ExecuteQuery(sql).FirstOrDefault();
+
+ RecordChangedEventArgs ev = new RecordChangedEventArgs(operationType, db_name, table_name, record);
+ _recordChanged?.Invoke(this, ev);
+ }
+
+ internal IntPtr GetHandle()
+ {
+ return _db;
+ }
+
+ public void Open(Uri uri)
+ {
+ if (IsOpen())
+ return;
+
+ if (uri.Scheme != "tdbc")
+ throw new ArgumentException("Wrong scheme:" + uri.Scheme);
+
+ if (uri.Host != "localhost")
+ throw new ArgumentException("Host should be 'localhost':" + uri.Host);
+
+ string query = uri.Query;
+ var queryDictionary = System.Web.HttpUtility.ParseQueryString(query);
+ int mode = (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_READWRITE |
+ (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_CREATE;
+
+ if (queryDictionary.Get("mode") == "ro")
+ {
+ mode = (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_READONLY;
+ }
+ else if (queryDictionary.Get("mode") == "rw")
+ {
+ mode = (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_READWRITE;
+ }
+ else if (queryDictionary.Get("mode") == "rwc")
+ {
+ mode = (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_READWRITE |
+ (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_CREATE;
+ }
+ else if (queryDictionary.Get("mode") == "memory")
+ {
+ mode = (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_MEMORY;
+ }
+
+ if (queryDictionary.Get("cache") == "shared")
+ {
+ mode |= (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_SHAREDCACHE;
+ }
+ else if (queryDictionary.Get("cache") == "private")
+ {
+ mode |= (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_PRIVATECACHE;
+ }
+
+ int ret = Interop.Sqlite.OpenV2(uri.LocalPath, out _db, mode, IntPtr.Zero);
+ if (ret != (int)Interop.Sqlite.ResultCode.SQLITE_OK)
+ throw new InvalidOperationException("code:" + ret);
+
+ Interop.Sqlite.UpdateHook(_db, UpdateHookCallback, IntPtr.Zero);
+ _opened = true;
+ }
+
+ public IStatement CreateStatement()
+ {
+ if (!IsOpen())
+ throw new InvalidOperationException("Not opened");
+
+ return new Statement(this);
+ }
+
+ public bool IsOpen()
+ {
+ return _opened;
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!disposedValue)
+ {
+ if (disposing)
+ {
+ }
+
+ if (_opened)
+ Close();
+ disposedValue = true;
+ }
+ }
+
+ ~Connection()
+ {
+ Dispose(disposing: false);
+ }
+
+ public void Dispose()
+ {
+ Dispose(disposing: true);
+ GC.SuppressFinalize(this);
+ }
+ }
+}
--- /dev/null
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ const string Lib = "libsqlite3.so.0";
+
+ internal static partial class Sqlite
+ {
+ internal static void Init()
+ {
+ }
+
+ [Flags]
+ internal enum OpenParameter : int
+ {
+ SQLITE_OPEN_READONLY = 0x00000001,
+ SQLITE_OPEN_READWRITE = 0x00000002,
+ SQLITE_OPEN_CREATE = 0x00000004,
+ SQLITE_OPEN_DELETEONCLOSE = 0x00000008,
+ SQLITE_OPEN_EXCLUSIVE = 0x00000010,
+ SQLITE_OPEN_AUTOPROXY = 0x00000020,
+ SQLITE_OPEN_URI = 0x00000040,
+ SQLITE_OPEN_MEMORY = 0x00000080,
+ SQLITE_OPEN_MAIN_DB = 0x00000100,
+ SQLITE_OPEN_TEMP_DB = 0x00000200,
+ SQLITE_OPEN_TRANSIENT_DB = 0x00000400,
+ SQLITE_OPEN_MAIN_JOURNAL = 0x00000800,
+ SQLITE_OPEN_TEMP_JOURNAL = 0x00001000,
+ SQLITE_OPEN_SUBJOURNAL = 0x00002000,
+ SQLITE_OPEN_MASTER_JOURNAL = 0x00004000,
+ SQLITE_OPEN_NOMUTEX = 0x00008000,
+ SQLITE_OPEN_FULLMUTEX = 0x00010000,
+ SQLITE_OPEN_SHAREDCACHE = 0x00020000,
+ SQLITE_OPEN_PRIVATECACHE = 0x00040000,
+ SQLITE_OPEN_WAL = 0x00080000
+ }
+
+ internal enum ResultCode : int
+ {
+ SQLITE_OK = 0,
+ SQLITE_ERROR = 1,
+ SQLITE_INTERNAL = 2,
+ SQLITE_PERM = 3,
+ SQLITE_ABORT = 4,
+ SQLITE_BUSY = 5,
+ SQLITE_LOCKED = 6,
+ SQLITE_NOMEM = 7,
+ SQLITE_READONLY = 8,
+ SQLITE_INTERRUPT = 9,
+ SQLITE_IOERR = 10,
+ SQLITE_CORRUPT = 11,
+ SQLITE_NOTFOUND = 12,
+ SQLITE_FULL = 13,
+ SQLITE_CANTOPEN = 14,
+ SQLITE_PROTOCOL = 15,
+ SQLITE_EMPTY = 16,
+ SQLITE_SCHEMA = 17,
+ SQLITE_TOOBIG = 18,
+ SQLITE_CONSTRAINT = 19,
+ SQLITE_MISMATCH = 20,
+ SQLITE_MISUSE = 21,
+ SQLITE_NOLFS = 22,
+ SQLITE_AUTH = 23,
+ SQLITE_FORMAT = 24,
+ SQLITE_RANGE = 25,
+ SQLITE_NOTADB = 26,
+ SQLITE_NOTICE = 27,
+ SQLITE_WARNING = 28,
+ SQLITE_ROW = 100,
+ SQLITE_DONE = 101
+ }
+
+ //int sqlite3_open_v2(const char* filename, sqlite3** ppDb, int flags, const char* zVfs)
+ [DllImport(Lib, EntryPoint = "sqlite3_open_v2")]
+ internal static extern int OpenV2(string filename, out IntPtr ppDb, int flags, IntPtr zVfs);
+
+ //int sqlite3_close_v2(sqlite3*)
+ [DllImport(Lib, EntryPoint = "sqlite3_close_v2")]
+ internal static extern int Close(IntPtr pDb);
+
+ //int sqlite3_prepare_v2(sqlite3* db, const char* zSql, int nByte, sqlite3_stmt** ppStmt, const char** pzTail)
+ [DllImport(Lib, EntryPoint = "sqlite3_prepare_v2")]
+ internal static extern int Prepare(IntPtr pDb, string zSql, int nByte, out IntPtr ppStmt, IntPtr pzTail);
+
+ //int sqlite3_bind_text(sqlite3_stmt*, int,const char*,int,void (*) (void*));
+ [DllImport(Lib, EntryPoint = "sqlite3_bind_text")]
+ internal static extern int BindText(IntPtr stmt, int pos, string text, int size, IntPtr mode);
+
+ //int sqlite3_bind_int(sqlite3_stmt*, int, int);
+ [DllImport(Lib, EntryPoint = "sqlite3_bind_int")]
+ internal static extern int BindInt(IntPtr stmt, int pos, int val);
+
+ //int sqlite3_bind_double(sqlite3_stmt*, int, double);
+ [DllImport(Lib, EntryPoint = "sqlite3_bind_double")]
+ internal static extern int BindDouble(IntPtr stmt, int pos, double val);
+
+ //int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void (*) (void*));
+ [DllImport(Lib, EntryPoint = "sqlite3_bind_blob")]
+ internal static extern int BindData(IntPtr stmt, int pos, byte[] val, int size, IntPtr mode);
+
+ //int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
+ [DllImport(Lib, EntryPoint = "sqlite3_bind_parameter_index")]
+ internal static extern int GetParameterIndex(IntPtr stmt, string zName);
+
+ //int sqlite3_step(sqlite3_stmt*)
+ [DllImport(Lib, EntryPoint = "sqlite3_step")]
+ internal static extern int Step(IntPtr stmt);
+
+ //int sqlite3_finalize(sqlite3_stmt *pStmt);
+ [DllImport(Lib, EntryPoint = "sqlite3_finalize")]
+ internal static extern int Finalize(IntPtr stmt);
+
+ //int sqlite3_changes(sqlite3*)
+ [DllImport(Lib, EntryPoint = "sqlite3_changes")]
+ internal static extern int Changes(IntPtr db);
+
+ //const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
+ [DllImport(Lib, EntryPoint = "sqlite3_column_text")]
+ internal static extern IntPtr ColumnText(IntPtr stmt, int col);
+
+ //int sqlite3_column_int(sqlite3_stmt*, int iCol);
+ [DllImport(Lib, EntryPoint = "sqlite3_column_int")]
+ internal static extern int ColumnInt(IntPtr stmt, int col);
+
+ //double sqlite3_column_double(sqlite3_stmt*, int iCol);
+ [DllImport(Lib, EntryPoint = "sqlite3_column_double")]
+ internal static extern double ColumnDouble(IntPtr stmt, int col);
+
+ //const void* sqlite3_column_blob(sqlite3_stmt *, int iCol);
+ [DllImport(Lib, EntryPoint = "sqlite3_column_blob")]
+ internal static extern IntPtr ColumnBlob(IntPtr stmt, int col);
+
+ //int sqlite3_reset(sqlite3_stmt* pStmt);
+ [DllImport(Lib, EntryPoint = "sqlite3_reset")]
+ internal static extern int Reset(IntPtr stmt);
+
+ //int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
+ [DllImport(Lib, EntryPoint = "sqlite3_column_bytes")]
+ internal static extern int ColumnBytes(IntPtr stmt, int col);
+
+ internal enum UpdateHookAction : int
+ {
+ SQLITE_DELETE = 9,
+ SQLITE_INSERT = 18,
+ SQLITE_UPDATE = 23
+ }
+
+ internal delegate void UpdateHookCallback(IntPtr data, int action, string db_name, string table_name, long rowid);
+
+ //void* sqlite3_update_hook(sqlite3*, void(*)(void* data, int action, char const* db_name, char const* table_name, sqlite3_int64 rowid), void* data);
+ [DllImport(Lib, EntryPoint = "sqlite3_update_hook")]
+ internal static extern IntPtr UpdateHook(IntPtr db, UpdateHookCallback cb, IntPtr data);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Runtime.InteropServices;
+
+namespace Tizen.Data.Tdbc.Driver.Sqlite
+{
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ internal class Record : IRecord
+ {
+ private IntPtr _stmt;
+ IRecord IEnumerator<IRecord>.Current => this;
+ public object Current => this.Current;
+
+ internal Record(IntPtr stmt)
+ {
+ _stmt = stmt;
+ }
+
+ public bool MoveNext()
+ {
+ int ret = Interop.Sqlite.Step(_stmt);
+ if (ret != (int)Interop.Sqlite.ResultCode.SQLITE_ROW)
+ return false;
+
+ return true;
+ }
+
+ public void Reset()
+ {
+ Interop.Sqlite.Reset(_stmt);
+ }
+
+ public bool GetBool(int columnIndex)
+ {
+ int ret = Interop.Sqlite.ColumnInt(_stmt, columnIndex);
+ if (ret == 0)
+ return false;
+ return true;
+ }
+
+ public byte[] GetData(int columnIndex)
+ {
+ IntPtr raw = Interop.Sqlite.ColumnBlob(_stmt, columnIndex);
+ if (raw == IntPtr.Zero)
+ return null;
+
+ int size = Interop.Sqlite.ColumnBytes(_stmt, columnIndex);
+ byte[] ret = new byte[size];
+ Marshal.Copy((IntPtr)raw, (byte[])ret, 0, (int)size);
+
+ return ret;
+ }
+
+ public double GetDouble(int columnIndex)
+ {
+ return Interop.Sqlite.ColumnDouble(_stmt, columnIndex);
+ }
+
+ public int GetInt(int columnIndex)
+ {
+ return Interop.Sqlite.ColumnInt(_stmt, columnIndex);
+ }
+
+ public string GetString(int columnIndex)
+ {
+ IntPtr raw = Interop.Sqlite.ColumnText(_stmt, columnIndex);
+
+ return Marshal.PtrToStringAnsi(raw);
+ }
+
+ public char GetChar(int columnIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ public char[] GetChars(int columnIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ public DateTime GetDate(int columnIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ public DateTime GetDateTime(int columnIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ public decimal GetDecimal(int columnIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ public float GetFloat(int columnIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ public short GetInt16(int columnIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ public long GetInt64(int columnIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ public TimeSpan GetTime(int columnIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ public string GetName(int columnIndex)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Dispose()
+ {
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.ComponentModel;
+
+namespace Tizen.Data.Tdbc.Driver.Sqlite
+{
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ internal class ResultSet : IResultSet
+ {
+ private IntPtr _stmt;
+ private bool disposedValue;
+ private Connection _conn;
+
+ private void Clear()
+ {
+ if (_stmt != IntPtr.Zero)
+ {
+ Interop.Sqlite.Finalize(_stmt);
+ _stmt = IntPtr.Zero;
+ }
+ }
+
+ internal ResultSet(IntPtr stmt, Connection conn)
+ {
+ _stmt = stmt;
+ _conn = conn;
+ }
+
+ public IEnumerator<IRecord> GetEnumerator()
+ {
+ return new Record(_stmt);
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return this.GetEnumerator();
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!disposedValue)
+ {
+ if (disposing)
+ {
+ }
+
+ Clear();
+ disposedValue = true;
+ }
+ }
+
+ ~ResultSet()
+ {
+ Dispose(disposing: false);
+ }
+
+ public void Dispose()
+ {
+ Dispose(disposing: true);
+ GC.SuppressFinalize(this);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.ComponentModel;
+using System.Threading.Tasks;
+
+namespace Tizen.Data.Tdbc.Driver.Sqlite
+{
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class Statement : IStatement
+ {
+ Connection _conn;
+ private IntPtr _stmt;
+ private bool disposedValue;
+
+ private void Clear()
+ {
+ if (_stmt != IntPtr.Zero)
+ {
+ Interop.Sqlite.Finalize(_stmt);
+ _stmt = IntPtr.Zero;
+ }
+ }
+
+ private bool Prepare(Sql sql)
+ {
+ Clear();
+ Console.WriteLine("Prepare: " + sql.Command);
+ int ret = Interop.Sqlite.Prepare(_conn.GetHandle(), sql.Command, -1, out _stmt, IntPtr.Zero);
+ if (ret != (int)Interop.Sqlite.ResultCode.SQLITE_OK)
+ {
+ Console.WriteLine("Prepare: failed " + ret);
+ return false;
+ }
+
+ foreach (var i in sql.Bindings)
+ {
+ string key = i.Key;
+ Object obj = i.Value;
+ int pos = Interop.Sqlite.GetParameterIndex(_stmt, key);
+ if (pos == 0)
+ throw new InvalidOperationException("Invalid binding");
+
+ if (typeof(int) == obj.GetType())
+ {
+ Interop.Sqlite.BindInt(_stmt, pos, (int)obj);
+ }
+ else if (typeof(bool) == obj.GetType())
+ {
+ bool val = (bool)obj;
+ Interop.Sqlite.BindInt(_stmt, pos, val ? 1 : 0);
+ }
+ else if (typeof(double) == obj.GetType())
+ {
+ Interop.Sqlite.BindDouble(_stmt, pos, (double)obj);
+ }
+ else if (typeof(string) == obj.GetType())
+ {
+ Interop.Sqlite.BindText(_stmt, pos, (string)obj, -1, (IntPtr)(-1));
+ }
+ else if (typeof(byte[]) == obj.GetType())
+ {
+ if (obj != null)
+ Interop.Sqlite.BindData(_stmt, pos, (byte[])obj, ((byte[])obj).Length, IntPtr.Zero);
+ }
+ }
+
+ return true;
+ }
+
+ internal Statement(Connection conn)
+ {
+ _conn = conn;
+ }
+
+ public bool Execute(Sql sql)
+ {
+ if (!Prepare(sql))
+ return false;
+ int ret = Interop.Sqlite.Step(_stmt);
+ Console.WriteLine("Execute: " + ret);
+ if (ret != (int)Interop.Sqlite.ResultCode.SQLITE_ROW &&
+ ret != (int)Interop.Sqlite.ResultCode.SQLITE_DONE)
+ return false;
+ return true;
+ }
+
+ public int ExecuteUpdate(Sql sql)
+ {
+ if (!Prepare(sql))
+ return 0;
+ int ret = Interop.Sqlite.Step(_stmt);
+ if (ret != (int)Interop.Sqlite.ResultCode.SQLITE_ROW &&
+ ret != (int)Interop.Sqlite.ResultCode.SQLITE_DONE)
+ return 0;
+ return Interop.Sqlite.Changes(_conn.GetHandle());
+ }
+
+ public IResultSet ExecuteQuery(Sql sql)
+ {
+ bool prepared = Prepare(sql);
+
+ if (!prepared)
+ throw new InvalidOperationException("Couldn't prepare");
+
+ var set = new ResultSet(_stmt, _conn);
+ _stmt = IntPtr.Zero;
+
+ return set;
+ }
+
+ public async Task<IResultSet> ExecuteQueryAsync(Sql sql)
+ {
+ return await Task.Run(() =>
+ {
+ return ExecuteQuery(sql);
+ }).ConfigureAwait(false);
+ }
+
+ public async Task<int> ExecuteUpdateAsync(Sql sql)
+ {
+ return await Task.Run(() =>
+ {
+ return ExecuteUpdate(sql);
+ }).ConfigureAwait(false);
+ }
+
+ public async Task<bool> ExecuteAsync(Sql sql)
+ {
+ return await Task.Run(() =>
+ {
+ return Execute(sql);
+ }).ConfigureAwait(false);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!disposedValue)
+ {
+ if (disposing)
+ {
+ }
+
+ Clear();
+ disposedValue = true;
+ }
+ }
+
+ ~Statement()
+ {
+ Dispose(disposing: false);
+ }
+
+ public void Dispose()
+ {
+ Dispose(disposing: true);
+ GC.SuppressFinalize(this);
+ }
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-using System;
-using System.ComponentModel;
-using System.Linq;
-
-namespace Tizen.Data.Tdbc.Driver.Sqlite
-{
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal class Connection : IConnection
- {
- private bool _opened;
- private IntPtr _db;
- private bool disposedValue;
- private readonly object _lock = new object();
- private EventHandler<RecordChangedEventArgs> _recordChanged;
-
-
- static Connection()
- {
- Interop.Sqlite.Init();
- }
-
- public Connection()
- {
- }
-
- public event EventHandler<RecordChangedEventArgs> RecordChanged
- {
- add
- {
- lock (_lock)
- {
- _recordChanged += value;
- }
- }
-
- remove
- {
- lock (_lock)
- {
- _recordChanged -= value;
- }
- }
- }
-
- public void Open(String openString)
- {
- Open(new Uri(openString));
- }
-
- public void Close()
- {
- if (_opened)
- {
- Interop.Sqlite.UpdateHook(_db, null, IntPtr.Zero);
- Interop.Sqlite.Close(_db);
- _opened = false;
- }
- }
-
- private void UpdateHookCallback(IntPtr data, int action, string db_name, string table_name, long rowid)
- {
- OperationType operationType = OperationType.None;
- switch (((Interop.Sqlite.UpdateHookAction)action))
- {
- case Interop.Sqlite.UpdateHookAction.SQLITE_UPDATE:
- operationType = OperationType.Update;
- break;
- case Interop.Sqlite.UpdateHookAction.SQLITE_INSERT:
- operationType = OperationType.Insert;
- break;
- case Interop.Sqlite.UpdateHookAction.SQLITE_DELETE:
- operationType = OperationType.Delete;
- break;
- }
-
- Sql sql = new Sql(string.Format("SELECT * from {0} WHERE rowid = {1}", table_name, rowid));
- IRecord record = CreateStatement().ExecuteQuery(sql).FirstOrDefault();
-
- RecordChangedEventArgs ev = new RecordChangedEventArgs(operationType, db_name, table_name, record);
- _recordChanged?.Invoke(this, ev);
- }
-
- internal IntPtr GetHandle()
- {
- return _db;
- }
-
- public void Open(Uri uri)
- {
- if (IsOpen())
- return;
-
- if (uri.Scheme != "tdbc")
- throw new ArgumentException("Wrong scheme:" + uri.Scheme);
-
- if (uri.Host != "localhost")
- throw new ArgumentException("Host should be 'localhost':" + uri.Host);
-
- string query = uri.Query;
- var queryDictionary = System.Web.HttpUtility.ParseQueryString(query);
- int mode = (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_READWRITE |
- (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_CREATE;
-
- if (queryDictionary.Get("mode") == "ro")
- {
- mode = (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_READONLY;
- }
- else if (queryDictionary.Get("mode") == "rw")
- {
- mode = (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_READWRITE;
- }
- else if (queryDictionary.Get("mode") == "rwc")
- {
- mode = (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_READWRITE |
- (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_CREATE;
- }
- else if (queryDictionary.Get("mode") == "memory")
- {
- mode = (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_MEMORY;
- }
-
- if (queryDictionary.Get("cache") == "shared")
- {
- mode |= (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_SHAREDCACHE;
- }
- else if (queryDictionary.Get("cache") == "private")
- {
- mode |= (int)Interop.Sqlite.OpenParameter.SQLITE_OPEN_PRIVATECACHE;
- }
-
- int ret = Interop.Sqlite.OpenV2(uri.LocalPath, out _db, mode, IntPtr.Zero);
- if (ret != (int)Interop.Sqlite.ResultCode.SQLITE_OK)
- throw new InvalidOperationException("code:" + ret);
-
- Interop.Sqlite.UpdateHook(_db, UpdateHookCallback, IntPtr.Zero);
- _opened = true;
- }
-
- public IStatement CreateStatement()
- {
- if (!IsOpen())
- throw new InvalidOperationException("Not opened");
-
- return new Statement(this);
- }
-
- public bool IsOpen()
- {
- return _opened;
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (!disposedValue)
- {
- if (disposing)
- {
- }
-
- if (_opened)
- Close();
- disposedValue = true;
- }
- }
-
- ~Connection()
- {
- Dispose(disposing: false);
- }
-
- public void Dispose()
- {
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
- }
-}
+++ /dev/null
-using System;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- const string Lib = "libsqlite3.so.0";
-
- internal static partial class Sqlite
- {
- internal static void Init()
- {
- }
-
- [Flags]
- internal enum OpenParameter : int
- {
- SQLITE_OPEN_READONLY = 0x00000001,
- SQLITE_OPEN_READWRITE = 0x00000002,
- SQLITE_OPEN_CREATE = 0x00000004,
- SQLITE_OPEN_DELETEONCLOSE = 0x00000008,
- SQLITE_OPEN_EXCLUSIVE = 0x00000010,
- SQLITE_OPEN_AUTOPROXY = 0x00000020,
- SQLITE_OPEN_URI = 0x00000040,
- SQLITE_OPEN_MEMORY = 0x00000080,
- SQLITE_OPEN_MAIN_DB = 0x00000100,
- SQLITE_OPEN_TEMP_DB = 0x00000200,
- SQLITE_OPEN_TRANSIENT_DB = 0x00000400,
- SQLITE_OPEN_MAIN_JOURNAL = 0x00000800,
- SQLITE_OPEN_TEMP_JOURNAL = 0x00001000,
- SQLITE_OPEN_SUBJOURNAL = 0x00002000,
- SQLITE_OPEN_MASTER_JOURNAL = 0x00004000,
- SQLITE_OPEN_NOMUTEX = 0x00008000,
- SQLITE_OPEN_FULLMUTEX = 0x00010000,
- SQLITE_OPEN_SHAREDCACHE = 0x00020000,
- SQLITE_OPEN_PRIVATECACHE = 0x00040000,
- SQLITE_OPEN_WAL = 0x00080000
- }
-
- internal enum ResultCode : int
- {
- SQLITE_OK = 0,
- SQLITE_ERROR = 1,
- SQLITE_INTERNAL = 2,
- SQLITE_PERM = 3,
- SQLITE_ABORT = 4,
- SQLITE_BUSY = 5,
- SQLITE_LOCKED = 6,
- SQLITE_NOMEM = 7,
- SQLITE_READONLY = 8,
- SQLITE_INTERRUPT = 9,
- SQLITE_IOERR = 10,
- SQLITE_CORRUPT = 11,
- SQLITE_NOTFOUND = 12,
- SQLITE_FULL = 13,
- SQLITE_CANTOPEN = 14,
- SQLITE_PROTOCOL = 15,
- SQLITE_EMPTY = 16,
- SQLITE_SCHEMA = 17,
- SQLITE_TOOBIG = 18,
- SQLITE_CONSTRAINT = 19,
- SQLITE_MISMATCH = 20,
- SQLITE_MISUSE = 21,
- SQLITE_NOLFS = 22,
- SQLITE_AUTH = 23,
- SQLITE_FORMAT = 24,
- SQLITE_RANGE = 25,
- SQLITE_NOTADB = 26,
- SQLITE_NOTICE = 27,
- SQLITE_WARNING = 28,
- SQLITE_ROW = 100,
- SQLITE_DONE = 101
- }
-
- //int sqlite3_open_v2(const char* filename, sqlite3** ppDb, int flags, const char* zVfs)
- [DllImport(Lib, EntryPoint = "sqlite3_open_v2")]
- internal static extern int OpenV2(string filename, out IntPtr ppDb, int flags, IntPtr zVfs);
-
- //int sqlite3_close_v2(sqlite3*)
- [DllImport(Lib, EntryPoint = "sqlite3_close_v2")]
- internal static extern int Close(IntPtr pDb);
-
- //int sqlite3_prepare_v2(sqlite3* db, const char* zSql, int nByte, sqlite3_stmt** ppStmt, const char** pzTail)
- [DllImport(Lib, EntryPoint = "sqlite3_prepare_v2")]
- internal static extern int Prepare(IntPtr pDb, string zSql, int nByte, out IntPtr ppStmt, IntPtr pzTail);
-
- //int sqlite3_bind_text(sqlite3_stmt*, int,const char*,int,void (*) (void*));
- [DllImport(Lib, EntryPoint = "sqlite3_bind_text")]
- internal static extern int BindText(IntPtr stmt, int pos, string text, int size, IntPtr mode);
-
- //int sqlite3_bind_int(sqlite3_stmt*, int, int);
- [DllImport(Lib, EntryPoint = "sqlite3_bind_int")]
- internal static extern int BindInt(IntPtr stmt, int pos, int val);
-
- //int sqlite3_bind_double(sqlite3_stmt*, int, double);
- [DllImport(Lib, EntryPoint = "sqlite3_bind_double")]
- internal static extern int BindDouble(IntPtr stmt, int pos, double val);
-
- //int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void (*) (void*));
- [DllImport(Lib, EntryPoint = "sqlite3_bind_blob")]
- internal static extern int BindData(IntPtr stmt, int pos, byte[] val, int size, IntPtr mode);
-
- //int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
- [DllImport(Lib, EntryPoint = "sqlite3_bind_parameter_index")]
- internal static extern int GetParameterIndex(IntPtr stmt, string zName);
-
- //int sqlite3_step(sqlite3_stmt*)
- [DllImport(Lib, EntryPoint = "sqlite3_step")]
- internal static extern int Step(IntPtr stmt);
-
- //int sqlite3_finalize(sqlite3_stmt *pStmt);
- [DllImport(Lib, EntryPoint = "sqlite3_finalize")]
- internal static extern int Finalize(IntPtr stmt);
-
- //int sqlite3_changes(sqlite3*)
- [DllImport(Lib, EntryPoint = "sqlite3_changes")]
- internal static extern int Changes(IntPtr db);
-
- //const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
- [DllImport(Lib, EntryPoint = "sqlite3_column_text")]
- internal static extern IntPtr ColumnText(IntPtr stmt, int col);
-
- //int sqlite3_column_int(sqlite3_stmt*, int iCol);
- [DllImport(Lib, EntryPoint = "sqlite3_column_int")]
- internal static extern int ColumnInt(IntPtr stmt, int col);
-
- //double sqlite3_column_double(sqlite3_stmt*, int iCol);
- [DllImport(Lib, EntryPoint = "sqlite3_column_double")]
- internal static extern double ColumnDouble(IntPtr stmt, int col);
-
- //const void* sqlite3_column_blob(sqlite3_stmt *, int iCol);
- [DllImport(Lib, EntryPoint = "sqlite3_column_blob")]
- internal static extern IntPtr ColumnBlob(IntPtr stmt, int col);
-
- //int sqlite3_reset(sqlite3_stmt* pStmt);
- [DllImport(Lib, EntryPoint = "sqlite3_reset")]
- internal static extern int Reset(IntPtr stmt);
-
- //int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
- [DllImport(Lib, EntryPoint = "sqlite3_column_bytes")]
- internal static extern int ColumnBytes(IntPtr stmt, int col);
-
- internal enum UpdateHookAction : int
- {
- SQLITE_DELETE = 9,
- SQLITE_INSERT = 18,
- SQLITE_UPDATE = 23
- }
-
- internal delegate void UpdateHookCallback(IntPtr data, int action, string db_name, string table_name, long rowid);
-
- //void* sqlite3_update_hook(sqlite3*, void(*)(void* data, int action, char const* db_name, char const* table_name, sqlite3_int64 rowid), void* data);
- [DllImport(Lib, EntryPoint = "sqlite3_update_hook")]
- internal static extern IntPtr UpdateHook(IntPtr db, UpdateHookCallback cb, IntPtr data);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Runtime.InteropServices;
-
-namespace Tizen.Data.Tdbc.Driver.Sqlite
-{
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal class Record : IRecord
- {
- private IntPtr _stmt;
- IRecord IEnumerator<IRecord>.Current => this;
- public object Current => this.Current;
-
- internal Record(IntPtr stmt)
- {
- _stmt = stmt;
- }
-
- public bool MoveNext()
- {
- int ret = Interop.Sqlite.Step(_stmt);
- if (ret != (int)Interop.Sqlite.ResultCode.SQLITE_ROW)
- return false;
-
- return true;
- }
-
- public void Reset()
- {
- Interop.Sqlite.Reset(_stmt);
- }
-
- public bool GetBool(int columnIndex)
- {
- int ret = Interop.Sqlite.ColumnInt(_stmt, columnIndex);
- if (ret == 0)
- return false;
- return true;
- }
-
- public byte[] GetData(int columnIndex)
- {
- IntPtr raw = Interop.Sqlite.ColumnBlob(_stmt, columnIndex);
- if (raw == IntPtr.Zero)
- return null;
-
- int size = Interop.Sqlite.ColumnBytes(_stmt, columnIndex);
- byte[] ret = new byte[size];
- Marshal.Copy((IntPtr)raw, (byte[])ret, 0, (int)size);
-
- return ret;
- }
-
- public double GetDouble(int columnIndex)
- {
- return Interop.Sqlite.ColumnDouble(_stmt, columnIndex);
- }
-
- public int GetInt(int columnIndex)
- {
- return Interop.Sqlite.ColumnInt(_stmt, columnIndex);
- }
-
- public string GetString(int columnIndex)
- {
- IntPtr raw = Interop.Sqlite.ColumnText(_stmt, columnIndex);
-
- return Marshal.PtrToStringAnsi(raw);
- }
-
- public char GetChar(int columnIndex)
- {
- throw new NotImplementedException();
- }
-
- public char[] GetChars(int columnIndex)
- {
- throw new NotImplementedException();
- }
-
- public DateTime GetDate(int columnIndex)
- {
- throw new NotImplementedException();
- }
-
- public DateTime GetDateTime(int columnIndex)
- {
- throw new NotImplementedException();
- }
-
- public decimal GetDecimal(int columnIndex)
- {
- throw new NotImplementedException();
- }
-
- public float GetFloat(int columnIndex)
- {
- throw new NotImplementedException();
- }
-
- public short GetInt16(int columnIndex)
- {
- throw new NotImplementedException();
- }
-
- public long GetInt64(int columnIndex)
- {
- throw new NotImplementedException();
- }
-
- public TimeSpan GetTime(int columnIndex)
- {
- throw new NotImplementedException();
- }
-
- public string GetName(int columnIndex)
- {
- throw new NotImplementedException();
- }
-
- public void Dispose()
- {
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.ComponentModel;
-
-namespace Tizen.Data.Tdbc.Driver.Sqlite
-{
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal class ResultSet : IResultSet
- {
- private IntPtr _stmt;
- private bool disposedValue;
- private Connection _conn;
-
- private void Clear()
- {
- if (_stmt != IntPtr.Zero)
- {
- Interop.Sqlite.Finalize(_stmt);
- _stmt = IntPtr.Zero;
- }
- }
-
- internal ResultSet(IntPtr stmt, Connection conn)
- {
- _stmt = stmt;
- _conn = conn;
- }
-
- public IEnumerator<IRecord> GetEnumerator()
- {
- return new Record(_stmt);
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return this.GetEnumerator();
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (!disposedValue)
- {
- if (disposing)
- {
- }
-
- Clear();
- disposedValue = true;
- }
- }
-
- ~ResultSet()
- {
- Dispose(disposing: false);
- }
-
- public void Dispose()
- {
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-using System;
-using System.ComponentModel;
-using System.Threading.Tasks;
-
-namespace Tizen.Data.Tdbc.Driver.Sqlite
-{
- [EditorBrowsable(EditorBrowsableState.Never)]
- public class Statement : IStatement
- {
- Connection _conn;
- private IntPtr _stmt;
- private bool disposedValue;
-
- private void Clear()
- {
- if (_stmt != IntPtr.Zero)
- {
- Interop.Sqlite.Finalize(_stmt);
- _stmt = IntPtr.Zero;
- }
- }
-
- private bool Prepare(Sql sql)
- {
- Clear();
- Console.WriteLine("Prepare: " + sql.Command);
- int ret = Interop.Sqlite.Prepare(_conn.GetHandle(), sql.Command, -1, out _stmt, IntPtr.Zero);
- if (ret != (int)Interop.Sqlite.ResultCode.SQLITE_OK)
- {
- Console.WriteLine("Prepare: failed " + ret);
- return false;
- }
-
- foreach (var i in sql.Bindings)
- {
- string key = i.Key;
- Object obj = i.Value;
- int pos = Interop.Sqlite.GetParameterIndex(_stmt, key);
- if (pos == 0)
- throw new InvalidOperationException("Invalid binding");
-
- if (typeof(int) == obj.GetType())
- {
- Interop.Sqlite.BindInt(_stmt, pos, (int)obj);
- }
- else if (typeof(bool) == obj.GetType())
- {
- bool val = (bool)obj;
- Interop.Sqlite.BindInt(_stmt, pos, val ? 1 : 0);
- }
- else if (typeof(double) == obj.GetType())
- {
- Interop.Sqlite.BindDouble(_stmt, pos, (double)obj);
- }
- else if (typeof(string) == obj.GetType())
- {
- Interop.Sqlite.BindText(_stmt, pos, (string)obj, -1, (IntPtr)(-1));
- }
- else if (typeof(byte[]) == obj.GetType())
- {
- if (obj != null)
- Interop.Sqlite.BindData(_stmt, pos, (byte[])obj, ((byte[])obj).Length, IntPtr.Zero);
- }
- }
-
- return true;
- }
-
- internal Statement(Connection conn)
- {
- _conn = conn;
- }
-
- public bool Execute(Sql sql)
- {
- if (!Prepare(sql))
- return false;
- int ret = Interop.Sqlite.Step(_stmt);
- Console.WriteLine("Execute: " + ret);
- if (ret != (int)Interop.Sqlite.ResultCode.SQLITE_ROW &&
- ret != (int)Interop.Sqlite.ResultCode.SQLITE_DONE)
- return false;
- return true;
- }
-
- public int ExecuteUpdate(Sql sql)
- {
- if (!Prepare(sql))
- return 0;
- int ret = Interop.Sqlite.Step(_stmt);
- if (ret != (int)Interop.Sqlite.ResultCode.SQLITE_ROW &&
- ret != (int)Interop.Sqlite.ResultCode.SQLITE_DONE)
- return 0;
- return Interop.Sqlite.Changes(_conn.GetHandle());
- }
-
- public IResultSet ExecuteQuery(Sql sql)
- {
- bool prepared = Prepare(sql);
-
- if (!prepared)
- throw new InvalidOperationException("Couldn't prepare");
-
- var set = new ResultSet(_stmt, _conn);
- _stmt = IntPtr.Zero;
-
- return set;
- }
-
- public async Task<IResultSet> ExecuteQueryAsync(Sql sql)
- {
- return await Task.Run(() =>
- {
- return ExecuteQuery(sql);
- }).ConfigureAwait(false);
- }
-
- public async Task<int> ExecuteUpdateAsync(Sql sql)
- {
- return await Task.Run(() =>
- {
- return ExecuteUpdate(sql);
- }).ConfigureAwait(false);
- }
-
- public async Task<bool> ExecuteAsync(Sql sql)
- {
- return await Task.Run(() =>
- {
- return Execute(sql);
- }).ConfigureAwait(false);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (!disposedValue)
- {
- if (disposing)
- {
- }
-
- Clear();
- disposedValue = true;
- }
- }
-
- ~Statement()
- {
- Dispose(disposing: false);
- }
-
- public void Dispose()
- {
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
- }
-}
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
-
- <PropertyGroup>
- <TargetFramework>netstandard2.0</TargetFramework>
- </PropertyGroup>
-
- <ItemGroup>
- <ProjectReference Include="..\Tizen.Data.Tdbc\Tizen.Data.Tdbc.csproj" />
- </ItemGroup>
-
-</Project>
--- /dev/null
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>netstandard2.0</TargetFramework>
+ </PropertyGroup>
+
+</Project>
# Visual Studio Version 17
VisualStudioVersion = 17.3.32819.101
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Data.Tdbc", "Tizen.Data.Tdbc\Tizen.Data.Tdbc.csproj", "{218E5B96-2231-4C8A-9980-5858EDD84D29}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Data.Tdbc.Driver.Sqlite", "Tizen.Data.Tdbc.Driver.Sqlite\Tizen.Data.Tdbc.Driver.Sqlite.csproj", "{7798035E-735F-4489-9795-06A0918532FB}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Data.Tdbc", "Tizen.Data.Tdbc.csproj", "{93578DBF-ADA7-430E-A4AB-15A4DDF1748A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {218E5B96-2231-4C8A-9980-5858EDD84D29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {218E5B96-2231-4C8A-9980-5858EDD84D29}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {218E5B96-2231-4C8A-9980-5858EDD84D29}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {218E5B96-2231-4C8A-9980-5858EDD84D29}.Release|Any CPU.Build.0 = Release|Any CPU
- {7798035E-735F-4489-9795-06A0918532FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {7798035E-735F-4489-9795-06A0918532FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {7798035E-735F-4489-9795-06A0918532FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {7798035E-735F-4489-9795-06A0918532FB}.Release|Any CPU.Build.0 = Release|Any CPU
+ {93578DBF-ADA7-430E-A4AB-15A4DDF1748A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {93578DBF-ADA7-430E-A4AB-15A4DDF1748A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {93578DBF-ADA7-430E-A4AB-15A4DDF1748A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {93578DBF-ADA7-430E-A4AB-15A4DDF1748A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
-
- <PropertyGroup>
- <TargetFramework>netstandard2.0</TargetFramework>
- </PropertyGroup>
-
-</Project>