示例#1
0
        public void ReadOneAllSetup(DAL db)
        {
            StringBuilder sb = new StringBuilder();
            foreach (String tableName in CruiseDAL.Schema.Schema.TABLE_NAMES)
            {
                List<ColumnInfo> columnInfos = db.GetTableInfo(tableName);
                String[] columnNames = (from ci in columnInfos
                                       where ci.IsRequired
                                       select ci.Name).ToArray();
                String[] values = (from ci in columnInfos
                                   where ci.IsRequired
                                   select (ci.DBType == "TEXT") ? "'TestStr'" :
                                   (ci.DBType == "INTEGER") ? "101010" :
                                   (ci.DBType == "REAL") ? "202.02" : "'Something'").ToArray();

                if (columnNames.Length > 0)
                {
                    sb.AppendFormat("INSERT INTO {0} ({1}) VALUES ({2}); ", tableName, string.Join(",", columnNames), string.Join(",", values));
                }
                else
                {
                    sb.AppendFormat("INSERT INTO {0} DEFAULT VALUES; ", tableName);
                }
            }

            db.Execute(sb.ToString());
        }
        public MergeTableCommandBuilder(DAL masterDB, String clientTableName)
        {
            this.ClientTableName = clientTableName;
            this.MergeTableName = "Merge" + this.ClientTableName;

            this.AllClientColumns = masterDB.GetTableInfo(clientTableName);

            this.ClientGUIDKeyField = (from ColumnInfo ci in this.AllClientColumns
                                       where ci.Name == this.ClientTableName + "_GUID"
                                       select ci).FirstOrDefault();

            this.ClientPrimaryKey = (from ColumnInfo ci in this.AllClientColumns
                                     where ci.IsPK == true
                                     select ci).FirstOrDefault() ?? new ColumnInfo() { Name = "RowID" };

            this.HasRowVersion = this.AllClientColumns.Find(x => x.Name == "RowVersion") != null;

            this.ClientUniqueFieldNames = masterDB.GetTableUniques(clientTableName).ToArray();
            InitializeCommonColumns(this.HasGUIDKey, this.HasRowVersion);
        }
示例#3
0
        private static void UpdateToVersion2015_08_19(DAL db)
        {
            System.Collections.Generic.List<ColumnInfo> tavCols = db.GetTableInfo("TreeAuditValue");
            bool hasErrorMessageCol = false;
            foreach (ColumnInfo col in tavCols)
            {
                if (col.Name == "ErrorMessage")
                {
                    hasErrorMessageCol = true; break;
                }
            }

            try
            {
                db.BeginTransaction();
                if (!hasErrorMessageCol)
                {
                    db.AddField("TreeAuditValue", "ErrorMessage TEXT");
                }

                SetDatabaseVersion(db, "2015.08.19");
                db.CommitTransaction();
            }
            catch (Exception e)
            {
                db.RollbackTransaction();
                throw new SchemaUpdateException(db.DatabaseVersion, "2015.08.19", e);
            }
        }