Firebird Tarih UDF sinde Aynı Değeri Döndürüyo

Firebird ve Interbase veritabanları ve SQL komutlarıyla ilgli sorularınızı sorabilirsiniz. Delphi tarafındaki sorularınızı lütfen Programlama forumunda sorunuz.
Cevapla
Kullanıcı avatarı
mustafaozdemir
Üye
Mesajlar: 137
Kayıt: 19 Haz 2004 01:56

Firebird Tarih UDF sinde Aynı Değeri Döndürüyo

Mesaj gönderen mustafaozdemir »

S.A. Arkadaşlar.
Verilen tarihin hangi güne ait olduğunu bulan bi UDF yazdım ama hangi tarihi verirsem vereyim hep CUMARTESI döndürüyor. Bunu yapan UDF ler var ama ben kendimin oluşturduğu DLL i kullanmak istiyorum. Hem öğrenmek maksatlı.

Delphideki Library kısmı:

Kod: Tümünü seç

library PDKS_Udf;
uses
  SysUtils,
  Classes,
  Unit1 in 'Unit1.pas';

{$R *.res}
  exports
  gunbul,
  Topla;
begin
end.

Kod: Tümünü seç

unit Unit1;

interface
function gunbul(tarih:TDateTime):pchar;cdecl;export;

implementation

uses SysUtils,ib_util,math,dateutils;

function gunbul(tarih:Tdatetime):pchar;
begin
  case dayofweek(tarih) of
  1:Result:='PAZAR';
  2:Result:='PAZARTESI';
  3:Result:='SALI';
  4:Result:='CARSAMBA';
  5:Result:='PERSEMBE';
  6:Result:='CUMA';
  7:Result:='CUMARTESI';
  end;
end;

end.
 
Firebird de funcitonu tanımlama:

Kod: Tümünü seç

