コード例 #1
0
        /// <summary>
        /// 获取Excel客户端
        /// </summary>
        /// <returns>Excel客户端</returns>
        public unsafe client GetClient()
        {
            provider provider = Enum <providerType, provider> .Array((byte)Provider);

            pointer buffer = fastCSharp.sql.client.SqlBuffers.Get();

            try
            {
                using (charStream connectionStream = new charStream(buffer.Char, fastCSharp.sql.client.SqlBufferSize))
                {
                    connectionStream.SimpleWriteNotNull("Provider=");
                    connectionStream.Write(provider.Name);
                    connectionStream.SimpleWriteNotNull(";Data Source=");
                    connectionStream.Write(DataSource);
                    if (Password != null)
                    {
                        connectionStream.WriteNotNull(";Database Password="******";Extended Properties='");
                    connectionStream.Write(provider.Excel);
                    connectionStream.WriteNotNull(IsTitleColumn ? ";HDR=YES;IMEX=" : ";HDR=NO;IMEX=");
                    number.ToString((byte)Intermixed, connectionStream);
                    connectionStream.Write('\'');
                    return((client) new sql.connection {
                        Type = type.Excel, Connection = connectionStream.ToString()
                    }.Client);
                }
            }
            finally { fastCSharp.sql.client.SqlBuffers.Push(ref buffer); }
        }
コード例 #2
0
        /// <summary>
        /// CSharp代码生成器
        /// </summary>
        /// <param name="parameter">安装参数</param>
        /// <param name="type">模板数据视图</param>
        /// <param name="language">语言</param>
        public coder(auto.parameter parameter, Type type, auto.language language)
            : base(type, error.Add, error.Message)
        {
            this.parameter = parameter;
            extensionName  = "." + Enum <auto.language, auto.languageAttribute> .Array((int)(byte)language).ExtensionName;

            creators[command.NOTE.ToString()]     = note;
            creators[command.LOOP.ToString()]     = creators[command.FOR.ToString()] = loop;
            creators[command.AT.ToString()]       = at;
            creators[command.PUSH.ToString()]     = push;
            creators[command.IF.ToString()]       = ifThen;
            creators[command.NOT.ToString()]      = not;
            creators[command.NAME.ToString()]     = name;
            creators[command.FROMNAME.ToString()] = fromName;
            creators[command.PART.ToString()]     = part;
        }
コード例 #3
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);
                    }
                }
            }
        }