System.Data.SQLite
Check-in [e3f2fe8d85]
Not logged in

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

Overview
Comment:Create the metadata item for the xConflict callback.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1: e3f2fe8d85b01d6e61f54cc248a165ff9688d3e3
User & Date: mistachkin 2017-10-11 21:21:43
Context
2017-10-11
21:22
Add tests for Apply and CombineWith. check-in: d1def95f7b user: mistachkin tags: sessions
21:21
Create the metadata item for the xConflict callback. check-in: e3f2fe8d85 user: mistachkin tags: sessions
05:18
Wrap calls to the SessionTableFilterCallback delegate in a try/catch. check-in: 9c4784ee2f user: mistachkin tags: sessions
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

   398    398           #endregion
   399    399       }
   400    400       #endregion
   401    401   
   402    402       ///////////////////////////////////////////////////////////////////////////
   403    403   
   404    404       #region SQLiteChangeSetIterator Class
   405         -    internal abstract class SQLiteChangeSetIterator : IDisposable
          405  +    internal class SQLiteChangeSetIterator : IDisposable
   406    406       {
   407    407           #region Private Data
   408    408           private IntPtr iterator;
          409  +
          410  +        ///////////////////////////////////////////////////////////////////////
          411  +
          412  +        private bool ownHandle;
   409    413           #endregion
   410    414   
   411    415           ///////////////////////////////////////////////////////////////////////
   412    416   
   413    417           #region Protected Constructors
   414    418           protected SQLiteChangeSetIterator(
   415         -            IntPtr iterator
          419  +            IntPtr iterator,
          420  +            bool ownHandle
   416    421               )
   417    422           {
   418    423               this.iterator = iterator;
          424  +            this.ownHandle = ownHandle;
   419    425           }
   420    426           #endregion
   421    427   
   422    428           ///////////////////////////////////////////////////////////////////////
   423    429   
   424    430           #region Private Methods
   425    431           internal void CheckHandle()
................................................................................
   468    474                       }
   469    475               }
   470    476           }
   471    477           #endregion
   472    478   
   473    479           ///////////////////////////////////////////////////////////////////////
   474    480   
          481  +        #region Static "Factory" Methods
          482  +        public static SQLiteChangeSetIterator Attach(
          483  +            IntPtr iterator
          484  +            )
          485  +        {
          486  +            return new SQLiteChangeSetIterator(iterator, false);
          487  +        }
          488  +        #endregion
          489  +
          490  +        ///////////////////////////////////////////////////////////////////////
          491  +
   475    492           #region IDisposable Members
   476    493           public void Dispose()
   477    494           {
   478    495               Dispose(true);
   479    496               GC.SuppressFinalize(this);
   480    497           }
   481    498           #endregion
