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 Unified Diffs Show Whitespace Changes Patch

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

398
399
400
401
402
403
404
405
406
407
408




409
410
411
412
413
414
415

416
417
418

419
420
421
422
423
424
425
...
468
469
470
471
472
473
474











475
476
477
478
479
480
481
...
511
512
513
514
515
516
517


518
519
520

521
522
523
524
525
526
527
...
555
556
557
558
559
560
561
562

563
564
565
566
567
568
569
570
571
...
591
592
593
594
595
596
597
598

599
600
601
602
603
604
605
...
685
686
687
688
689
690
691
692

693
694
695
696
697
698
699
700
701
...
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
....
1668
1669
1670
1671
1672
1673
1674












1675
1676
1677
1678
1679
1680
1681
....
1732
1733
1734
1735
1736
1737
1738


1739

1740
1741

1742




1743
1744
1745
1746
1747
1748
1749
        #endregion
    }
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region SQLiteChangeSetIterator Class
    internal abstract class SQLiteChangeSetIterator : IDisposable
    {
        #region Private Data
        private IntPtr iterator;




        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Protected Constructors
        protected SQLiteChangeSetIterator(
            IntPtr iterator

            )
        {
            this.iterator = iterator;

        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Private Methods
        internal void CheckHandle()
................................................................................
                    }
            }
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////












        #region IDisposable Members
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        #endregion
................................................................................
                    //}

                    //////////////////////////////////////
                    // release unmanaged resources here...
                    //////////////////////////////////////

                    if (iterator != IntPtr.Zero)


                    {
                        UnsafeNativeMethods.sqlite3changeset_finalize(
                            iterator);


                        iterator = IntPtr.Zero;
                    }
                }
            }
            finally
            {
................................................................................
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Private Constructors
        private SQLiteMemoryChangeSetIterator(
            IntPtr pData,
            IntPtr iterator

            )
            : base(iterator)
        {
            this.pData = pData;
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

................................................................................

                SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3changeset_start(
                    ref iterator, nData, pData);

                if (rc != SQLiteErrorCode.Ok)
                    throw new SQLiteException(rc, "sqlite3changeset_start");

                result = new SQLiteMemoryChangeSetIterator(pData, iterator);

            }
            finally
            {
                if (result == null)
                {
                    if (iterator != IntPtr.Zero)
                    {
................................................................................

    #region SQLiteStreamChangeSetIterator Class
    internal sealed class SQLiteStreamChangeSetIterator :
        SQLiteChangeSetIterator
    {
        #region Private Constructors
        private SQLiteStreamChangeSetIterator(
            IntPtr iterator

            )
            : base(iterator)
        {
            // do nothing.
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

................................................................................
                SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3changeset_start_strm(
                    ref iterator, new SQLiteStreamAdapter(stream, flags).xInput,
                    IntPtr.Zero);

                if (rc != SQLiteErrorCode.Ok)
                    throw new SQLiteException(rc, "sqlite3changeset_start_strm");

                result = new SQLiteStreamChangeSetIterator(iterator);
            }
            finally
            {
                if (result == null)
                {
                    if (iterator != IntPtr.Zero)
                    {
................................................................................
        {
            // do nothing.
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////













        #region Protected Methods
        protected UnsafeNativeMethods.xSessionFilter GetDelegate(
            SessionTableFilterCallback tableFilterCallback,
            object clientData
            )
        {
            if (tableFilterCallback == null)
................................................................................
            UnsafeNativeMethods.xSessionConflict xConflict;

            xConflict = new UnsafeNativeMethods.xSessionConflict(
                delegate(IntPtr context,
                         SQLiteChangeSetConflictType type,
                         IntPtr iterator)
            {


                ISQLiteChangeSetMetadataItem item = null;


                try

                {




                    return conflictCallback(clientData, type, item);
                }
                catch (Exception e)
                {
                    try
                    {
                        if (HelperMethods.LogCallbackExceptions(GetFlags()))







|



>
>
>
>






|
>



>







 







>
>
>
>
>
>
>
>
>
>
>







 







>
>



>







 







|
>

|







 







|
>







 







|
>

|







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
|
>

<
>
|
>
>
>
>







398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
...
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
...
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
...
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
...
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
...
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
...
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
....
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
....
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778

1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
        #endregion
    }
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region SQLiteChangeSetIterator Class
    internal class SQLiteChangeSetIterator : IDisposable
    {
        #region Private Data
        private IntPtr iterator;

        ///////////////////////////////////////////////////////////////////////

        private bool ownHandle;
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Protected Constructors
        protected SQLiteChangeSetIterator(
            IntPtr iterator,
            bool ownHandle
            )
        {
            this.iterator = iterator;
            this.ownHandle = ownHandle;
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Private Methods
        internal void CheckHandle()
................................................................................
                    }
            }
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Static "Factory" Methods
        public static SQLiteChangeSetIterator Attach(
            IntPtr iterator
            )
        {
            return new SQLiteChangeSetIterator(iterator, false);
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region IDisposable Members
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        #endregion
................................................................................
                    //}

                    //////////////////////////////////////
                    // release unmanaged resources here...
                    //////////////////////////////////////

                    if (iterator != IntPtr.Zero)
                    {
                        if (ownHandle)
                        {
                            UnsafeNativeMethods.sqlite3changeset_finalize(
                                iterator);
                        }

                        iterator = IntPtr.Zero;
                    }
                }
            }
            finally
            {
................................................................................
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Private Constructors
        private SQLiteMemoryChangeSetIterator(
            IntPtr pData,
            IntPtr iterator,
            bool ownHandle
            )
            : base(iterator, ownHandle)
        {
            this.pData = pData;
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

................................................................................

                SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3changeset_start(
                    ref iterator, nData, pData);

                if (rc != SQLiteErrorCode.Ok)
                    throw new SQLiteException(rc, "sqlite3changeset_start");

                result = new SQLiteMemoryChangeSetIterator(
                    pData, iterator, true);
            }
            finally
            {
                if (result == null)
                {
                    if (iterator != IntPtr.Zero)
                    {
................................................................................

    #region SQLiteStreamChangeSetIterator Class
    internal sealed class SQLiteStreamChangeSetIterator :
        SQLiteChangeSetIterator
    {
        #region Private Constructors
        private SQLiteStreamChangeSetIterator(
            IntPtr iterator,
            bool ownHandle
            )
            : base(iterator, ownHandle)
        {
            // do nothing.
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

................................................................................
                SQLiteErrorCode rc = UnsafeNativeMethods.sqlite3changeset_start_strm(
                    ref iterator, new SQLiteStreamAdapter(stream, flags).xInput,
                    IntPtr.Zero);

                if (rc != SQLiteErrorCode.Ok)
                    throw new SQLiteException(rc, "sqlite3changeset_start_strm");

                result = new SQLiteStreamChangeSetIterator(iterator, true);
            }
            finally
            {
                if (result == null)
                {
                    if (iterator != IntPtr.Zero)
                    {
................................................................................
        {
            // do nothing.
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Private Methods
        private ISQLiteChangeSetMetadataItem CreateMetadataItem(
            IntPtr iterator
            )
        {
            return new SQLiteChangeSetMetadataItem(
                SQLiteChangeSetIterator.Attach(iterator));
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Protected Methods
        protected UnsafeNativeMethods.xSessionFilter GetDelegate(
            SessionTableFilterCallback tableFilterCallback,
            object clientData
            )
        {
            if (tableFilterCallback == null)
................................................................................
            UnsafeNativeMethods.xSessionConflict xConflict;

            xConflict = new UnsafeNativeMethods.xSessionConflict(
                delegate(IntPtr context,
                         SQLiteChangeSetConflictType type,
                         IntPtr iterator)
            {
                try
                {
                    ISQLiteChangeSetMetadataItem item = CreateMetadataItem(
                        iterator);


                    if (item == null)
                    {
                        throw new SQLiteException(
                            "could not create metadata item");
                    }

                    return conflictCallback(clientData, type, item);
                }
                catch (Exception e)
                {
                    try
                    {
                        if (HelperMethods.LogCallbackExceptions(GetFlags()))