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

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

- 读取映射_
- 写映射_

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

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

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

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

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


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

   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | KingbaseES 数据类型         | 默认.NET类型          | 提供者特定的类型 | 其他.NET类型                             |
   +=============================+=======================+==================+==========================================+
   | boolean                     | bool                  |                  |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | smallint                    | int                   |                  | byte,sbyte,int,long,float,double,decimal |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | bigint                      | long                  |                  | byte,short,long,float,double,decimal     |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | integer                     | int                   |                  | byte,short,long,float,double,decimal     |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | real                        | float                 |                  | double                                   |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | double                      | precision             | double           |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | numeric                     | decimal               |                  | byte,short,int,long,float,double         |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | money                       | decimal               |                  |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | text                        | string                |                  | char[]                                   |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | character varying           | string                |                  | char[]                                   |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | character                   | string                |                  | char[]                                   |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | citext                      | string                |                  | char[]                                   |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | json                        | string                |                  | char[]                                   |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | jsonb                       | string                |                  | char[]                                   |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | xml                         | string                |                  | char[]                                   |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | oid                         | uint                  |                  |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | xid                         | uint                  |                  |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | cid                         | uint                  |                  |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | byte                        | byte[]                |                  |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | bit(1)                      | bool                  |                  | BitArray                                 |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | bit(n)                      | BitArray              |                  |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | bit varying                 | BitArray              |                  |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | uuid                        | Guid                  |                  |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | date                        | DataTime              | KdbndpData       |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | interval                    | TimeSpan              | KdbndpDataSpan   |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | timestamp without time zone | DataTime(Unspecified) | KdbndpDataTime   |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | timestamp with time zone    | DataTime(Local)       | KdbndpDataTime   | DateTimeOffset                           |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | time without time zone      | TimeSpan              |                  |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | time with time zone         | DataTimeOffset        |                  | DataTimeOffset,DataTime,TimeSpan         |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | name                        | string                |                  | char[]                                   |
   +-----------------------------+-----------------------+------------------+------------------------------------------+
   | record                      | object[]              |                  |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+


.. 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                | DateTime      | SqlServer_Date     |                                          |
   +---------------------+---------------+--------------------+------------------------------------------+
   | time                | TimeSpan      | SqlServer_Time     |                                          |
   +---------------------+---------------+--------------------+------------------------------------------+
   | datetime            | DateTime      | SqlServer_DateTime |                                          |
   +---------------------+---------------+--------------------+------------------------------------------+
   | char                | string        | CharByte           | char[]                                   |
   +---------------------+---------------+--------------------+------------------------------------------+
   | varchar             | string        | VarcharByte        | char[]                                   |
   +---------------------+---------------+--------------------+------------------------------------------+
   | nchar               | string        | Nchar              | char[]                                   |
   +---------------------+---------------+--------------------+------------------------------------------+
   | nvarchar            | string        | NVarchar           | char[]                                   |
   +---------------------+---------------+--------------------+------------------------------------------+
   | binary(N)           | Byte[]        | Binary             |                                          |
   +---------------------+---------------+--------------------+------------------------------------------+
   | varbinary(N)        | Byte[]        | VarBinary          |                                          |
   +---------------------+---------------+--------------------+------------------------------------------+


   

写映射
------

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

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

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

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

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


.. table:: Oracle模式写数据时KingbaseES 数据类型和 .NET类型之间映射
   :widths: 2 2 2 3   
   :class: longtable
      
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | KdbndpDbType    | DbType                    | KingbaseES类型              | 可接受的.NET类型                 |
   +=================+===========================+=============================+==================================+
   | Boolean         | Boolean                   | boolean                     | bool                             |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | smallint        | Int16                     | smallint                    | short                            |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Integer         | Int32                     | integer                     | int                              |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Bigint          | Int64                     | bigint                      | long                             |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Real            | Single                    | real                        | float                            |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Double          | Double                    | double precision            | double                           |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Numeric         | Decimal,VarNumeric        | numeric                     | decimal                          |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Money           | Currency                  | money                       | decimal                          |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Text            | String,StringFixedLength, | text                        | string,char[],char               |
   |                 | AnsiString,               |                             |                                  |
   |                 | AnsiStringFixedLength     |                             |                                  |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Varchar         | character varying         | text                        | string,char[],char               |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Char            |                           | character varying           | string,char[],char               |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Citext          |                           | citext                      | string,char[],char               |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Json            |                           | json                        | string,char[],char               |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Jsonb           |                           | jsonb                       | string,char[],char               |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Xml             |                           | xml                         | string,char[],char               |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Bit             |                           | bit                         | BitArray,bool,string             |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Varbit          | bit varying               |                             | BitArray,bool,string             |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Hstore          |                           | hstore                      | IDictionary                      |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Uuid            |                           | uuid                        | Guid                             |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Date            | Date                      | date                        | DateTime,KdbndpDate              |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Interval        |                           | interval                    | TimeSpan,KdbndpTimeSpan          |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Timestamp       | DateTime,DateTime2        | timestamp without time zone | DateTime,KdbndpDataTime          |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | TimestampTz     | DateTimeOffset            | timestamp with time zone    | DateTimeOffset,DateTime,TimeSpan |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Time            | Time                      | time without time zone      | TimeSpan                         |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | TimeTz          |                           | time with time zone         | DateTimeOffset,DateTime,TimeSpan |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Bytea           | Binary                    | bytea                       | byte[],ArraySegment              |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Oid             |                           | oid                         | uint                             |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Xid             |                           | oid                         | uint                             |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Cid             |                           | cid                         | uint                             |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Oidvector       |                           | oidvector                   | uint[]                           |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Name            |                           | name                        | string,char[],char               |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | InternalChar    |                           | (internal)char              | byte                             |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Composite       |                           | composite types             | T                                |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Range | (other  |                           | range types                 | KdbndpRange                      |
   | KdbndpDbType)   |                           |                             |                                  |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Enum            |                           | enum types                  | TEnum                            |
   +-----------------+---------------------------+-----------------------------+----------------------------------+
   | Array | (other  |                           | arrays types                | Array,IList,IList                |
   | KdbndpDbType)   |                           |                             |                                  |
   +-----------------+---------------------------+-----------------------------+----------------------------------+


.. 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        |                                          |
   +--------------------+---------------+-----------------+------------------------------------------+
   | CharByte           | string        | char            | char[]                                   |
   +--------------------+---------------+-----------------+------------------------------------------+
   | VarcharByte        | string        | varchar         | char[]                                   |
   +--------------------+---------------+-----------------+------------------------------------------+
   | Nchar              | string        | nchar           | char[]                                   |
   +--------------------+---------------+-----------------+------------------------------------------+
   | NVarchar           | string        | nvarchar        | char[]                                   |
   +--------------------+---------------+-----------------+------------------------------------------+
   | Binary             |               | binary(N)       | Byte[]                                   |
   +--------------------+---------------+-----------------+------------------------------------------+
   | VarBinary          |               | varbinary(N)    | Byte[]                                   |
   +--------------------+---------------+-----------------+------------------------------------------+
