Best Approach To solve this..

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2007
Posts: 445
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 69
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Best Approach To solve this..

 
0
  #1
Jun 12th, 2009
hey guys,

I have a fixed length .txt file. Values in the file correspond to columns in a db table.
ex file row is something like:

India 3455 78787 89898

table has columns something like:

column_name length startPosn EndPosn
country 6 1 6
ID 6 7 13

so you see that the spaces are actually part of the values, its not delimited.

what i have to do it insert each value and create 1 row in the db(assuming there's only 1 row in the txt file right now).

Problem is that I will want to give the user some flexibility that he can change column lengths in future. As a result i was thinking of create a .dat file with 'column_name,length,start-posn' mentioned in it for each column. Then i would read this .dat file first. accordingly get the startPosn-length for each column and get the substrings from the original .txt file(which i would have read in a string) and create an insert query.

Just wondering if anyone can suggest a more efficient way to do this or any issues I can get in this approach?
thanks
-chandra
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Best Approach To solve this..

 
1
  #2
Jun 12th, 2009
Are you sure that your method is not efficient?
Why?..
What's your efficiency criterion?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 445
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 69
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Re: Best Approach To solve this..

 
0
  #3
Jun 13th, 2009
Originally Posted by ArkM View Post
Are you sure that your method is not efficient?
Why?..
What's your efficiency criterion?
well no I'm not sure it is inefficient, actually i don't really know how to calculate efficiency and that's the whole reason I had to post it here. Someone who knows how to do that would tell me if its efficient or not. Or someone who's probably done something like this before could tell me if there are any issues I can face later.
thanks
-chandra
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 793
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: Best Approach To solve this..

 
0
  #4
Jun 13th, 2009
Depending on your platform, you can time your application for a given set of data.
Or you can use a profiler . But whatever you do, please don't optimize your code without analyzing its performance.
Optimize only and only when you really need it.
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: Best Approach To solve this..

 
0
  #5
Jun 13th, 2009
First write it in the way where you think of that it is the most efficient one, then you post your code here, and after you've posted your code, we can analyze it and make suggestions to increase performance
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC