コード例 #1
0
        /// <summary>
        /// 检测SQL表格
        /// </summary>
        /// <param name="table">SQL表格</param>
        private static void checkSqlTable(keyValue <Type, keyValue <Type, sqlTable> > table)
        {
            table  memberTable = setup.cSharp.sqlTable.cSharp.GetTable(table.Key, table.Value.Value, setup.cSharp.sqlTable.cSharp.GetMembers(table.Value.Key, table.Value.Value));
            client sqlClient   = GetConnection(table.Value.Value.ConnectionType).Client;
            table  sqlTable    = sqlClient.GetTable(memberTable.Columns.Name);

            if (sqlTable == null)
            {
                if (!sqlClient.CreateTable(memberTable))
                {
                    fastCSharp.log.Default.Real("表格 " + memberTable.Columns.Name + " 创建失败", false, false);
                }
            }
            else
            {
                staticDictionary <string, column> sqlColumnNames = new staticDictionary <string, column>(sqlTable.Columns.Columns, value => value.Name);
                list <column> newColumns = memberTable.Columns.Columns.getFind(value => !sqlColumnNames.ContainsKey(value.Name));
                if (newColumns.count() != 0)
                {
                    if (sqlClient.AddFields(new columnCollection {
                        Name = memberTable.Columns.Name, Columns = newColumns.toArray()
                    }))
                    {
                        sqlTable.Columns.Columns = newColumns.add(sqlTable.Columns.Columns).toArray();
                    }
                    else
                    {
                        fastCSharp.log.Default.Real("表格 " + memberTable.Columns.Name + " 字段添加失败 : " + newColumns.joinString(',', value => value.Name), false, false);
                    }
                }
                newColumns = memberTable.Columns.Columns.getFind(value => !value.IsMatch(sqlColumnNames.Get(value.Name, null)));
                if (newColumns.count() != 0)
                {
                    fastCSharp.log.Default.Real("表格 " + memberTable.Columns.Name + " 字段类型不匹配 : " + newColumns.joinString(',', value => value.Name), false, false);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 检测SQL表格
        /// </summary>
        /// <param name="type">表格绑定类型</param>
        /// <param name="modelType">表格模型类型</param>
        /// <param name="sqlModel">数据库表格模型配置</param>
        /// <param name="sqlTable">数据库表格配置</param>
        private static void checkSqlTable(Type type, Type modelType, fastCSharp.code.cSharp.sqlModel sqlModel, fastCSharp.emit.sqlTable sqlTable)
        {
            client sqlClient   = GetConnection(sqlTable.ConnectionType).Client;
            table  memberTable = (table)typeof(sqlModel <>).MakeGenericType(modelType).GetMethod("GetTable", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[] { typeof(Type), typeof(fastCSharp.emit.sqlTable) }, null).Invoke(null, new object[] { type, sqlTable });

            sqlClient.ToSqlColumn(memberTable);
            table table = sqlClient.GetTable(memberTable.Columns.Name);

            if (table == null)
            {
                if (!sqlClient.CreateTable(memberTable))
                {
                    fastCSharp.log.Error.Add("表格 " + memberTable.Columns.Name + " 创建失败", new System.Diagnostics.StackFrame(), false);
                }
            }
            else
            {
                bool ignoreCase = Enum <fastCSharp.sql.type, fastCSharp.sql.typeInfo> .Array((byte)sqlClient.Connection.Type).IgnoreCase;

                if (sqlModel.DeleteColumnNames != null)
                {
                    HashSet <string> deleteNames   = sqlModel.DeleteColumnNames.Split(',').getHash(value => ignoreCase ? value.toLower() : value);
                    column[]         deleteColumns = table.Columns.Columns.getFindArray(value => deleteNames.Contains(ignoreCase ? value.SqlName.ToLower() : value.SqlName));
                    if (deleteColumns.Length != 0)
                    {
                        table.Columns.Columns = table.Columns.Columns.getFindArray(value => !deleteNames.Contains(ignoreCase ? value.SqlName.ToLower() : value.SqlName));
                        if (!sqlClient.DeleteFields(new columnCollection {
                            Name = memberTable.Columns.Name, Columns = deleteColumns
                        }))
                        {
                            fastCSharp.log.Error.Add("表格 " + memberTable.Columns.Name + " 字段删除失败 : " + deleteColumns.joinString(',', value => value.SqlName), new System.Diagnostics.StackFrame(), false);
                        }
                    }
                }
                string[] names = ignoreCase ? table.Columns.Columns.getArray(value => value.SqlName.ToLower()) : table.Columns.Columns.getArray(value => value.SqlName);
                using (fastCSharp.stateSearcher.ascii <column> sqlColumnNames = new stateSearcher.ascii <column>(names, table.Columns.Columns, false))
                {
                    subArray <column> newColumns;
                    if (ignoreCase)
                    {
                        newColumns = memberTable.Columns.Columns.getFind(value => !sqlColumnNames.ContainsKey(value.SqlName.ToLower()));
                    }
                    else
                    {
                        newColumns = memberTable.Columns.Columns.getFind(value => !sqlColumnNames.ContainsKey(value.SqlName));
                    }
                    if (newColumns.length != 0)
                    {
                        if (sqlClient.IsAddField && sqlClient.AddFields(new columnCollection {
                            Name = memberTable.Columns.Name, Columns = newColumns.ToArray()
                        }))
                        {
                            table.Columns.Columns = newColumns.Add(table.Columns.Columns).ToArray();
                        }
                        else
                        {
                            fastCSharp.log.Error.Add("表格 " + memberTable.Columns.Name + " 字段添加失败 : " + newColumns.joinString(',', value => value.SqlName), new System.Diagnostics.StackFrame(), false);
                        }
                    }
                    if (ignoreCase)
                    {
                        newColumns = memberTable.Columns.Columns.getFind(value => !value.IsMatch(sqlColumnNames.Get(value.SqlName.ToLower()), ignoreCase));
                    }
                    else
                    {
                        newColumns = memberTable.Columns.Columns.getFind(value => !value.IsMatch(sqlColumnNames.Get(value.SqlName), ignoreCase));
                    }
                    if (newColumns.count() != 0)
                    {
                        fastCSharp.log.Default.Add("表格 " + memberTable.Columns.Name + " 字段类型不匹配 : " + newColumns.joinString(',', value => value.SqlName), new System.Diagnostics.StackFrame(), false);
                    }
                }
            }
        }