Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Базы";
Текущий архив: 2004.09.12;
Скачать: [xml.tar.bz2];

Вниз

Вариантный тип в 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;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.47 MB
Время: 0.043 c
14-1093269258
antonn
2004-08-23 17:54
2004.09.12
Программулина...


14-1091046073
Сергей Суровцев
2004-07-29 00:21
2004.09.12
И снова о вечном...


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


1-1093035441
ИМХО
2004-08-21 00:57
2004.09.12
The specified module could not be found.


4-1091164721
wild_arg
2004-07-30 09:18
2004.09.12
Контекстное меню





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский