Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.09.12;
Скачать: CL | DM;

Вниз

Вариантный тип в Firebird   Найти похожие ветки 

 
DmitryMN   (2004-08-13 16:24) [0]

Естьли возможность создания такого типа?
Или как передать в UDF-функцию любой тип данных?


 
y-soft ©   (2004-08-13 16:30) [1]

Работайте с Blob


 
DmitryMN   (2004-08-13 16:33) [2]

Мне нужно реализовать udf-функцию IsNull. Саму функцию реализовать несложно, но как в declare external fucntion передать любой тип данных?


 
Digitman ©   (2004-08-13 16:35) [3]


> DmitryMN   (13.08.04 16:33) [2]


by descriptor


 
Digitman ©   (2004-08-13 16:42) [4]


> DmitryMN


"внутри себя" FB оперирует как раз именно "вариантными" типами данных, т.е. данными, весьма схожими по организации и логике с variant-данными в различных известных средах программирования

передача в UDF параметра by descriptor подразумевает передачу адреса упр.структуры дескриптора, т.е. по сути - упр.структуры данных вариантного типа

вот примерный порототип , на базе которого можно строить UDF-модули с ф-циями, работающими с параметрами, передаваемыми по дескриптору :


unit DSC;

interface

uses Windows, SysUtils;

const
 // dsc_flags
 DSC_null = 1;
 DSC_no_subtype = 2; //dsc has no sub type specified
 DSC_nullable = 4;

 //dsc_dtype
 dtype_null = 0;
 dtype_text = 1;
 dtype_cstring = 2;
 dtype_varying = 3;
 dtype_packed = 6;
 dtype_byte = 7;
 dtype_short = 8;
 dtype_long = 9;
 dtype_quad = 10;
 dtype_real = 11;
 dtype_double = 12;
 dtype_d_float = 13;
 dtype_sql_date = 14;
 dtype_sql_time = 15;
 dtype_timestamp = 16;
 dtype_blob = 17;
 dtype_array = 18;
 dtype_int64 = 19;

type

 PVCharString = ^TVCharString;
 TVCharString = packed record
   Length: Smallint;
   Data: array[0..0] of Byte;
 end;

 TRegularText = packed record
   Data: array[0..0] of Byte;
 end;

 TCString = packed record
   Data: array[0..0] of Byte;
 end;

 // Descriptor format

 PDescriptor = ^TDescriptor;
 TDescriptor = packed record
  dsc_dtype: Byte;
  dsc_scale: ShortInt;
  dsc_length: Word;
  dsc_sub_type: Smallint;
  dsc_flags: Word;
  dsc_address: Pointer;
 end;
 TDSC = TDescriptor;
 PDSC = ^TDSC;

 // scalar array description

 TSAD_element = packed record
   sad_lower: Longint;
   sad_upper: Longint;
 end;

 PScalarArrayDescriptor = ^TScalarArrayDescriptor;
 TScalarArrayDescriptor = packed record
   sad_desc: TDSC;
   sad_dimensions: Longint;
   sad_rpt: array[0..0] of TSAD_element;
 end;
 TSAD = TScalarArrayDescriptor;
 SAD = TSAD;
 PSAD = ^TSAD;

 // array description

 TADS_element = packed record
   ads_desc: TDSC;         // element descriptor
   ads_length: Longint;    // length of "vector" element
   ads_lower: Longint;     // lower bound
   ads_upper: Longint;     // upper bound
 end;

 PArrayDescriptor = ^TArrayDescriptor;
 TArrayDescriptor = packed record
   ADS_version: Byte;                    // array descriptor version
   ADS_dimensions: Byte;                 // dimension of array
   ADS_struct_count: Word;               // number of array element
   ADS_element_length: Word;             // length of array element
   ADS_length: Word;                     // length of array descriptor
   ADS_count: DWord;                     // total number of elements
   ADS_total_length: DWord;              // total length of array
   ads_rpt: array[0..0] of TADS_element;
 end;
 TADS = TArrayDescriptor;
 ADS = TADS;
 PADS = ^TADS;

 function IsEmpty(Value: PDescriptor): Boolean;
 function IsNull(Value: PDescriptor): Boolean;
 function IsCardinal(Value: PDescriptor): Boolean;
 function IsShortInt(Value: PDescriptor): Boolean;
 function IsSmallInt(Value: PDescriptor): Boolean;
 function IsLongInt(Value: PDescriptor): Boolean;
 function IsInt64(Value: PDescriptor): Boolean;
 function IsString(Value: PDescriptor): Boolean;
 function IsFloat(Value: PDescriptor): Boolean;
 function IsReal(Value: PDescriptor): Boolean;
 function IsDouble(Value: PDescriptor): Boolean;
 function IsDFloat(Value: PDescriptor): Boolean;
 function IsBlob(Value: PDescriptor): Boolean;
 function IsDateTime(Value: PDescriptor): Boolean;
 function IsDate(Value: PDescriptor): Boolean;
 function IsTime(Value: PDescriptor): Boolean;
 function IsTimestamp(Value: PDescriptor): Boolean;
 function IsQuad(Value: PDescriptor): Boolean;
 function IsArray(Value: PDescriptor): Boolean;
 function GetData(Value: PDescriptor): Pointer;
 function GetSize(Value: PDescriptor): Word;

