Example #1
0
        public bool NeedToCreateTrackingTable(DbBuilderOption builderOption)
        {
            if (builderOption.HasFlag(DbBuilderOption.CreateOrUseExistingSchema))
            {
                return(!SQLiteManagementUtils.TableExists(connection, transaction, trackingName.QuotedString));
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// For a foreign key, check if the Parent table exists
        /// </summary>
        private bool EnsureForeignKeysTableExist(DmRelation foreignKey)
        {
            var childTable  = foreignKey.ChildTable;
            var parentTable = foreignKey.ParentTable;

            // The foreignkey comes from the child table
            var ds = foreignKey.ChildTable.DmSet;

            if (ds == null)
            {
                return(false);
            }

            // Check if the parent table is part of the sync configuration
            var exist = ds.Tables.Any(t => ds.IsEqual(t.TableName, parentTable.TableName));

            if (!exist)
            {
                return(false);
            }

            bool alreadyOpened = connection.State == ConnectionState.Open;

            try
            {
                if (!alreadyOpened)
                {
                    connection.Open();
                }

                return(SQLiteManagementUtils.TableExists(connection, transaction, parentTable.TableName));
            }
            catch (Exception ex)
            {
                Logger.Current.Error($"Error during EnsureForeignKeysTableExist : {ex}");
                throw;
            }
            finally
            {
                if (!alreadyOpened && connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
            }
        }