コード例 #1
0
 /// <summary>
 /// 获取变量定义的数据类型。
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="suppressSize">if set to <c>true</c> [suppress size].</param>
 /// <returns></returns>
 public abstract string GetVariableDeclaration(QueryType type, bool suppressSize);
コード例 #2
0
        public override string GetVariableDeclaration(QueryType type, bool suppressSize)
        {
            StringBuilder sb = new StringBuilder();
            DbQueryType sqlType = (DbQueryType)type;
            SqlDbType sqlDbType = sqlType.SqlDbType;

            switch (sqlDbType)
            {
                case SqlDbType.BigInt:
                case SqlDbType.SmallInt:
                case SqlDbType.Int:
                case SqlDbType.TinyInt:
                    sb.Append("INTEGER");
                    break;
                case SqlDbType.Bit:
                    sb.Append("BOOLEAN");
                    break;
                case SqlDbType.SmallDateTime:
                    sb.Append("DATETIME");
                    break;
                case SqlDbType.Char:
                case SqlDbType.NChar:
                    sb.Append("CHAR");
                    if (type.Length > 0 && !suppressSize)
                    {
                        sb.Append("(");
                        sb.Append(type.Length);
                        sb.Append(")");
                    }
                    break;
                case SqlDbType.Variant:
                case SqlDbType.Binary:
                case SqlDbType.Image:
                case SqlDbType.UniqueIdentifier: //There is a setting to make it string, look at later
                    sb.Append("BLOB");
                    if (type.Length > 0 && !suppressSize)
                    {
                        sb.Append("(");
                        sb.Append(type.Length);
                        sb.Append(")");
                    }
                    break;
                case SqlDbType.Xml:
                case SqlDbType.NText:
                case SqlDbType.NVarChar:
                case SqlDbType.Text:
                case SqlDbType.VarBinary:
                case SqlDbType.VarChar:
                    sb.Append("TEXT");
                    if (type.Length > 0 && !suppressSize)
                    {
                        sb.Append("(");
                        sb.Append(type.Length);
                        sb.Append(")");
                    }
                    break;
                case SqlDbType.Decimal:
                case SqlDbType.Money:
                case SqlDbType.SmallMoney:
                    sb.Append("NUMERIC");
                    if (type.Precision != 0)
                    {
                        sb.Append("(");
                        sb.Append(type.Precision);
                        sb.Append(")");
                    }
                    break;
                case SqlDbType.Float:
                case SqlDbType.Real:
                    sb.Append("FLOAT");
                    if (type.Precision != 0)
                    {
                        sb.Append("(");
                        sb.Append(type.Precision);
                        sb.Append(")");
                    }
                    break;
                case SqlDbType.Date:
                case SqlDbType.DateTime:
                case SqlDbType.Timestamp:
                default:
                    sb.Append(sqlDbType);
                    break;
            }
            return sb.ToString();
        }
コード例 #3
0
        /// <summary>
        /// 获取变量定义的数据类型。
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="suppressSize">if set to <c>true</c> [suppress size].</param>
        /// <returns></returns>
        public override string GetVariableDeclaration(QueryType type, bool suppressSize)
        {
            StringBuilder sb = new StringBuilder();
            DbQueryType sqlType = (DbQueryType)type;
            SqlDbType sqlDbType = sqlType.SqlDbType;

            switch (sqlDbType)
            {
                case SqlDbType.BigInt:
                case SqlDbType.Bit:
                case SqlDbType.DateTime:
                case SqlDbType.Int:
                case SqlDbType.Money:
                case SqlDbType.SmallDateTime:
                case SqlDbType.SmallInt:
                case SqlDbType.SmallMoney:
                case SqlDbType.Timestamp:
                case SqlDbType.TinyInt:
                case SqlDbType.UniqueIdentifier:
                case SqlDbType.Variant:
                case SqlDbType.Xml:
                    sb.Append(sqlDbType);
                    break;
                case SqlDbType.Binary:
                case SqlDbType.Char:
                case SqlDbType.NChar:
                    sb.Append(sqlDbType);
                    if (type.Length > 0 && !suppressSize)
                    {
                        sb.Append("(");
                        sb.Append(type.Length);
                        sb.Append(")");
                    }
                    break;
                case SqlDbType.Image:
                case SqlDbType.NText:
                case SqlDbType.NVarChar:
                case SqlDbType.Text:
                case SqlDbType.VarBinary:
                case SqlDbType.VarChar:
                    sb.Append(sqlDbType);
                    if (type.Length > 0 && !suppressSize)
                    {
                        sb.Append("(");
                        sb.Append(type.Length);
                        sb.Append(")");
                    }
                    break;
                case SqlDbType.Decimal:
                    sb.Append("Currency");
                    break;
                case SqlDbType.Float:
                case SqlDbType.Real:
                    sb.Append(sqlDbType);  
                    if (type.Precision != 0)
                    {
                        sb.Append("(");
                        sb.Append(type.Precision);
                        if (type.Scale != 0)
                        {
                            sb.Append(",");
                            sb.Append(type.Scale);
                        }
                        sb.Append(")");
                    }
                    break;
            }
            return sb.ToString();
        }
コード例 #4
0
 /// <summary>
 /// Gets the type of the OLE db.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <returns></returns>
 protected override OleDbType GetOleDbType(QueryType type)
 {
     DbQueryType sqlType = type as DbQueryType;
     if (sqlType != null)
     {
         return ToOleDbType(sqlType.SqlDbType);
     }
     return base.GetOleDbType(type);
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryParameter"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="type">The type.</param>
 /// <param name="queryType">Type of the query.</param>
 public QueryParameter(string name, Type type, QueryType queryType)
 {
     this.name = name;
     this.type = type;
     this.queryType = queryType;
 }
コード例 #6
0
 /// <summary>
 /// 获取OleDb 数据库类型
 /// </summary>
 /// <param name="type">The type.</param>
 /// <returns></returns>
 protected virtual OleDbType GetOleDbType(QueryType type)
 {
     return ToOleDbType(((DbQueryType)type).SqlDbType);
 }