Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 18th, 2006, 03:34 AM
SKING SKING is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Location: London
Posts: 4 SKING User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 30 m 30 sec
Reputation Power: 0
Question How to test for a date value in a Firebird stored procedure?

Hello All!

I'm trying to write a Firebird (1.5) stored procedure that checks a VARCHAR column for an entry that is a date (e.g. 01/01/2006). If a date isn't found, my procedure then runs an update to insert a date into the column (regardless of what the current non-date value is).

Does anybody have any ideas how to check for a date value? The VARCHAR column will contain various text entries, some of which will be dates in the format shown above. I was hoping for some magic function like 'IsDate' - but I've run into brick wall after brick wall.

I just don't know enough about Firebird stored procedures, and I'm not sure if I'm trying to achieve something that can't be done in a stored procedure. It's been a good learning exercise trying to do this - but I think that I am going to perhaps have to write a small Delphi utility to achieve the job.

Why didn't I write the Delphi utility in the first place? Because I want to know more about stored procedures!

Many thanks in advance,

SKING

Reply With Quote
  #2  
Old February 18th, 2006, 03:50 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,815 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 1 Day 14 m 37 sec
Reputation Power: 278
I would try to CAST it as a date and handle exceptions.

Reply With Quote
  #3  
Old February 18th, 2006, 07:54 AM
SKING SKING is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Location: London
Posts: 4 SKING User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 30 m 30 sec
Reputation Power: 0
Quote:
Originally Posted by pabloj
I would try to CAST it as a date and handle exceptions.



Hi Pabloj - thanks for the reply.

I tried something similar (using EXTRACT), and I have just tried using CAST as you suggested, but when I run the procedure it doesn't update any records, and it looks as though my exception handler is doing anything.

I thought 'when any do' should capture all exceptions. I assume that I'm using it wrong. Here's the test procedure...



CREATE PROCEDURE FIXDATASHORTDATES
AS
DECLARE VARIABLE PATNO INTEGER;
DECLARE VARIABLE ENC_DATE DATE;
DECLARE VARIABLE DATA_SHORT varchar(200);
DECLARE VARIABLE TEMP_DATE DATE;
begin
FOR
select patno, enc_date, data_short from enc_details
where data_rc = 'DateSeen'
and patno = 23
into atno, :enc_date, :data_short
do begin
temp_date = CAST (:data_short AS date);
when any do
begin
update enc_details set data_short = :enc_date
where patno = atno and enc_date = :enc_date;
end
end
end


When I try to debug the procedure (IBExpert) I get the following error:

Overflow occurred during data type conversion.
conversion error from string "29/04/2003"

I feel like I'm on the right track, but I'm dammed if I know what's going wrong!

Cheers,

SKING

Reply With Quote
  #4  
Old February 18th, 2006, 08:22 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,815 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 1 Day 14 m 37 sec
Reputation Power: 278
sql Code:
Original - sql Code
  1. CREATE PROCEDURE FIXDATASHORTDATES
  2. AS
  3. DECLARE VARIABLE PATNO INTEGER;
  4. DECLARE VARIABLE ENC_DATE DATE;
  5. DECLARE VARIABLE DATA_SHORT varchar(200);
  6. DECLARE VARIABLE TEMP_DATE DATE;
  7. BEGIN
  8. FOR
  9. SELECT patno, enc_date, data_short FROM enc_details
  10. WHERE data_rc = 'DateSeen'
  11. AND patno = 23
  12. INTO :patno, :enc_date, :data_short
  13. do BEGIN
  14. temp_date = CAST (:data_short AS DATE);
  15. WHEN any do
  16. BEGIN
  17. UPDATE enc_details SET data_short = :enc_date
  18. WHERE patno = :patno AND enc_date = :enc_date;
  19. END
  20. end
  21. END
Seems to work for me

Reply With Quote
  #5  
Old February 18th, 2006, 09:11 AM
SKING SKING is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Location: London
Posts: 4 SKING User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 30 m 30 sec
Reputation Power: 0
Quote:
Originally Posted by pabloj
sql Code:
Original - sql Code
  1. CREATE PROCEDURE FIXDATASHORTDATES
  2. AS
  3. DECLARE VARIABLE PATNO INTEGER;
  4. DECLARE VARIABLE ENC_DATE DATE;
  5. DECLARE VARIABLE DATA_SHORT varchar(200);
  6. DECLARE VARIABLE TEMP_DATE DATE;
  7. BEGIN
  8. FOR
  9. SELECT patno, enc_date, data_short FROM enc_details
  10. WHERE data_rc = 'DateSeen'
  11. AND patno = 23
  12. INTO :patno, :enc_date, :data_short
  13. do BEGIN
  14. temp_date = CAST (:data_short AS DATE);
  15. WHEN any do
  16. BEGIN
  17. UPDATE enc_details SET data_short = :enc_date
  18. WHERE patno = :patno AND enc_date = :enc_date;
  19. END
  20. end
  21. END
Seems to work for me




Seriously? Damn! I wonder what's going on my end??!

Could this have anything to do with SQL Dialects, do you think? The Firebird database that I'm running against is Dialect 1. I'm clutching at straws, here, but I just can't see why the debugger in IBExpert doesn't take me into the 'when any do' block. Running the procedure against my test data yields no results.

Another curious thing - I can't see why an error is being thrown when type coverting "29/04/2003" from a string to a date. Unless an American date format is being expected, of course (no '29th' month!).

Hmmm...(scratches head)...it seems this should work - I'm not going to rest easy until I find-out what the issue is!

Cheers, again for the input.

SKING

Reply With Quote
  #6  
Old February 18th, 2006, 01:44 PM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,815 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 1 Day 14 m 37 sec
Reputation Power: 278
Quote:
Originally Posted by SKING
... I can't see why an error is being thrown when type coverting "29/04/2003" from a string to a date. Unless an American date format is being expected, of course (no '29th' month!)...
This might be the problem.
What is the database charset?

Reply With Quote
  #7  
Old February 18th, 2006, 02:18 PM
SKING SKING is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Location: London
Posts: 4 SKING User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 30 m 30 sec
Reputation Power: 0
Quote:
Originally Posted by pabloj
This might be the problem.
What is the database charset?



I'm not sure. I checked the properties of the database within IBExpert. There are several properties listed, but nothing under 'Server', 'Role' and 'Charset' - just blank fields - no entries.

IBExpert is the only tool that I have used to work with Firebird. Is there anything that can be done from the command line to directly interrogate the database and determine this information?

Thanks again,

SKING

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > How to test for a date value in a Firebird stored procedure?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway