ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion 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 10th, 2005, 12:30 AM
premzero premzero is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Sydney, AU
Posts: 36 premzero User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 24 m 58 sec
Reputation Power: 5
Need to optimize my code!

Here is how my code goes.

- query calling table A from DB1
- query calling table B from DB2

Note:
1. both tables are structurally identical but from different datasources - DB1 (CSV) and DB2 (postgres)
2. table A contains new data; table B contains existing data.

Requirements:
1. If row in table A doesn't exist in B, then insert into B.
2. If row in table B doesn't exist in A, then delete from B.
3. For matching rows, check if any changes in data.
If no change, leave it alone. If changed, then update table B with values from table A.

My long-winded method:
- Loop old table B. Delete that row if not found in new table A. Loop to next record and continue process.
- Loop new table A. Select if row found in B. If not found insert. If found, update row with new values from B. Loop to next record and continue process.

Hope it makes sense. The page has alot of loops and queries.
Would appreciate a shorter algorithm - shorter code or maybe a different comparison method.. any ideas?

Thanks,
Prem
__________________
We can help export your products http://www.GIAgroup.com/

Reply With Quote
  #2  
Old August 10th, 2005, 08:04 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,648 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 12 h 8 m 8 sec
Reputation Power: 53
Looping over the data is probably the only way. You could try using query of queries as well but this might be more complex than just looping.

The best advise would really be to scrap this entire system and build one that meets your needs effectively, becuase the current setup is woefully ineffecient.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old August 10th, 2005, 06:12 PM
premzero premzero is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Sydney, AU
Posts: 36 premzero User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 24 m 58 sec
Reputation Power: 5
Kiteless, I understand what you mean. However, since the client has a different internal system (FileMaker), that's how they export their data to us so we can add it into their web DB (postgres). I know - why not just use postgres. I guess they've got many internal systems connected to/and built with FileMaker, so that's another issue. Guess I'll stick to this for now.

Reply With Quote
  #4  
Old August 10th, 2005, 06:33 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,648 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 12 h 8 m 8 sec
Reputation Power: 53
Yes, the only alternative that I can see is looping over the data and manually pulling out what you want.

Reply With Quote
  #5  
Old August 10th, 2005, 06:39 PM
premzero premzero is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Sydney, AU
Posts: 36 premzero User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 24 m 58 sec
Reputation Power: 5
On a positive note, it's good this is done only when we get new data. Typically accessing the page maybe once a week and just 1 HTTP request. Even with a few 1,000s of records, it shouldn't be too slow.

Reply With Quote
  #6  
Old August 10th, 2005, 08:05 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,648 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 12 h 8 m 8 sec
Reputation Power: 53
I should ask if you've tried using query of queries to solve the problem?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Need to optimize my code!


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