Subject | Re: Timestamp variable with fractional seconds |
---|---|
Author | nxciro |
Post date | 2005-02-08T02:30:34Z |
Fractional seconds in timestamps can be achieved like this
Tested with FB1.5.2 and Delphi 7
1. use ibexpert or similar to register the UDF GETEXACTTIMESTAMP
here is how the metadata should look like afterwards
/* External Function declarations */
DECLARE EXTERNAL FUNCTION GETEXACTTIMESTAMP
RETURNS TIMESTAMP
ENTRY_POINT 'getExactTimestamp' MODULE_NAME 'fbudf';
2. in your database create a stored procedure called EXATIME
here is the metadata
DECLARE VARIABLE EXACTIME VARCHAR(24);
begin
/* Procedure Text */
for select getexacttimestamp() as exactime from rdb$database
into :exactimeinfo
do
suspend;
end
3. in your program you can write the sql of a query
here called myQuery like this :
select * from EXATIME ;
4. first run myQuery to get the datetime data :
myQuery.close;
if not myQuery.prepared then
myquery.Prepare;
myQuery.Open;
//write the time to some label to see if it worked
myLabel.Caption:=myQuery['exactimeinfo'];
//exactimeinfo = the return value from our
stored prodecure exatime above
now you can insert it into your table like this ,
where exactime is the varchar field with length 24 or
wider in myTable which shall hold the time info.
//sql code for your insertion statement :
insert into myTable (somefield1,somefield2,exactime) values
(:somefield1,:somefield2,:exactime)
//parameter assignment
parambyname('somefield1').asstring=mydata1;
parambyname('somefield2').asstring=mydata2;
parambyname('exactime').AsString:=myQuery['exactimeinfo'];
Tested with FB1.5.2 and Delphi 7
1. use ibexpert or similar to register the UDF GETEXACTTIMESTAMP
here is how the metadata should look like afterwards
/* External Function declarations */
DECLARE EXTERNAL FUNCTION GETEXACTTIMESTAMP
RETURNS TIMESTAMP
ENTRY_POINT 'getExactTimestamp' MODULE_NAME 'fbudf';
2. in your database create a stored procedure called EXATIME
here is the metadata
DECLARE VARIABLE EXACTIME VARCHAR(24);
begin
/* Procedure Text */
for select getexacttimestamp() as exactime from rdb$database
into :exactimeinfo
do
suspend;
end
3. in your program you can write the sql of a query
here called myQuery like this :
select * from EXATIME ;
4. first run myQuery to get the datetime data :
myQuery.close;
if not myQuery.prepared then
myquery.Prepare;
myQuery.Open;
//write the time to some label to see if it worked
myLabel.Caption:=myQuery['exactimeinfo'];
//exactimeinfo = the return value from our
stored prodecure exatime above
now you can insert it into your table like this ,
where exactime is the varchar field with length 24 or
wider in myTable which shall hold the time info.
//sql code for your insertion statement :
insert into myTable (somefield1,somefield2,exactime) values
(:somefield1,:somefield2,:exactime)
//parameter assignment
parambyname('somefield1').asstring=mydata1;
parambyname('somefield2').asstring=mydata2;
parambyname('exactime').AsString:=myQuery['exactimeinfo'];