コード例 #1
0
        /// <summary>
        /// 创建表格
        /// </summary>
        /// <param name="connection">SQL连接</param>
        /// <param name="table">表格信息</param>
        internal unsafe override bool createTable(DbConnection connection, table table)
        {
            string name = table.Columns.Name;

            if (connection != null && name != null && name.Length != 0 && table.Columns != null && table.Columns.Columns.Length != 0)
            {
                pointer buffer = fastCSharp.sql.client.SqlBuffers.Get();
                try
                {
                    using (charStream sqlStream = new charStream(buffer.Char, fastCSharp.sql.client.SqlBufferSize))
                    {
                        sqlStream.SimpleWriteNotNull("create table ");
                        sqlStream.SimpleWriteNotNull(name);
                        sqlStream.SimpleWriteNotNull(" (");
                        bool isNext = false;
                        foreach (column column in table.Columns.Columns)
                        {
                            if (isNext)
                            {
                                sqlStream.Write(',');
                            }
                            sqlStream.SimpleWriteNotNull(column.SqlName);
                            sqlStream.Write(' ');
                            sqlStream.Write(column.DbType.getSqlTypeName());
                            isNext = true;
                        }
                        sqlStream.Write(')');
                        return(executeNonQuery(connection, sqlStream.ToString()) >= 0);
                    }
                }
                finally { fastCSharp.sql.client.SqlBuffers.Push(ref buffer); }
            }
            return(false);
        }
コード例 #2
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); }
        }
コード例 #3
0
ファイル: selectQuery.cs プロジェクト: iLanceS/fastCSharp
 /// <summary>
 /// 排序字符串
 /// </summary>
 /// <param name="sqlTable">数据库表格操作工具</param>
 /// <param name="sqlStream">SQL表达式流</param>
 internal void WriteOrder(fastCSharp.emit.sqlTable.sqlToolBase sqlTable, charStream sqlStream)
 {
     if (Orders != null)
     {
         int isNext = 0;
         sqlStream.SimpleWriteNotNull(" order by ");
         foreach (keyValue <LambdaExpression, bool> order in Orders)
         {
             if (isNext == 0)
             {
                 isNext = 1;
             }
             else
             {
                 sqlStream.Write(',');
             }
             keyValue <string, string> name = sqlTable.Client.GetSql(order.Key, sqlStream);
             if (order.Value)
             {
                 sqlStream.SimpleWriteNotNull(" desc");
             }
             if (!isCreatedIndex && name.Key != null)
             {
                 isCreatedIndex = true;
                 sqlTable.CreateIndex(name.Key, name.Value);
             }
         }
     }
     else if (SqlFieldOrders != null)
     {
         int isNext = 0;
         sqlStream.SimpleWriteNotNull(" order by ");
         foreach (keyValue <sqlModel.fieldInfo, bool> order in SqlFieldOrders)
         {
             if (isNext == 0)
             {
                 isNext = 1;
             }
             else
             {
                 sqlStream.Write(',');
             }
             sqlStream.SimpleWriteNotNull(order.Key.SqlFieldName);
             if (order.Value)
             {
                 sqlStream.SimpleWriteNotNull(" desc");
             }
         }
     }
 }
コード例 #4
0
ファイル: type.cs プロジェクト: iLanceS/fastCSharp
 /// <summary>
 /// 获取XML注释文档名称
 /// </summary>
 /// <param name="type"></param>
 public void Xml(Type type)
 {
     if (type.IsArray)
     {
         array(type, true);
     }
     else if (type.IsGenericType)
     {
         genericFullName(type);
     }
     else
     {
         Type reflectedType = type.ReflectedType;
         if (reflectedType == null)
         {
             NameStream.SimpleWriteNotNull(type.Namespace);
             NameStream.Write('.');
             NameStream.SimpleWriteNotNull(type.Name);
         }
         else
         {
             this.reflectedType(type, reflectedType);
         }
     }
 }
コード例 #5
0
        /// <summary>
        /// 转换表达式
        /// </summary>
        /// <param name="converter">表达式转换器</param>
        /// <param name="binaryExpression">表达式</param>
        /// <param name="type">操作字符串</param>
        private void convertBinaryExpression(converter converter, BinaryExpression binaryExpression, string type)
        {
            charStream stream = converter.Stream;
            Expression left = binaryExpression.Left, right = binaryExpression.Right;

            stream.Write('(');
            if (left.IsSimple)
            {
                converters[(int)left.NodeType](converter, left);
                stream.Write('=');
                stream.Write('1');
            }
            else
            {
                converters[(int)left.NodeType](converter, left);
            }
            stream.Write(')');
            stream.SimpleWriteNotNull(type);
            stream.Write('(');
            if (right.IsSimple)
            {
                converters[(int)right.NodeType](converter, right);
                stream.Write('=');
                stream.Write('1');
            }
            else
            {
                converters[(int)right.NodeType](converter, right);
            }
            stream.Write(')');
        }
