You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

79 lines
3.5 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FireBirdUtil.DataTypes
{
/// <summary>
/// FireBird的数据库类型
/// </summary>
public enum FBType
{
Integer = 1,//32位 从-2147483648到2147483647 整数
SmallInt = 2,//16位 从-32768到32767 短整数
Float = 4,//32位: 从1.175×10的-38次方到3.402×10的38次方 IEEE单精度浮点数,7位长度(指小数位数)
Double = 8,//Double Precision//64位: 从2.225×10的-308次方到1.797×10的308次方 IEEE双精度浮点数,15位长度(指小数位数)
Numeric = 16,// 变长(16、32或64位):Numeric(P,S) 精度p从1到18:指定数字的总长度;标度s从0到18:指定小数点后的位数。s<=p 定点小数。例如decimal(10,3)可以存储的数字形式为:ppppppp.sss
Decimal = 32,//变长(16、32或64位): Decimal(P,S) 精度p从1到18:指定数字的总长度;标度s从0到18:指定小数点后的位数。s<=p 定点小数。例如decimal(5,3)可以存储的数字形式为:pp.sss
Date = 64,//64位: 从公元后100年一月一日到32768年二月29日 日期类型。只有年月日,不带时间。如:2011-9-21
Time = 128,//64位: 从0:00 AM到23:59.9999 PM 时间类型
Timestamp = 256,//64位: 从公元后100年一月一日到32768年二月29日 带有时间的日期类型。如:2011-9-21 16:56:13.0000
Char = 512,//n个字符: 1到32767个字节。字符集决定了其能容纳的最大字符数 固定长度的字符或字符串【如果存入的长度不足定义的长度,则自动补空。因此,查询时,要去掉空字符】
Varchar = 1024,//n个字符: 1到32767个字节。字符集决定了其能容纳的最大字符数 变长字符或字符串类型
/// <summary>
/// 暂时以Varchar(5)代替。当内容为字符串“true”时,代表值为true;false类似;为空时表示为null或false(根据该值是否允许为空来决定)
/// </summary>
Boolean = 2048,//16位:True False Unkown 代表了逻辑上的真、假或不确定。必须是ODS11或以上版本,与Dialect无关。
//TODO:blob如何使用?
Blob = 4096,//变长: blob段大小限于64K 动态变长度二进制类型,可用于存放大量数据的情况,如图片、音乐、视频、多媒体等。其基本结构单位为段,它的子类型描述了存储数据的详细信息
}
//超出数据范围时报错:FbException。内容为:arithmetic exception, numeric overflow, or string truncation\r\nnumeric value is out of range【测试Integer类型的数据,存入2147483648报的这个错】
public static class FBTypeUtil
{
public static string ToTypeString(this FBType fbType)
{
switch (fbType) {
case FBType.Blob:
return "Blob";
case FBType.Boolean:
return "Varchar(5)";//TODO:由于没有bool类型,暂时以这个代替。详见FBType中的Boolean的说明
case FBType.Char:
return "Char";
case FBType.Date:
return "Date";
case FBType.Decimal:
return "Decimal";
case FBType.Double:
return "Double PRECISION";
case FBType.Float:
return "Float";
case FBType.Integer:
return "Integer";
case FBType.Numeric:
return "Numeric";
case FBType.SmallInt:
return "SmallInt";
case FBType.Time:
return "Time";
case FBType.Timestamp:
return "Timestamp";
case FBType.Varchar:
return "Varchar";
default:
#if DEBUG
throw new ApplicationException("未处理的类型");
#else
return "Varchar";
#endif
}
}
}
}