DECLARE EXTERNAL FUNCTION GUNBUL
DATE
RETURNS CSTRING(9) FREE_IT
ENTRY_POINT 'gunbul' MODULE_NAME 'PDKS_Udf'
Nerde hata yapıyorum hala anlamış değilim :(
Kullanıcı avatarı
aslangeri
Moderator
Mesajlar: 4322
Kayıt: 26 Ara 2003 04:19
Konum: Ankara
İletişim:

Mesaj gönderen aslangeri »

s.a.
tiplerle ilgili olabilir.
kodda tdatetime belirtmişsin. ama fb da date göndermişsin.
Duyduğun Şeylerin Söylediklerim Olduğuna Eminim Ama
Anladığın Şeylerin Anlatmak İstediklerim Olduğuna Emin Değilim
Kullanıcı avatarı
mustafaozdemir
Üye
Mesajlar: 137
Kayıt: 19 Haz 2004 01:56

Mesaj gönderen mustafaozdemir »

@aslangeri arkadaşım firebird de timestamp olarak ta denedim olmadı. Yine aynı sorun.
fduman
Moderator
Mesajlar: 2749
Kayıt: 17 Ara 2004 12:02
Konum: Ankara

Mesaj gönderen fduman »

Firebird tarih verisini TDateTime olarak mı gönderiyor ki? Zannetmiyorum. Delphi DateTime formatını kendine özel bir şekilde tutuyor. Firebird de kendine has bir formatta tutuyor olabilir.
fduman
Moderator
Mesajlar: 2749
Kayıt: 17 Ara 2004 12:02
Konum: Ankara

Mesaj gönderen fduman »

Evet LONG olarak kendine has bir şekilde tutuyormuş. Date değeri nasıl alacağın ve ayrıştıracağın burada anlatılmış.
fduman
Moderator
Mesajlar: 2749
Kayıt: 17 Ara 2004 12:02
Konum: Ankara

Mesaj gönderen fduman »

Arşiv olması açısından:
Let's build some date routines

In InterBase 6, three different "date" types are supported, DATE, TIME, and TIMESTAMP. For those familiar with InterBase 5.5 and older, the TIMESTAMP data type is exactly the equivalent of the 5.5 DATE type.

In order to "decode" and "encode" these types into something meaningful for your Delphi program, you need a "little bit" of information about the InterBase API. In your unit, put the following code:

interface
...

type

TM = record
tm_sec : integer; // Seconds
tm_min : integer; // Minutes
tm_hour : integer; // Hour (0--23)
tm_mday : integer; // Day of month (1--31)
tm_mon : integer; // Month (0--11)
tm_year : integer; // Year (calendar year minus 1900)
tm_wday : integer; // Weekday (0--6) Sunday = 0)
tm_yday : integer; // Day of year (0--365)
tm_isdst : integer; // 0 if daylight savings time is not in effect)
end;

PTM = ^TM;

ISC_TIMESTAMP = record
timestamp_date : Long;
timestamp_time : ULong;
end;

PISC_TIMESTAMP = ^ISC_TIMESTAMP;

implementation
...

procedure isc_encode_timestamp (tm_date: PTM;
ib_date: PISC_TIMESTAMP);
stdcall; external IBASE_DLL;

procedure isc_decode_timestamp (ib_date: PISC_TIMESTAMP;
tm_date: PTM);
stdcall; external IBASE_DLL;


procedure isc_decode_sql_date (var ib_date: Long;
tm_date: PTM);
stdcall; external IBASE_DLL;

procedure isc_encode_sql_date (tm_date: PTM;
var ib_date: Long);
stdcall; external IBASE_DLL;



procedure isc_decode_sql_time (var ib_date: ULong;
tm_date: PTM);
stdcall; external IBASE_DLL;

procedure isc_encode_sql_time (tm_date: PTM;
var ib_date: ULong);
stdcall; external IBASE_DLL;

Now, let's write some date UDFs!

In the interface section of the newly created unit, type the following declaration:

function Year(var ib_date: Long): Integer; cdecl; export;
function Hour(var ib_time: ULong): Integer; cdecl; export;

In the implementation section of the unit, type:

function Year(var ib_date: Long): Integer;
var
tm_date: TM;
begin
isc_decode_sql_date(@ib_date, @tm_date);
result := tm_date.tm_year + 1900;
end;

function Hour(var ib_time: ULong): Integer;
var
tm_date: TM;
begin
isc_decode_sql_time(@ib_time, @tm_date);
result := tm_date.tm_hour;
end;
Kullanıcı avatarı
mustafaozdemir
Üye
Mesajlar: 137
Kayıt: 19 Haz 2004 01:56

Mesaj gönderen mustafaozdemir »

Hepinize teşekkürler arkadaşlar. Bi deneyim durumu göreyim.
Kullanıcı avatarı
mege
Admin
Mesajlar: 2360
Kayıt: 05 Şub 2004 04:32
Konum: Beşiktaş
İletişim:

Mesaj gönderen mege »

bunu sp içerisinde karşılaştırıp udf siz değerde döndürebilirsin,

Kod: Tümünü seç

select x,y,z,EXTRACT(WEEKDAY FROM current_timestamp) from ...
http://www.janus-software.com/fbmanual/ ... L&topic=50
.-.-.-.-.-.-.-. ^_^
Kullanıcı avatarı
mustafaozdemir
Üye
Mesajlar: 137
Kayıt: 19 Haz 2004 01:56

Mesaj gönderen mustafaozdemir »

Sağol @mege dediğin gibi de oluyo.
Kullanıcı avatarı
mustafaozdemir
Üye
Mesajlar: 137
Kayıt: 19 Haz 2004 01:56

Mesaj gönderen mustafaozdemir »

S.A.

Kod: Tümünü seç

timestamp_date : Long; 
timestamp_time : ULong;
Arkadaşlar yukarıda satırda Long ve Ulong tiplerinde hata verdi. ib_util unitini ekledim. Delphide Library e Firebird ün Bin ve İnclude klasörlerinin pathinide verdim. Yine tanımsız tip hatası alıyorum. :roll:
Cevapla