コード例 #6
0
        /// <summary>
        /// 转换表达式
        /// </summary>
        /// <param name="converter">表达式转换器</param>
        /// <param name="expression">表达式</param>
        private void convertInSet(sql.expression.converter converter, Expression expression)
        {
            charStream       stream           = converter.Stream;
            BinaryExpression binaryExpression = (BinaryExpression)expression;
            Expression       left             = binaryExpression.Left;

            converters[(int)left.NodeType](converter, left);
            stream.SimpleWriteNotNull(" In(");
            Action <charStream, object> toString = null;
            int index = -1;

            foreach (object value in (IEnumerable)((ConstantExpression)binaryExpression.Right).Value)
            {
                if (++index == 0)
                {
                    toString = constantConverter[value.GetType()];
                }
                else
                {
                    stream.Write(',');
                }
                if (toString == null)
                {
                    stringConverter(stream, value.ToString());
                }
                else
                {
                    toString(stream, value);
                }
            }
            stream.Write(')');
        }
コード例 #7
0
 private void convertConstant(charStream sqlStream, decimal?value)
 {
     if (value == null)
     {
         fastCSharp.web.ajax.WriteNull(sqlStream);
     }
     else
     {
         sqlStream.SimpleWriteNotNull(((decimal)value).ToString());
     }
 }
コード例 #8
0
        /// <summary>
        /// 转换表达式
        /// </summary>
        /// <param name="converter">表达式转换器</param>
        /// <param name="expression">表达式</param>
        private void convertConditional(converter converter, Expression expression)
        {
            charStream            stream = converter.Stream;
            ConditionalExpression conditionalExpression = (ConditionalExpression)expression;
            Expression            test = conditionalExpression.Test, ifTrue = conditionalExpression.IfTrue, ifFalse = conditionalExpression.IfFalse;

            stream.SimpleWriteNotNull("case when ");
            if (test.IsSimple)
            {
                converters[(int)test.NodeType](converter, test);
                stream.Write('=');
                stream.Write('1');
            }
            else
            {
                converters[(int)test.NodeType](converter, test);
            }
            stream.SimpleWriteNotNull(" then ");
            if (ifTrue.IsSimple)
            {
                converters[(int)ifTrue.NodeType](converter, ifTrue);
            }
            else
            {
                stream.Write('(');
                converters[(int)ifTrue.NodeType](converter, ifTrue);
                stream.Write(')');
            }
            stream.SimpleWriteNotNull(" else ");
            if (ifFalse.IsSimple)
            {
                converters[(int)ifFalse.NodeType](converter, ifFalse);
            }
            else
            {
                stream.Write('(');
                converters[(int)ifFalse.NodeType](converter, ifFalse);
                stream.Write(')');
            }
            stream.SimpleWriteNotNull(" end");
        }
コード例 #9
0
ファイル: sql2005.cs プロジェクト: iLanceS/fastCSharp
        /// <summary>
        /// 查询对象集合
        /// </summary>
        /// <typeparam name="valueType">对象类型</typeparam>
        /// <typeparam name="modelType">模型类型</typeparam>
        /// <param name="sqlTool">SQL操作工具</param>
        /// <param name="query">查询信息</param>
        /// <param name="memberMap">成员位图</param>
        /// <param name="sqlStream"></param>
        /// <returns></returns>
        private unsafe string selectRows <valueType, modelType>
            (fastCSharp.emit.sqlTable.sqlTool <valueType, modelType> sqlTool, selectQuery <modelType> query, fastCSharp.code.memberMap <modelType> memberMap, charStream sqlStream)
            where valueType : class, modelType
            where modelType : class
        {
            pointer buffer = fastCSharp.sql.client.SqlBuffers.Get();

            try
            {
                using (sqlStream)
                {
                    sqlStream.UnsafeReset(buffer.Byte, SqlBufferSize << 1);
                    sqlStream.WriteNotNull("select * from(select ");
                    sqlModel <modelType> .GetNames(sqlStream, memberMap);

                    sqlStream.WriteNotNull(",row_number()over(");
                    query.WriteOrder(sqlTool, sqlStream);
                    sqlStream.SimpleWriteNotNull(")as ");
                    sqlStream.SimpleWriteNotNull(orderOverName);
                    sqlStream.SimpleWriteNotNull(" from[");
                    sqlStream.SimpleWriteNotNull(sqlTool.TableName);
                    sqlStream.SimpleWriteNotNull("]with(nolock)");
                    if (query.WriteWhereOnly(sqlTool, sqlStream))
                    {
                        sqlStream.SimpleWriteNotNull(")as T where ");
                        sqlStream.SimpleWriteNotNull(orderOverName);
                        sqlStream.SimpleWriteNotNull(" between ");
                        number.ToString(query.SkipCount, sqlStream);
                        sqlStream.SimpleWriteNotNull(" and ");
                        number.ToString(query.SkipCount + query.GetCount - 1, sqlStream);
                        return(sqlStream.ToString());
                    }
                }
            }
            finally { fastCSharp.sql.client.SqlBuffers.Push(ref buffer); }
            return(null);
        }
