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[]              |                  |                                          |
   +-----------------------------+-----------------------+------------------+------------------------------------------+


   

写映射
------

有以下三个规则确定为参数发送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)   |                           |                             |                                  |
   +-----------------+---------------------------+-----------------------------+----------------------------------+

