System.Data.SQLite
Check-in [7529b50e97]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Cleanup integration between the session extension classes and the SQLiteConnection class.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1: 7529b50e971e872f2f0c2feb4930b688086f8b2c
User & Date: mistachkin 2017-10-05 23:10:54
Context
2017-10-06
15:51
Further work on the SQLiteMemoryChangeSet class. check-in: 5dc5e48cb0 user: mistachkin tags: sessions
2017-10-05
23:10
Cleanup integration between the session extension classes and the SQLiteConnection class. check-in: 7529b50e97 user: mistachkin tags: sessions
22:55
The 'Apply' methods logically belong to the change set, not the session. check-in: baed0aa503 user: mistachkin tags: sessions
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite/SQLiteConnection.cs.

  3002   3002       /// Forwards to the local <see cref="CreateCommand" /> function.
  3003   3003       /// </summary>
  3004   3004       /// <returns></returns>
  3005   3005       protected override DbCommand CreateDbCommand()
  3006   3006       {
  3007   3007         return CreateCommand();
  3008   3008       }
         3009  +
         3010  +#if INTEROP_SESSION_EXTENSION
         3011  +    /// <summary>
         3012  +    /// Attempts to create a new <see cref="ISQLiteSession" /> object instance
         3013  +    /// using this connection and the specified database name.
         3014  +    /// </summary>
         3015  +    /// <param name="databaseName">
         3016  +    /// The name of the database for the newly created session.
         3017  +    /// </param>
         3018  +    /// <returns>
         3019  +    /// The newly created session -OR- null if it cannot be created.
         3020  +    /// </returns>
         3021  +    public ISQLiteSession CreateSession(
         3022  +        string databaseName
         3023  +        )
         3024  +    {
         3025  +        CheckDisposed();
         3026  +
         3027  +        return new SQLiteSession(GetNativeHandle(this), _flags, databaseName);
         3028  +    }
         3029  +
         3030  +    /// <summary>
         3031  +    /// Attempts to create a new <see cref="ISQLiteChangeSet" /> object instance
         3032  +    /// using this connection and the specified raw data.
         3033  +    /// </summary>
         3034  +    /// <param name="rawData">
         3035  +    /// The raw data that contains a change set (or patch set).
         3036  +    /// </param>
         3037  +    /// <returns>
         3038  +    /// The newly created change set -OR- null if it cannot be created.
         3039  +    /// </returns>
         3040  +    public ISQLiteChangeSet CreateChangeSet(
         3041  +        byte[] rawData
         3042  +        )
         3043  +    {
         3044  +        CheckDisposed();
         3045  +
         3046  +        return new SQLiteMemoryChangeSet(
         3047  +            rawData, GetNativeHandle(this), _flags, null);
         3048  +    }
         3049  +
         3050  +    /// <summary>
         3051  +    /// Attempts to create a new <see cref="ISQLiteChangeSet" /> object instance
         3052  +    /// using this connection and the specified stream.
         3053  +    /// </summary>
         3054  +    /// <param name="stream">
         3055  +    /// The stream where the raw data that contains a change set (or patch set)
         3056  +    /// may be read.
         3057  +    /// </param>
         3058  +    /// <returns>
         3059  +    /// The newly created change set -OR- null if it cannot be created.
         3060  +    /// </returns>
         3061  +    public ISQLiteChangeSet CreateChangeSet(
         3062  +        Stream stream
         3063  +        )
         3064  +    {
         3065  +        CheckDisposed();
         3066  +
         3067  +        return new SQLiteStreamChangeSet(
         3068  +            stream, GetNativeHandle(this), _flags, null);
         3069  +    }
         3070  +#endif
  3009   3071   
  3010   3072       /// <summary>
  3011   3073       /// Returns the data source file name without extension or path.
  3012   3074       /// </summary>
  3013   3075   #if !PLATFORM_COMPACTFRAMEWORK
  3014   3076       [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  3015   3077   #endif

Changes to System.Data.SQLite/SQLiteSessions.cs.

   548    548   
   549    549       ///////////////////////////////////////////////////////////////////////////
   550    550   
   551    551       #region SQLiteSession Class
   552    552       public sealed class SQLiteSession : ISQLiteSession, IDisposable
   553    553       {
   554    554           #region Private Data
   555         -        private SQLiteConnection connection;
          555  +        private SQLiteConnectionHandle handle;
          556  +        private SQLiteConnectionFlags flags;
          557  +        private string databaseName;
   556    558           private IntPtr session;
   557    559   
   558    560           ///////////////////////////////////////////////////////////////////////
   559    561   
   560    562           private SessionTableFilterCallback tableFilterCallback;
   561    563           private object tableFilterClientData;
   562    564           #endregion
   563    565   
   564    566           ///////////////////////////////////////////////////////////////////////
   565    567   
   566         -        #region Public Constructors
   567         -        public SQLiteSession(
   568         -            SQLiteConnection connection,
          568  +        #region Private Constructors
          569  +        internal SQLiteSession(
          570  +            SQLiteConnectionHandle handle,
          571  +            SQLiteConnectionFlags flags,
   569    572               string databaseName
   570    573               )
   571    574           {
   572         -            this.connection = connection;
          575  +            this.handle = handle;
          576  +            this.flags = flags;
          577  +            this.databaseName = databaseName;
   573    578   
   574    579               UnsafeNativeMethods.sqlite3session_create(
   575         -                SQLiteConnection.GetNativeHandle(connection),
   576         -                SQLiteString.GetUtf8BytesFromString(databaseName),
          580  +                handle, SQLiteString.GetUtf8BytesFromString(databaseName),
   577    581                   ref session);
   578    582           }
   579    583           #endregion
   580    584   
   581    585           ///////////////////////////////////////////////////////////////////////
   582    586   
   583    587           #region Private Methods
   584    588           private void CheckHandle()
   585    589           {
   586    590               if (session == IntPtr.Zero)
   587    591                   throw new InvalidOperationException("session is not open");
   588    592           }
   589    593   
   590         -        ///////////////////////////////////////////////////////////////////////
   591         -
   592         -        private SQLiteConnectionFlags GetConnectionFlags()
   593         -        {
   594         -            return SQLiteConnectionFlags.None;
   595         -        }
   596         -
   597    594           ///////////////////////////////////////////////////////////////////////
   598    595   
   599    596           #region Native Callback Methods
   600    597           private int xFilter(
   601    598               IntPtr context, /* NOT USED */
   602    599               byte[] tblName
   603    600               )
................................................................................
   748    745           public void CreateChangeSet(
   749    746               Stream stream
   750    747               )
   751    748           {
   752    749               CheckDisposed();
   753    750               CheckHandle();
   754    751   
   755         -            SQLiteConnectionFlags flags = GetConnectionFlags();
   756         -
   757    752               SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3session_changeset_strm(
   758    753                   session, new SQLiteStreamAdapter(stream, flags).xOutput,
   759    754                   IntPtr.Zero);
   760    755   
   761    756               if (rc != SQLiteErrorCode.Ok)
   762    757                   throw new SQLiteException(rc, "sqlite3session_changeset_strm");
   763    758           }
................................................................................
   800    795           public void CreatePatchSet(
   801    796               Stream stream
   802    797               )
   803    798           {
   804    799               CheckDisposed();
   805    800               CheckHandle();
   806    801   
   807         -            SQLiteConnectionFlags flags = GetConnectionFlags();
   808         -
   809    802               SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3session_patchset_strm(
   810    803                   session, new SQLiteStreamAdapter(stream, flags).xOutput,
   811    804                   IntPtr.Zero);
   812    805   
   813    806               if (rc != SQLiteErrorCode.Ok)
   814    807                   throw new SQLiteException(rc, "sqlite3session_patchset_strm");
   815    808           }