コード例 #10
0
 /// <summary>
 /// 获取字段信息
 /// </summary>
 /// <param name="field"></param>
 /// <returns></returns>
 private xmlNode get(FieldInfo field)
 {
     if (field != null)
     {
         xmlNode node;
         if (fieldLock.TryGetValue(field, out node))
         {
             return(node);
         }
         try
         {
             hashString fieldName;
             pointer    buffer = unmanagedPool.StreamBuffers.Get();
             try
             {
                 using (fieldNameStream)
                 {
                     fieldNameStream.UnsafeReset(buffer.Byte, unmanagedPool.StreamBuffers.Size);
                     type.nameBuilder nameBuilder = new type.nameBuilder {
                         NameStream = fieldNameStream, IsXml = true
                     };
                     nameBuilder.Xml(field.DeclaringType);
                     fieldNameStream.Write('.');
                     fieldNameStream.SimpleWriteNotNull(field.Name);
                     fieldName = fieldNameStream.ToString();
                 }
             }
             finally { unmanagedPool.StreamBuffers.Push(ref buffer); }
             if (fields.TryGetValue(fieldName, out node))
             {
                 fields.Remove(fieldName);
             }
             fieldLock.Set(field, node);
         }
         finally { fieldLock.Exit(); }
         return(node);
     }
     return(default(xmlNode));
 }
コード例 #11
0
        /// <summary>
        /// 转换表达式
        /// </summary>
        /// <param name="converter">表达式转换器</param>
        /// <param name="expression">表达式</param>
        private void convertCall(converter converter, Expression expression)
        {
            MethodCallExpression methodCallExpression = (MethodCallExpression)expression;
            charStream           stream = converter.Stream;

            stream.SimpleWriteNotNull(methodCallExpression.Method.Name);
            stream.Write('(');
            if (methodCallExpression.Arguments != null)
            {
                bool isNext = false;
                foreach (Expression argumentExpression in methodCallExpression.Arguments)
                {
                    if (isNext)
                    {
                        stream.Write(',');
                    }
                    converters[(int)argumentExpression.NodeType](converter, argumentExpression);
                    isNext = true;
                }
            }
            stream.Write(')');
        }
コード例 #12
0
        /// <summary>
        /// 转换表达式
        /// </summary>
        /// <param name="converter">表达式转换器</param>
        /// <param name="expression">表达式</param>
        private void convertNotEqual(converter converter, Expression expression)
        {
            BinaryExpression binaryExpression = (BinaryExpression)expression;

            if (binaryExpression.Left.IsConstantNull)
            {
                charStream stream = converter.Stream;
                if (binaryExpression.Right.IsSimple)
                {
                    converters[(int)binaryExpression.Right.NodeType](converter, binaryExpression.Right);
                }
                else
                {
                    stream.Write('(');
                    converters[(int)binaryExpression.Right.NodeType](converter, binaryExpression.Right);
                    stream.Write(')');
                }
                stream.SimpleWriteNotNull(" is not null");
            }
            else if (binaryExpression.Right.IsConstantNull)
            {
                charStream stream = converter.Stream;
                if (binaryExpression.Left.IsSimple)
                {
                    converters[(int)binaryExpression.Left.NodeType](converter, binaryExpression.Left);
                }
                else
                {
                    stream.Write('(');
                    converters[(int)binaryExpression.Left.NodeType](converter, binaryExpression.Left);
                    stream.Write(')');
                }
                stream.SimpleWriteNotNull(" is not null");
            }
            else
            {
                convertNotEqual(converter, (BinaryExpression)expression);
            }
        }