................................................................................
   512    529   
   513    530                       //////////////////////////////////////
   514    531                       // release unmanaged resources here...
   515    532                       //////////////////////////////////////
   516    533   
   517    534                       if (iterator != IntPtr.Zero)
   518    535                       {
   519         -                        UnsafeNativeMethods.sqlite3changeset_finalize(
   520         -                            iterator);
          536  +                        if (ownHandle)
          537  +                        {
          538  +                            UnsafeNativeMethods.sqlite3changeset_finalize(
          539  +                                iterator);
          540  +                        }
   521    541   
   522    542                           iterator = IntPtr.Zero;
   523    543                       }
   524    544                   }
   525    545               }
   526    546               finally
   527    547               {
................................................................................
   555    575           #endregion
   556    576   
   557    577           ///////////////////////////////////////////////////////////////////////
   558    578   
   559    579           #region Private Constructors
   560    580           private SQLiteMemoryChangeSetIterator(
   561    581               IntPtr pData,
   562         -            IntPtr iterator
          582  +            IntPtr iterator,
          583  +            bool ownHandle
   563    584               )
   564         -            : base(iterator)
          585  +            : base(iterator, ownHandle)
   565    586           {
   566    587               this.pData = pData;
   567    588           }
   568    589           #endregion
   569    590   
   570    591           ///////////////////////////////////////////////////////////////////////
   571    592   
................................................................................
   591    612   
   592    613                   SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3changeset_start(
   593    614                       ref iterator, nData, pData);
   594    615   
   595    616                   if (rc != SQLiteErrorCode.Ok)
   596    617                       throw new SQLiteException(rc, "sqlite3changeset_start");
   597    618   
   598         -                result = new SQLiteMemoryChangeSetIterator(pData, iterator);
          619  +                result = new SQLiteMemoryChangeSetIterator(
          620  +                    pData, iterator, true);
   599    621               }
   600    622               finally
   601    623               {
   602    624                   if (result == null)
   603    625                   {
   604    626                       if (iterator != IntPtr.Zero)
   605    627                       {
................................................................................
   685    707   
   686    708       #region SQLiteStreamChangeSetIterator Class
   687    709       internal sealed class SQLiteStreamChangeSetIterator :
   688    710           SQLiteChangeSetIterator
   689    711       {
   690    712           #region Private Constructors
   691    713           private SQLiteStreamChangeSetIterator(
   692         -            IntPtr iterator
          714  +            IntPtr iterator,
          715  +            bool ownHandle
   693    716               )
   694         -            : base(iterator)
          717  +            : base(iterator, ownHandle)
   695    718           {
   696    719               // do nothing.
   697    720           }
   698    721           #endregion
   699    722   
   700    723           ///////////////////////////////////////////////////////////////////////
   701    724   
................................................................................
   716    739                   SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3changeset_start_strm(
   717    740                       ref iterator, new SQLiteStreamAdapter(stream, flags).xInput,
   718    741                       IntPtr.Zero);
   719    742   
   720    743                   if (rc != SQLiteErrorCode.Ok)
   721    744                       throw new SQLiteException(rc, "sqlite3changeset_start_strm");
   722    745   
   723         -                result = new SQLiteStreamChangeSetIterator(iterator);
          746  +                result = new SQLiteStreamChangeSetIterator(iterator, true);
   724    747               }
   725    748               finally
   726    749               {
   727    750                   if (result == null)
   728    751                   {
   729    752                       if (iterator != IntPtr.Zero)
   730    753                       {
................................................................................
  1668   1691           {
  1669   1692               // do nothing.
  1670   1693           }
  1671   1694           #endregion
  1672   1695   
  1673   1696           ///////////////////////////////////////////////////////////////////////
  1674   1697   
         1698  +        #region Private Methods
         1699  +        private ISQLiteChangeSetMetadataItem CreateMetadataItem(
         1700  +            IntPtr iterator
         1701  +            )
         1702  +        {
         1703  +            return new SQLiteChangeSetMetadataItem(
         1704  +                SQLiteChangeSetIterator.Attach(iterator));
         1705  +        }
         1706  +        #endregion
         1707  +
         1708  +        ///////////////////////////////////////////////////////////////////////
         1709  +
  1675   1710           #region Protected Methods
  1676   1711           protected UnsafeNativeMethods.xSessionFilter GetDelegate(
  1677   1712               SessionTableFilterCallback tableFilterCallback,
  1678   1713               object clientData
  1679   1714               )
  1680   1715           {
  1681   1716               if (tableFilterCallback == null)
................................................................................
  1732   1767               UnsafeNativeMethods.xSessionConflict xConflict;
  1733   1768   
  1734   1769               xConflict = new UnsafeNativeMethods.xSessionConflict(
  1735   1770                   delegate(IntPtr context,
  1736   1771                            SQLiteChangeSetConflictType type,
  1737   1772                            IntPtr iterator)
  1738   1773               {
  1739         -                ISQLiteChangeSetMetadataItem item = null;
  1740         -
  1741   1774                   try
  1742   1775                   {
         1776  +                    ISQLiteChangeSetMetadataItem item = CreateMetadataItem(
         1777  +                        iterator);
         1778  +
         1779  +                    if (item == null)
         1780  +                    {
         1781  +                        throw new SQLiteException(
         1782  +                            "could not create metadata item");
         1783  +                    }
         1784  +
  1743   1785                       return conflictCallback(clientData, type, item);
  1744   1786                   }
  1745   1787                   catch (Exception e)
  1746   1788                   {
  1747   1789                       try
  1748   1790                       {
  1749   1791                           if (HelperMethods.LogCallbackExceptions(GetFlags()))