implementation

function IsEmpty(Value: PDescriptor): Boolean;
begin
 Result := Boolean(Value.dsc_flags and DSC_null);
end;

function IsNull(Value: PDescriptor): Boolean;
begin
 Result := Value.dsc_dtype = dtype_null;
end;

function IsCardinal(Value: PDescriptor): Boolean;
begin
 case Value.dsc_dtype of
   dtype_byte, dtype_short, dtype_long, dtype_int64, dtype_sql_date, dtype_sql_time: Result := True;
 else
   Result := False;
 end;
end;

function IsShortInt(Value: PDescriptor): Boolean;
begin
 Result := Value.dsc_dtype = dtype_byte;
end;

function IsSmallInt(Value: PDescriptor): Boolean;
begin
 Result := Value.dsc_dtype = dtype_short;
end;

function IsLongInt(Value: PDescriptor): Boolean;
begin
 Result := Value.dsc_dtype = dtype_long;
end;

function IsInt64(Value: PDescriptor): Boolean;
begin
 Result := Value.dsc_dtype = dtype_int64;
end;

function IsString(Value: PDescriptor): Boolean;
begin
 case Value.dsc_dtype of
   dtype_text, dtype_cstring, dtype_varying: Result := True;
 else
   Result := False;
 end;
end;

function IsFloat(Value: PDescriptor): Boolean;
begin
 case Value.dsc_dtype of
   dtype_real, dtype_double, dtype_d_float: Result := True;
 else
   Result := False;
 end;
end;

function IsReal(Value: PDescriptor): Boolean;
begin
 Result := Value.dsc_dtype = dtype_real;
end;

function IsDouble(Value: PDescriptor): Boolean;
begin
 Result := Value.dsc_dtype = dtype_double;
end;

function IsDFloat(Value: PDescriptor): Boolean;
begin
 Result := Value.dsc_dtype = dtype_d_float;
end;

function IsBlob(Value: PDescriptor): Boolean;
begin
 Result := Value.dsc_dtype = dtype_blob;
end;

function IsDateTime(Value: PDescriptor): Boolean;
begin
 case Value.dsc_dtype of
   dtype_timestamp, dtype_quad, dtype_sql_date, dtype_sql_time: Result := True;
 else
   Result := False;
 end;
end;

function IsDate(Value: PDescriptor): Boolean;
begin
 Result := Value.dsc_dtype = dtype_sql_date;
end;

function IsTime(Value: PDescriptor): Boolean;
begin
 Result := Value.dsc_dtype = dtype_sql_time;
end;

function IsTimestamp(Value: PDescriptor): Boolean;
begin
 Result := Value.dsc_dtype = dtype_timestamp;
end;

function IsQuad(Value: PDescriptor): Boolean;
begin
 Result := Value.dsc_dtype = dtype_quad;
end;

function IsArray(Value: PDescriptor): Boolean;
begin
 Result := Value.dsc_dtype = dtype_array;
end;

function GetData(Value: PDescriptor): Pointer;
begin
 Result := Value.dsc_address;
end;

function GetSize(Value: PDescriptor): Word;
begin
 Result := Value.dsc_length;
end;

end.


 
Fay ©   (2004-08-13 22:47) [5]

2 Digitman ©   (13.08.04 16:42) [4]
А зачем uses Windows, SysUtils;?



Страницы: 1 вся ветка

Текущий архив: 2004.09.12;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.046 c
14-1093462970
YurikGL
2004-08-25 23:42
2004.09.12
Совет по железу


14-1093204390
gn
2004-08-22 23:53
2004.09.12
самый быстрый


14-1092038514
Mystic
2004-08-09 12:01
2004.09.12
Новая версия шашечной программы


14-1092970149
Думкин
2004-08-20 06:49
2004.09.12
С днем рождения! 20 августа


3-1092818243
nv_
2004-08-18 12:37
2004.09.12
ADOConnection: Как создать *.udl?