コード例 #13
0
 /// <summary>
 /// 获取属性信息
 /// </summary>
 /// <param name="property"></param>
 /// <returns></returns>
 private xmlNode get(PropertyInfo property)
 {
     if (property != null)
     {
         xmlNode node;
         if (propertyLock.TryGetValue(property, out node))
         {
             return(node);
         }
         try
         {
             hashString propertyName;
             pointer    buffer = unmanagedPool.StreamBuffers.Get();
             try
             {
                 using (propertyNameStream)
                 {
                     propertyNameStream.UnsafeReset(buffer.Byte, unmanagedPool.StreamBuffers.Size);
                     type.nameBuilder nameBuilder = new type.nameBuilder {
                         NameStream = propertyNameStream, IsXml = true
                     };
                     nameBuilder.Xml(property.DeclaringType);
                     propertyNameStream.Write('.');
                     propertyNameStream.SimpleWriteNotNull(property.Name);
                     propertyName = propertyNameStream.ToString();
                 }
             }
             finally { unmanagedPool.StreamBuffers.Push(ref buffer); }
             if (properties.TryGetValue(propertyName, out node))
             {
                 properties.Remove(propertyName);
             }
             propertyLock.Set(property, node);
         }
         finally { propertyLock.Exit(); }
         return(node);
     }
     return(default(xmlNode));
 }
コード例 #14
0
 private void convertConstant(charStream sqlStream, decimal value)
 {
     sqlStream.SimpleWriteNotNull(value.ToString());
 }
コード例 #15
0
 /// <summary>
 /// 常量转换字符串
 /// </summary>
 /// <param name="sqlStream">SQL字符流</param>
 /// <param name="value">常量</param>
 private void convertConstantFloat(charStream sqlStream, object value)
 {
     sqlStream.SimpleWriteNotNull(((float)value).ToString());
 }
コード例 #16
0
 public static void ToString(decimal value, charStream jsonStream)
 {
     jsonStream.SimpleWriteNotNull(value.ToString());
 }
コード例 #17
0
 /// <summary>
 /// 获取方法信息
 /// </summary>
 /// <param name="method"></param>
 /// <returns></returns>
 private xmlNode get(MethodInfo method)
 {
     if (method != null)
     {
         xmlNode node;
         if (methodLock.TryGetValue(method, out node))
         {
             return(node);
         }
         try
         {
             hashString methodName;
             pointer    buffer = unmanagedPool.StreamBuffers.Get();
             try
             {
                 using (methodNameStream)
                 {
                     methodNameStream.UnsafeReset(buffer.Byte, unmanagedPool.StreamBuffers.Size);
                     type.nameBuilder nameBuilder = new type.nameBuilder {
                         NameStream = methodNameStream, IsXml = true
                     };
                     nameBuilder.Xml(method.DeclaringType);
                     methodNameStream.Write('.');
                     string name = method.Name;
                     if (name[0] == '.')
                     {
                         methodNameStream.Write('#');
                         methodNameStream.Write(subString.Unsafe(name, 1, name.Length - 1));
                     }
                     else
                     {
                         methodNameStream.SimpleWriteNotNull(name);
                     }
                     ParameterInfo[] parameters = method.GetParameters();
                     if (parameters.Length != 0)
                     {
                         bool isFirst = true;
                         methodNameStream.Write('(');
                         foreach (ParameterInfo parameter in parameters)
                         {
                             if (isFirst)
                             {
                                 isFirst = false;
                             }
                             else
                             {
                                 methodNameStream.Write(',');
                             }
                             nameBuilder.Xml(parameter.ParameterType);
                         }
                         methodNameStream.Write(')');
                     }
                     formatName(methodNameStream.Char, methodNameStream.CurrentChar);
                     methodName = methodNameStream.ToString();
                 }
             }
             finally { unmanagedPool.StreamBuffers.Push(ref buffer); }
             if (methods.TryGetValue(methodName, out node))
             {
                 methods.Remove(methodName);
             }
             methodLock.Set(method, node);
         }
         finally { methodLock.Exit(); }
         return(node);
     }
     return(default(xmlNode));
 }
コード例 #18
0
 /// <summary>
 /// 常量转换字符串
 /// </summary>
 /// <param name="sqlStream">SQL字符流</param>
 /// <param name="value">常量</param>
 private void convertConstantDecimal(charStream sqlStream, object value)
 {
     sqlStream.SimpleWriteNotNull(((decimal)value).ToString());
 }