Database field type/es

From Lazarus wiki
Jump to navigationJump to search

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.

ftADT:

ftArray:

ftAutoInc: an autoincrementing 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 number of bytes stored as-is. Needs to have its Size property set to work.

ftCurrency: a format to precisely store currency values.

ftCursor:

ftDBaseOle: presumably meant to store OLE objects in a DBase database. Needs to have its Size property set to work.

ftDataSet: presumably meant to store an entire dataset (possibly to implement master/detail table).

ftDate: a date without time information.

ftDateTime: date and time information.

ftFMTBcd: 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: presumably an ftMemo with multibyte characters.

ftWideString: presumably an ftString with multibyte characters.

ftWord: presumably stores an integer value

Note that for string type fields, Size indicates the number of characters that can be stored. DataSize indicates the field size in bytes. If you use multibyte characters like UTF8 or UTF16 do, 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.

Asignando y retornando valores

Una vez que se tienen definidos los campos en el dataset, se puede asignar y retornar datos en la siguiente manera - aquí se supone que se tiene un dataset llamado FTestDataset:

  FTestDataset.Open; //Abre para visualización/edición/inserción
  FTestDataset.Append;
  FTestDataset.FieldByName('TuNombreDeCampo').Asstring := 'Este es mi campo de datos'; //Supongamos que tu nombre de campo es del tipo memo
  FTestDataset.Post; //"Commit (acometer)"/save (salvar) los cambios en el campo al dataset
  WriteLn('Tú nombre de campo es:' + FTestDataset.FieldByName('TuNombreDeCampo').AsString 
  { Retorna el valor del campo en el registro actual. Como no hemos movido el campo deberíamos obtener justamente lo que acabemos de entrar }

Para campos de tipo text/memo, utilizar el método AsString. Para campos binarios, se supone que puede utilizarse el método AsString - pero debe haber algún otro modo además

ver además