Alpha Video Training
Results 1 to 8 of 8

Thread: Programming Puzzle 18 - Import Madness #2

  1. #1
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default Programming Puzzle 18 - Import Madness #2

    Puzzle 18

    [ Thanks again to Andy Schone, for coming up with this one. ]

    Your manager interrupted your coffee & danish this morning to complain
    that your CSV import script has stopped working. She is sure nothing
    has changed, and implies that your script is somehow responsible for
    a total breakdown in civil order in the western hemisphere!

    On her way out of your cubicle she gives you the attached CSV file
    and says "Make it work".

    Quick inspection of the CSV indicates that the unnamed source for the
    data file has in fact changed the structure of each row. Each row now
    include middle names, sometimes.

    Your task grasshopper is this:

    1) Modify your script ( puzzle 17 ) so that it adds a Middle_name field
    to your DBF if it does not already exist.

    2) Modify your script so that the data from the new CSV is successfully
    "imported" into your table. Careful. some records contain a middle
    name, while others do not.

    3) Make sure you "import" 100% of the available data in each row of the CSV,
    placing each element into its correct field in your table.

    4) As before prefix the name of your script with your initials, and attach
    the exported version of your script here for our edification.

    Hint: If the middle name is part of the record it is always the 2nd
    field of the record.
    Last edited by Tom Cone Jr; 07-20-2011 at 11:49 AM.

  2. #2
    "Certified" Alphaholic Mike Wilson's Avatar
    Real Name
    mike wilson
    Join Date
    Apr 2005
    Location
    Grand Rapids, Michigan
    Posts
    4,198

    Default Re: Programming Puzzle 18 - Import Madness #2

    Here is my attempt. I imported the whole broken cvs file to a temp table, processed the records from the temp table and deleted the temp table. Pretty quick (~.36 sec) for these few records but may not be useful for thousands of records.
    Attached Files Attached Files
    Last edited by Mike Wilson; 07-20-2011 at 04:07 PM.
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

  3. #3
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default Re: Programming Puzzle 18 - Import Madness #2

    Mike,

    That's an interesting approach. Presumably you let Alpha write some of the code for you by defining an import operation, and then capturing the xbasic code? Very clever, grasshopper!

    Prof. Pickpicky has assigned 3 demerits however, for not commenting your code sufficiently. His standard is easy legibiliity six (6) months from now. Take heart, though, he's been persuaded to reconsider such judgments, if the code is resubmitted for his further consideration.

    Thanks for participating!

    -- tom

  4. #4
    "Certified" Alphaholic Mike Wilson's Avatar
    Real Name
    mike wilson
    Join Date
    Apr 2005
    Location
    Grand Rapids, Michigan
    Posts
    4,198

    Default Re: Programming Puzzle 18 - Import Madness #2

    OK, here is the newly commented script, Professor. Yes, I let Genie generate the import operation, converted it to xbasic and I used what I needed. Heck, I'm a two finger typist, why waste the time when Genie will do it for you?!
    Attached Files Attached Files
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

  5. #5
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default Re: Programming Puzzle 18 - Import Madness #2

    Thanks, Mike.

    I thought it worthwhile to mention using the xbasic which the operations genie builds in case newcomers didn't know about this handy little trick.

  6. #6
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,047

    Default Re: Programming Puzzle 18 - Import Madness #2

    Major Functions used: in addition to ones used in the first import madness

    w_count()
    is_one_of()
    a5.table_enum()
    table.external_field_name_get()
    a5_add_fields_to_table()
    for each ... next
    Attached Files Attached Files

  7. #7
    "Certified" Alphaholic Mike Wilson's Avatar
    Real Name
    mike wilson
    Join Date
    Apr 2005
    Location
    Grand Rapids, Michigan
    Posts
    4,198

    Default Re: Programming Puzzle 18 - Import Madness #2

    Nice work, Andy. I'd say that maybe the most important function you use you didn't list.... populate_from_string(). I don't use that, but now I think I might.
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

  8. #8
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,047

    Default Re: Programming Puzzle 18 - Import Madness #2

    I listed populate_from_string() in import madness #1. The functions listed here are the ones that I used in addition to the previous listing.

Similar Threads

  1. Programming Puzzle 3 - Fractions, anyone?
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 7
    Last Post: 11-08-2011, 06:40 AM
  2. Programming Puzzle 11 - More Loops
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 11
    Last Post: 08-20-2011, 05:50 PM
  3. Programming Puzzle 17 - Import Madness #1
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 7
    Last Post: 08-17-2011, 09:49 PM
  4. Programming Puzzle 16 - Perfect Numbers ?
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 4
    Last Post: 08-15-2011, 12:40 PM
  5. Programming Puzzle 5 - Nested loops
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 10
    Last Post: 08-08-2011, 03:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •