Difference between revisions of "データベースフィールド型"

From Free Pascal wiki
Jump to navigationJump to search
(Created page with "{{Japanese Menu}} == 概略 == FCL-DBデータベースフィールドは異なる種類のデータ型を持つことができる。データセットではこれらの型...")
 
 
(3 intermediate revisions by the same user not shown)
Line 94: Line 94:
  
 
== サイズ、データサイズ、ユニコード ==
 
== サイズ、データサイズ、ユニコード ==
 +
文字列型のフィールドでは、Sizeは格納することのできる文字の数を指していることに注意すること。 [[FPC Unicode support#Introduction]]に示されている通り、FPCは2.6まで'''ANSI/ASCII'''シングルバイト文字列のみ取り扱い、ユニコード/UTF8/UTF16/ユニコード文字列はサポートされていない。
  
Note that for string type fields, Size indicates the number of characters that can be stored.
+
読み込みのみのDataSizeはbyteで表されたフィールドサイズである。
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.
+
もし、マルチバイト文字(例えば、UTF8もしくはUTF16/ユニコードエンコードの文字)を用いていると、DataSizeとSize同じことを意味しない。もしANSI/ASCIIのみを用いているなら、DataSizeとSizeは文字通り同じものとなる。
 
 
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.
 
  
 
== データセットの型を定義する ==
 
== データセットの型を定義する ==
Line 107: Line 105:
  
 
== 値を割り当て取得する ==
 
== 値を割り当て取得する ==
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と仮定すると、このようにデータを取得できる:
  
 
<syntaxhighlight lang=pascal>
 
<syntaxhighlight lang=pascal>
   FTestDataset.Open; //Open for viewing/editing/inserting
+
   FTestDataset.Open; //見る、編集する、挿入するため開く
 
   FTestDataset.Append;
 
   FTestDataset.Append;
   FTestDataset.FieldByName('YourFieldName').AsString := 'This is my field data'; //Suppose field YourFieldName is a memo field
+
   FTestDataset.FieldByName('YourFieldName').AsString := 'This is my field data'; //YourFieldNameがmemoフィールドと仮定する
 
   FTestDataset.Post; //"Commit"/save changes in the record to the dataset.
 
   FTestDataset.Post; //"Commit"/save changes in the record to the dataset.
 
   Writeln('YourFieldName has data:' + FTestDataset.FieldByName('YourFieldName').AsString);
 
   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 }
+
   { 現在のレコードのフィールドの値を取得する。レコードを移動していないので、入力したものが得られるはずである }
 
</syntaxhighlight>
 
</syntaxhighlight>
  
For text/memo fields, use the AsString method.
+
Text/memoフィールドには、AsStringメソッドを用いること
For date/time fields, use the AsDateTime method.
+
Date/timeフィールドには、AsDateTimeメソッドを用いること
For binary fields, I suppose you can use the AsString method - ''but there must be another way, too''
+
バイナリフィールドにはAsStringメソッドを用いることができると思うが - '''ほかのやり方があるはずである'''
  
==See also==
+
==以下も参照のこと==
  
* [[Databases]]
+
* [[Databases/ja]]

Latest revision as of 13:22, 14 March 2024

日本語版メニュー
メインページ - Lazarus Documentation日本語版 - 翻訳ノート - 日本語障害情報

概略

FCL-DBデータベースフィールドは異なる種類のデータ型を持つことができる。データセットではこれらの型のサブセットが利用できる。どのような型がサポートされるかはデータセット型で異なる。

現在、以下のフィールド型が定義されている。 FCLフィールド型ドキュメンテーションを参照のこと。 To do: add assignment information (e.g. can you use .AsString) and additional information below.

フィールド型 内容
ftADT 抽象データ型 (サーバに生成されるユーザーにより定義される型); 未だサポートされていない(?)(->訳注ftADTはサポートされている模様)。
ftArray Interbase 6 / Firebird 配列データ型 (可変長文字列あるいは整数のような簡単なデータ型). しかし、SQLDBは配列データ型を現在サポートされていない(訳注->ftArrayはサポートされている模様)。
ftAutoInc 自動的に加算される整数フィールド。
ftBCD バイナリでコードされた10進数の浮動小数点値。
ftBlob バイナリの大きなオブジェクト(BLOB)、任意のバイナリデータを格納するために作られた。
ftBoolean ブール値 (yes/no)。
ftBytes おそらくそのまま格納される固定長byte。有効なSizeプロパティがある必要性あり。
ftCurrency 確実に格納される通貨値に対するフォーマット。
ftCursor
ftDataSet おそらくデータセット全体を格納するために作られたデータ型(マスター/詳細テーブルを実装する可能性のため)。
ftDate 時刻情報を除く日付。
ftDateTime 日付と時刻。
ftDBaseOle おそらくOLEオブジェクトをDBaseに格納するために作られた型。有効なSizeプロパティがある必要性あり。
ftFMTBcd バイナリでコードされた10進数(BCD)フィールド。有効なSizeプロパティがある必要性あり。
ftFixedChar 固定幅の文字フィールドPascalのshortstringに類似する。有効なSizeプロパティがある必要性あり。
ftFixedWideChar 固定長のマルチバイト文字フィールド。有効なSizeプロパティがある必要性あり。
ftFloat 浮動小数点型
ftFmtMemo 有効なSizeプロパティがある必要性あり。
ftGraphic 有効なSizeプロパティがある必要性あり。
ftGuid A field used to store a GUID (Globally Unique Identifier)のために使われるフィールド。現在のコードではこのフィールドのSizeは38に設定される必要がある。
ftIDispatch
ftInteger 整数値フィールド
ftInterface
ftLargeint 整数値を含むフィールド、ftIntegerよりも大きなbyteの整数値、ゆえに大きな幅を持つ。
ftMemo 可変長の文字/テキストを格納する: Sizeを設定する必要がない。
ftOraBlob おそらくOracle BLOBを格納する。
ftOraClob おそらくOracle CLOB: 4GBまでのデータを保持できるOracleのデータ型[1]
ftParadoxOle おそらくOLEオブジェクトをaradoxデータベースで格納されるために作られた型
ftReference
ftSmallint ftIntegerよりも小さなbyteのための型。
ftString 文字列データを格納する。フィールドに入力可能な最大の文字数をプロパティとして指定する必要がある。
ftTime 時刻のみを格納する。
ftTimeStamp 日付/時刻を格納する。おそらくftDateTimeと同等
ftTypedBinary ある種のBLOB様のフィールド?
ftUnknown
ftVarBytes おそらくbyte/バイナリのバリアントデータ?
ftVariant おそらくバリアントデータを格納するために作られた。
ftWideMemo ワイドストリング(UTF-16)ためのftMemo。
ftWideString ワイドストリング(UTF-16)ためのftString
ftWord おそらく整数値を格納する。

サイズ、データサイズ、ユニコード

文字列型のフィールドでは、Sizeは格納することのできる文字の数を指していることに注意すること。 FPC Unicode support#Introductionに示されている通り、FPCは2.6までANSI/ASCIIシングルバイト文字列のみ取り扱い、ユニコード/UTF8/UTF16/ユニコード文字列はサポートされていない。

読み込みのみのDataSizeはbyteで表されたフィールドサイズである。

もし、マルチバイト文字(例えば、UTF8もしくはUTF16/ユニコードエンコードの文字)を用いていると、DataSizeとSize同じことを意味しない。もしANSI/ASCIIのみを用いているなら、DataSizeとSizeは文字通り同じものとなる。

データセットの型を定義する

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

値を割り当て取得する

一度、データセットにフィールドを定義すると、データセットの名前がFTestDatasetと仮定すると、このようにデータを取得できる:

  FTestDataset.Open; //見る、編集する、挿入するため開く
  FTestDataset.Append;
  FTestDataset.FieldByName('YourFieldName').AsString := 'This is my field data'; //YourFieldNameがmemoフィールドと仮定する
  FTestDataset.Post; //"Commit"/save changes in the record to the dataset.
  Writeln('YourFieldName has data:' + FTestDataset.FieldByName('YourFieldName').AsString);
  { 現在のレコードのフィールドの値を取得する。レコードを移動していないので、入力したものが得られるはずである }

Text/memoフィールドには、AsStringメソッドを用いること Date/timeフィールドには、AsDateTimeメソッドを用いること バイナリフィールドにはAsStringメソッドを用いることができると思うが - ほかのやり方があるはずである

以下も参照のこと