943,733 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 468
  • C++ RSS
Jun 12th, 2009
0

Best Approach To solve this..

Expand Post »
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?
Similar Threads
Featured Poster
Reputation Points: 431
Solved Threads: 116
Practically a Master Poster
Agni is offline Offline
654 posts
since Dec 2007
Jun 12th, 2009
1

Re: Best Approach To solve this..

Are you sure that your method is not efficient?
Why?..
What's your efficiency criterion?
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Jun 13th, 2009
0

Re: Best Approach To solve this..

Click to Expand / Collapse  Quote originally posted by ArkM ...
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.
Featured Poster
Reputation Points: 431
Solved Threads: 116
Practically a Master Poster
Agni is offline Offline
654 posts
since Dec 2007
Jun 13th, 2009
0

Re: Best Approach To solve this..

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.
Reputation Points: 1486
Solved Threads: 140
Practically a Posting Shark
siddhant3s is offline Offline
816 posts
since Oct 2007
Jun 13th, 2009
0

Re: Best Approach To solve this..

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
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Static libary has undefined references
Next Thread in C++ Forum Timeline: Find first NULL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC