SunQuest
           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:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old October 8th, 2003, 11:01 AM
glaverick glaverick is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: NC
Posts: 4 glaverick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Creating autoinc trigger in Firebird

I am a newcomer to Firebird and need a little help. I have been using IBOConsole with Firebird 1.5 and have successfully created a databse and tables. However, in one of the tables I wanted to set an autoincrement id field. Using IBOConsole, I set the following parameters in the New Trigger wizard:

Before Insert
Position 0
Active

I then used the following code:

BEGIN
IF ( ( NEW.MemberID IS NULL) OR NEW.MemberID <= 0) ) THEN
NEW.MemberID = GEN_ID(gen_MemberID,1);
END

MemberID is an integer column in my table and I had previously created the generator gen_MemberID.

When I click on the compile button, I get a message 'UNKNOWN COLUMN: NEW.MEMBERID'.

Do any of you more experienced Firebird users have any idea why?

Reply With Quote
  #2  
Old October 8th, 2003, 11:30 AM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,173 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 24
The problem with your trigger isn't obvious to me. It is almost identical to the trigger in this tutorial:

http://www.fingerbird.de/generatorg..._AutoInc_fields

I'm assuming that your missing "(" after the "OR" is a typo. Otherwise if MemberID is a column in the table the trigger is being attached to, then I don't understand why you're getting that particular error message.

Reply With Quote
  #3  
Old October 8th, 2003, 04:10 PM
glaverick glaverick is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: NC
Posts: 4 glaverick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You're right! The missing "(" was a typo in the post.

Reply With Quote
  #4  
Old October 13th, 2003, 07:10 PM
glaverick glaverick is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: NC
Posts: 4 glaverick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question

I discovered that if I recreated the database specifying SQL dialect 1, the problem doesn't exist (the original db was dialect 3). Can anyone explain this or point me to a complete explanation of the differences between the two dialects?

Reply With Quote
  #5  
Old October 14th, 2003, 07:52 AM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,173 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 24

Reply With Quote
  #6  
Old October 16th, 2003, 11:58 AM
glaverick glaverick is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: NC
Posts: 4 glaverick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

For all of you that may encounter a similar problem, it appears to be related to my use of IBOConsole to create my tables. Apparently, IBOConsole wraps the field names in double quotes by default if using SQL Dialect 3. To refer to the fields later, they must again be wrapped in double quotes. If my code had been:

BEGIN
IF ( ( NEW."MemberID" IS NULL) OR (NEW."MemberID" <= 0) ) THEN
NEW."MemberID" = GEN_ID(gen_MemberID,1);
END

everything would have worked correctly.

Thanks dcaillouet for your help!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Creating autoinc trigger in Firebird


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 1 hosted by Hostway