Kdbndp支持的类型和类型映射
==========================

下面列出了将CLR类型读取和写入KingbaseES类型时的内置映射。


读取映射
--------

下面显示了读取值时使用的映射

-  使用和类似方式：KdbndpCommand.ExecuteScalar()，将返回默认类型KdbndpDataReader.GetValue()；

-  可以通过调用读取为其它类型：KdbndpDataReader.GetFieldValue()；

-  提供程序特定的类型并返回：KdbndpDataReader.GetProviderSpecificvalValue()。


.. table:: SQLServer模式读取数据时 KingbaseES 数据类型和.NET 类型之间映射
   :class: longtable

   +---------------------+---------------+---------------------+------------------------------------------+
   | KingbaseES 数据类型 | 默认.NET 类型 | 提供者特定的类型    | 其他.NET 类型                            |
   +=====================+===============+=====================+==========================================+
   | bit                 | sbyte         | SqlServer_Bit       | bool                                     |
   +---------------------+---------------+---------------------+------------------------------------------+
   | tinyint             | byte          | SqlServer_Tinyint   | byte,sbyte,int,long,float,double,decimal |
   +---------------------+---------------+---------------------+------------------------------------------+
   | smallint            | int16         | SqlServer_Smallint  | byte,sbyte,int,long,float,double,decimal |
   +---------------------+---------------+---------------------+------------------------------------------+
   | int                 | int32         | SqlServer_Int       | byte,sbyte,int,long,float,double,decimal |
   +---------------------+---------------+---------------------+------------------------------------------+
   | bigint              | int64         | SqlServer_Bigint    | byte,sbyte,int,long,float,double,decimal |
   +---------------------+---------------+---------------------+------------------------------------------+
   | decimal             | decimal       | SqlServer_Numeric   | byte,short,int,long,float,double         |
   +---------------------+---------------+---------------------+------------------------------------------+
   | money               | decimal       | SqlServer_Money     |                                          |
   +---------------------+---------------+---------------------+------------------------------------------+
   | numeric             | decimal       | SqlServer_Numeric   | byte,short,int,long,float,double         |
   +---------------------+---------------+---------------------+------------------------------------------+
   | float               | double        | SqlServer_Float     |                                          |
   +---------------------+---------------+---------------------+------------------------------------------+
   | real                | single        | SqlServer_Real      |                                          |
   +---------------------+---------------+---------------------+------------------------------------------+
   | date                | DateTime2     | SqlServer_Date      |                                          |
   +---------------------+---------------+---------------------+------------------------------------------+
   | time                | TimeSpan      | SqlServer_Time      |                                          |
   +---------------------+---------------+---------------------+------------------------------------------+
   | datetime            | DateTime2     | SqlServer_DateTime  |                                          |
   +---------------------+---------------+---------------------+------------------------------------------+
   | datetime2           | DateTime      | DateTime2           |                                          |
   +---------------------+---------------+---------------------+------------------------------------------+
   | smalldatetime       | DateTime      | SmallDateTime       |                                          |
   +---------------------+---------------+---------------------+------------------------------------------+
   | varchar             | string        | VarcharByte         | char[]                                   |
   +---------------------+---------------+---------------------+------------------------------------------+
   | char                | string        | CharByte            | char[]                                   |
   +---------------------+---------------+---------------------+------------------------------------------+
   | varchar             | string        | VarcharByte         | char[]                                   |
   +---------------------+---------------+---------------------+------------------------------------------+
   | Nchar               | string        | Nchar               | char[]                                   |
   +---------------------+---------------+---------------------+------------------------------------------+
   | nvarchar            | string        | NVarchar            | char[]                                   |
   +---------------------+---------------+---------------------+------------------------------------------+
   | text                | string        | Sqlserver_Text      | char[]                                   |
   +---------------------+---------------+---------------------+------------------------------------------+
   | ntext               | string        | Sqlserver_Ntext     | char[]                                   |
   +---------------------+---------------+---------------------+------------------------------------------+
   | binary(N)           | Byte[]        | SqlServer_Binary    |                                          |
   +---------------------+---------------+---------------------+------------------------------------------+
   | varbinary(N)        | Byte[]        | SqlServer_VarBinary |                                          |
   +---------------------+---------------+---------------------+------------------------------------------+
   | Image               | Byte[]        | Image               |                                          |
   +---------------------+---------------+---------------------+------------------------------------------+


   

写映射
------

有以下三个规则确定为参数发送KingbaseES类型：

-  如果参数设置了KdbndpDbType,则使用它；

-  如果参数设置了DataType,则使用它；

-  如果参数设置了DbType，则使用它；

-  如果未设置上述任何一项，则将从CLR值类型推断后端类型。


.. table:: SQLServer模式写数据时KingbaseES 数据类型和 .NET类型之间映射  
   :class: longtable

   +---------------------+---------------+-----------------+------------------------------------------+
   | KdbndpDbType        | DbType        | KingbaseES 类型 | 可接受的.NET 类型                        |
   +=====================+===============+=================+==========================================+
   | SqlServer_Bit       | Boolean       | bit             | sbyte,bool                               |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SqlServer_Tinyint   | Byte          | tinyint         | byte,sbyte,int,long,float,double,decimal |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SqlServer_Smallint  | Int16         | smallint        | byte,sbyte,int,long,float,double,decimal |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SqlServer_Int       | Int32         | int             | byte,sbyte,int,long,float,double,decimal |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SqlServer_Bigint    | Int64         | bigint          | byte,sbyte,int,long,float,double,decimal |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SqlServer_Numeric   | Decimal       | decimal         | byte,short,int,long,float,double         |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SqlServer_Money     | Decimal       | money           |                                          |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SqlServer_Numeric   | Decimal       | numeric         | byte,short,int,long,float,double         |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SqlServer_Float     | Single,Double | float           | double                                   |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SqlServer_Real      | single        | real            |                                          |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SqlServer_Date      | DateTime      | date            |                                          |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SqlServer_Time      |               | time            | timespan                                 |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SqlServer_DateTime  | DateTime      | datetime        |                                          |
   +---------------------+---------------+-----------------+------------------------------------------+
   | DateTime2           | DateTime      | char            | char[]                                   |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SmallDateTime       | DateTime      | varchar         | char[]                                   |
   +---------------------+---------------+-----------------+------------------------------------------+
   | CharByte            | string        | char            | char[]                                   |
   +---------------------+---------------+-----------------+------------------------------------------+
   | VarcharByte         | string        | varchar         | char[]                                   |
   +---------------------+---------------+-----------------+------------------------------------------+
   | Nchar               | string        | nchar           | char[]                                   |
   +---------------------+---------------+-----------------+------------------------------------------+
   | NVarchar            | string        | nvarchar        | char[]                                   |
   +---------------------+---------------+-----------------+------------------------------------------+
   | Sqlserver_Text      | string        | text            | char[]                                   |
   +---------------------+---------------+-----------------+------------------------------------------+
   | Sqlserver_Ntext     | string        | ntext           | char[]                                   |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SqlServer_Binary    |               | binary(N)       | Byte[]                                   |
   +---------------------+---------------+-----------------+------------------------------------------+
   | SqlServer_VarBinary |               | varbinary(N)    | Byte[]                                   |
   +---------------------+---------------+-----------------+------------------------------------------+
   | Image               |               | Image           | Byte[]                                   |
   +---------------------+---------------+-----------------+------------------------------------------+
