Difference between revisions of "Database field type"

From Free Pascal wiki
Jump to navigationJump to search
m (Reverted edits by Ariben (talk) to last revision by Alextp)
Tag: Rollback
 
Line 1: Line 1:
{{Japanese Menu}}
+
{{Database field type}}
  
== 概略 ==
+
== Overview ==
FCL-DBデータベースフィールドは異なる種類のデータ型を持つことができる。データセットではこれらの型のサブセットが利用できる。どのような型がサポートされるかはデータセット型で異なる。
+
FCL-DB database fields can have different data types. In datasets, a subset of these types is available. What types are supported differ per dataset type.
  
== ==
+
== Types ==
現在、以下のフィールド型が定義されている。
+
Currently, the following field types are defined.
[http://lazarus-ccr.sourceforge.net/docs/fcl/db/tfieldtype.html FCLフィールド型ドキュメンテーション]を参照のこと。
+
See [http://lazarus-ccr.sourceforge.net/docs/fcl/db/tfieldtype.html FCL field type documentation].
To do: add assignment information (e.g. can you use .AsString) and additional information below.
+
To do: add assignment information (e.g. can you use .AsString) and additional information below.  
 
{| class="wikitable sortable"
 
{| class="wikitable sortable"
 
|-
 
|-
! フィールド型 || 内容
+
! Field type || Description
 
|-
 
|-
| ftADT || 抽象データ型 (サーバに生成されるユーザーにより定義される型); 未だサポートされていない(?)(->訳注ftADTはサポートされている模様)。
+
| ftADT || Abstract data type (user defined types created on the server); not supported yet (?).
 
|-
 
|-
| ftArray || Interbase 6 / Firebird 配列データ型 (可変長文字列あるいは整数のような簡単なデータ型). しかし、SQLDBは配列データ型を現在サポートされていない(訳注->ftArrayはサポートされている模様)。
+
| ftArray || Represents an Interbase 6 / Firebird array datatype (array of simple data-types like varchar or integer). However, SQLDB does not support the array datatype currently.
 
|-
 
|-
| ftAutoInc || 自動的に加算される整数フィールド。
+
| ftAutoInc || An auto-incrementing integer field.
 
|-
 
|-
| ftBCD || バイナリでコードされた10進数の浮動小数点値。
+
| ftBCD || A binary coded decimal floating point value.
 
|-
 
|-
| ftBlob || バイナリの大きなオブジェクト(BLOB)、任意のバイナリデータを格納するために作られた。
+
| ftBlob || A binary large object (BLOB), meant to store arbitrary binary data.
 
|-
 
|-
| ftBoolean || ブール値 (yes/no)
+
| ftBoolean || A boolean value (yes/no).
 
|-
 
|-
| ftBytes || おそらくそのまま格納される固定長byte。有効なSizeプロパティがある必要性あり。
+
| ftBytes || Presumably a fixed number of bytes stored as-is. Needs to have its Size property set to work.
 
|-
 
|-
| ftCurrency || 確実に格納される通貨値に対するフォーマット。
+
| ftCurrency || A format to precisely store currency values.
 
|-
 
|-
 
| ftCursor ||  
 
| ftCursor ||  
 
|-
 
|-
| ftDataSet || おそらくデータセット全体を格納するために作られたデータ型(マスター/詳細テーブルを実装する可能性のため)
+
| ftDataSet || Presumably meant to store an entire dataset (possibly to implement master/detail table).
 
|-
 
|-
| ftDate || 時刻情報を除く日付。
+
| ftDate || A date without time information.
 
|-
 
|-
| ftDateTime || 日付と時刻。
+
| ftDateTime || A date and time information.
 
|-
 
|-
| ftDBaseOle || おそらくOLEオブジェクトをDBaseに格納するために作られた型。有効なSizeプロパティがある必要性あり。
+
| ftDBaseOle || Presumably meant to store OLE objects in a DBase database. Needs to have its Size property set to work.
 
|-
 
|-
| ftFMTBcd || バイナリでコードされた10進数(BCD)フィールド。有効なSizeプロパティがある必要性あり。
+
| ftFMTBcd || A form of Binary Coded Decimal (BCD) number field. Needs to have its Size property set to work.
 
|-
 
|-
| ftFixedChar || 固定幅の文字フィールドPascalのshortstringに類似する。有効なSizeプロパティがある必要性あり。
+
| ftFixedChar || A fixed width character field, similar to a Pascal shortstring. Needs to have its Size property set to work.
 
|-
 
|-
| ftFixedWideChar || 固定長のマルチバイト文字フィールド。有効なSizeプロパティがある必要性あり。
+
| ftFixedWideChar || A fixed width multibyte character field. Needs to have its Size property set to work.
 
|-
 
|-
| ftFloat || 浮動小数点型
+
| ftFloat || A floating point numeric type.
 
|-
 
|-
| ftFmtMemo || 有効なSizeプロパティがある必要性あり。
+
| ftFmtMemo || Needs to have its Size property set to work.
 
|-
 
|-
| ftGraphic || 有効なSizeプロパティがある必要性あり。
+
| ftGraphic || Needs to have its Size property set to work.
 
|-
 
|-
| ftGuid || A field used to store a GUID (Globally Unique Identifier)のために使われるフィールド。現在のコードではこのフィールドのSizeは38に設定される必要がある。
+
| ftGuid || A field used to store a GUID (Globally Unique Identifier). With the current code, this field needs to have its Size property set to 38.
 
|-
 
|-
 
| ftIDispatch ||  
 
| ftIDispatch ||  
 
|-
 
|-
| ftInteger || 整数値フィールド
+
| ftInteger || An integer field.
 
|-
 
|-
 
| ftInterface ||  
 
| ftInterface ||  
 
|-
 
|-
| ftLargeint || 整数値を含むフィールド、ftIntegerよりも大きなbyteの整数値、ゆえに大きな幅を持つ。
+
| ftLargeint || A field that contains an integer, stores more bytes than an integer and therefore has a larger range.
 
|-
 
|-
| ftMemo || 可変長の文字/テキストを格納する: Sizeを設定する必要がない。
+
| ftMemo || Stores a variable amount of string/text data; needs no size set.
 
|-
 
|-
| ftOraBlob || おそらくOracle BLOBを格納する。
+
| ftOraBlob || Presumably stores Oracle BLOB.
 
|-
 
|-
| ftOraClob || おそらくOracle CLOB: 4GBまでのデータを保持できるOracleのデータ型[http://www.orafaq.com/wiki/CLOB]
+
| ftOraClob || Presumably stores Oracle CLOB: an Oracle data type that can hold up to 4 GB of data [http://www.orafaq.com/wiki/CLOB].
 
|-
 
|-
| ftParadoxOle || おそらくOLEオブジェクトをaradoxデータベースで格納されるために作られた型
+
| ftParadoxOle || Presumably meant to store OLE objects in a Paradox database.
 
|-
 
|-
 
| ftReference ||  
 
| ftReference ||  
 
|-
 
|-
| ftSmallint || ftIntegerよりも小さなbyteのための型。
+
| ftSmallint || An integer type field with less bytes than ftInteger.
 
|-
 
|-
| ftString || 文字列データを格納する。フィールドに入力可能な最大の文字数をプロパティとして指定する必要がある。
+
| ftString || Stores string data; needs to have its Size property set to the maximum number of characters possible in that field.
 
|-
 
|-
| ftTime || 時刻のみを格納する。
+
| ftTime || Stores time-only data.
 
|-
 
|-
| ftTimeStamp || 日付/時刻を格納する。おそらくftDateTimeと同等
+
| ftTimeStamp || Stores date/time data. Probably equivalent to ftDateTime.
 
|-
 
|-
| ftTypedBinary || ある種のBLOB様のフィールド?
+
| ftTypedBinary || Some kind of BLOB-like field?
 
|-
 
|-
 
| ftUnknown ||  
 
| ftUnknown ||  
 
|-
 
|-
| ftVarBytes || おそらくbyte/バイナリのバリアントデータ?
+
| ftVarBytes || Presumably a variant with byte/binary data?
 
|-
 
|-
| ftVariant || おそらくバリアントデータを格納するために作られた。
+
| ftVariant || Presumably meant to store variant data.
 
|-
 
|-
| ftWideMemo || ワイドストリング(UTF-16)ためのftMemo。
+
| ftWideMemo || An ftMemo with widestring (UTF-16) characters.
 
|-
 
|-
| ftWideString || ワイドストリング(UTF-16)ためのftString
+
| ftWideString || An ftString with widestring (UTF-16) characters.
 
|-
 
|-
| ftWord || おそらく整数値を格納する。
+
| ftWord || Presumably stores an integer value.
 
|}
 
|}
  
== サイズ、データサイズ、ユニコード ==
+
== Size, DataSize and Unicode ==
  
 
Note that for string type fields, Size indicates the number of characters that can be stored.  
 
Note that for string type fields, Size indicates the number of characters that can be stored.  
Line 102: Line 102:
 
If you use multibyte characters (e.g. UTF8 or UTF16/Unicodestring encoded), DataSize and Size do not mean the same thing. If you use only ANSI/ASCII characters, DataSize and Size are effectively the same thing.
 
If you use multibyte characters (e.g. UTF8 or UTF16/Unicodestring encoded), DataSize and Size do not mean the same thing. If you use only ANSI/ASCII characters, DataSize and Size are effectively the same thing.
  
== データセットの型を定義する ==
+
== Defining types in your dataset ==
  
 
''Todo: write me. Explain various ways of doing things (TFieldDef, TFields) and which dataset supports which methods.''
 
''Todo: write me. Explain various ways of doing things (TFieldDef, TFields) and which dataset supports which methods.''
  
== 値を割り当て取得する ==
+
== Assigning and retrieving values ==
 
Once you have the fields in your dataset defined, you can assign and retrieve data like this - suppose you have a dataset called FTestDataset:
 
Once you have the fields in your dataset defined, you can assign and retrieve data like this - suppose you have a dataset called FTestDataset:
  

Latest revision as of 19:36, 14 March 2024

English (en) español (es) français (fr) 日本語 (ja) 中文(中国大陆)‎ (zh_CN)

Overview

FCL-DB database fields can have different data types. In datasets, a subset of these types is available. What types are supported differ per dataset type.

Types

Currently, the following field types are defined. See FCL field type documentation. To do: add assignment information (e.g. can you use .AsString) and additional information below.

Field type Description
ftADT Abstract data type (user defined types created on the server); not supported yet (?).
ftArray Represents an Interbase 6 / Firebird array datatype (array of simple data-types like varchar or integer). However, SQLDB does not support the array datatype currently.
ftAutoInc An auto-incrementing integer field.
ftBCD A binary coded decimal floating point value.
ftBlob A binary large object (BLOB), meant to store arbitrary binary data.
ftBoolean A boolean value (yes/no).
ftBytes Presumably a fixed number of bytes stored as-is. Needs to have its Size property set to work.
ftCurrency A format to precisely store currency values.
ftCursor
ftDataSet Presumably meant to store an entire dataset (possibly to implement master/detail table).
ftDate A date without time information.
ftDateTime A date and time information.
ftDBaseOle Presumably meant to store OLE objects in a DBase database. Needs to have its Size property set to work.
ftFMTBcd A form of Binary Coded Decimal (BCD) number field. Needs to have its Size property set to work.
ftFixedChar A fixed width character field, similar to a Pascal shortstring. Needs to have its Size property set to work.
ftFixedWideChar A fixed width multibyte character field. Needs to have its Size property set to work.
ftFloat A floating point numeric type.
ftFmtMemo Needs to have its Size property set to work.
ftGraphic Needs to have its Size property set to work.
ftGuid A field used to store a GUID (Globally Unique Identifier). With the current code, this field needs to have its Size property set to 38.
ftIDispatch
ftInteger An integer field.
ftInterface
ftLargeint A field that contains an integer, stores more bytes than an integer and therefore has a larger range.
ftMemo Stores a variable amount of string/text data; needs no size set.
ftOraBlob Presumably stores Oracle BLOB.
ftOraClob Presumably stores Oracle CLOB: an Oracle data type that can hold up to 4 GB of data [1].
ftParadoxOle Presumably meant to store OLE objects in a Paradox database.
ftReference
ftSmallint An integer type field with less bytes than ftInteger.
ftString Stores string data; needs to have its Size property set to the maximum number of characters possible in that field.
ftTime Stores time-only data.
ftTimeStamp Stores date/time data. Probably equivalent to ftDateTime.
ftTypedBinary Some kind of BLOB-like field?
ftUnknown
ftVarBytes Presumably a variant with byte/binary data?
ftVariant Presumably meant to store variant data.
ftWideMemo An ftMemo with widestring (UTF-16) characters.
ftWideString An ftString with widestring (UTF-16) characters.
ftWord Presumably stores an integer value.

Size, DataSize and Unicode

Note that for string type fields, Size indicates the number of characters that can be stored. As indicated in FPC Unicode support#Introduction, FPC up to and including 2.6 only deals with ANSI/ASCII single byte characters; it does not support Unicode/UTF8/UTF16/Unicodestring characters.

The read-only property DataSize indicates the field size in bytes.

If you use multibyte characters (e.g. UTF8 or UTF16/Unicodestring encoded), DataSize and Size do not mean the same thing. If you use only ANSI/ASCII characters, DataSize and Size are effectively the same thing.

Defining types in your dataset

Todo: write me. Explain various ways of doing things (TFieldDef, TFields) and which dataset supports which methods.

Assigning and retrieving values

Once you have the fields in your dataset defined, you can assign and retrieve data like this - suppose you have a dataset called FTestDataset:

  FTestDataset.Open; //Open for viewing/editing/inserting
  FTestDataset.Append;
  FTestDataset.FieldByName('YourFieldName').AsString := 'This is my field data'; //Suppose field YourFieldName is a memo field
  FTestDataset.Post; //"Commit"/save changes in the record to the dataset.
  Writeln('YourFieldName has data:' + FTestDataset.FieldByName('YourFieldName').AsString);
  { Retrieve the field value of the current record. Because we haven't moved the record, we should get what we just entered }

For text/memo fields, use the AsString method. For date/time fields, use the AsDateTime method. For binary fields, I suppose you can use the AsString method - but there must be another way, too

See also