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

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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 August 13th, 2012, 11:21 AM
frozenade frozenade is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 3 frozenade User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 56 sec
Reputation Power: 0
Unhappy Firebird Trigger: Modify Value & Insert Record Problem

Hi all experts...

I am currently new in Firebird especially in trigger. Usually I done this in script manually, but I am really fascinating to create it with trigger.

Please let me explain my tables first.

Code:
  • STOCK CODE NAME TOTAL GOOD BROKEN SERVICE
  • DETAIL ID STOCK_CODE SERIAL
  • BROKEN DETAIL_ID MARK
  • SERVICE DETAIL_ID START_DATE END_DATE COST
  • LOGS DETAIL_ID MARK START_DATE END_DATE COST


And now my problems:
1. How to modify STOCK.GOOD and STOCK.BROKEN value before insert a new record into BROKEN? That will be: STOCK.GOOD-1, STOCK.BROKEN+1.
2. How to insert all record from BROKEN and SERVICE into LOGS before current record in SERVICE is deleted?

I hope my questions could be accepted.

Thank you very much in advance.

Regards,
Abdi

Reply With Quote
  #2  
Old August 13th, 2012, 12:04 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
I have some serious reservations about your schema.
Assuming that will not be changed, it looks as if you just need an after insert trigger on
the BROKEN table that updates the STOCK table as required.

Somewhere, of course, you will have to take care of all the possible logic error situations
e.g. GOOD turning negative.
However, the integrity of the math inside the trigger will be guaranteed by the transaction within which it runs.

Clive

Reply With Quote
  #3  
Old August 13th, 2012, 08:45 PM
frozenade frozenade is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 3 frozenade User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 56 sec
Reputation Power: 0
Yes, I mean after insert. My mistake I'm sorry

I've try to consider all logic error situations as possible I can.
I mean like this, the user cannot mark a stock detail as broken, before she/he insert a record detail from table stock. So, if there's no record in DETAIL, access to insert record in BROKEN (in app) is disabled, and GOOD will not turning negative.

Regards,
Abdi

Reply With Quote
  #4  
Old August 14th, 2012, 02:29 AM
frozenade frozenade is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 3 frozenade User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 56 sec
Reputation Power: 0
Never mind, I figured it out.

Thanks.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Firebird Trigger: Update Value & Insert Value Problem

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap