1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Rep Power

    Question Over my head with Python and MySQL

    The project:

    Make a db of a fictitious bank with its clients and accounts.

    The problem:

    Taking the cleaned data (all in one text file) and putting it into the db using python. The hard part isn't inserting directly into the db, but some parts of the client table that i need to populate require keys from other tables... not sure how to go about getting that (ie taking column 6 of the text file and using it to find the referential key in the street table, then submitting the key in place of the streets name).

    If someone could help, would be a great relief.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Rep Power
    I've never used Python w/ MySQL before, but I have used Python to load an Oracle database (using cx_Oracle). The process was pretty simple-- if you've got a text file that contains values that correspond to keys from other tables, just write the code that does a select to retrieve the values from the table befre you do your insert. Python was quick enough to populate the oracle database with tens of thousands of records (one table had 19,000 records alone) in a reasonable amount of time (15 minutes IIRC?).

    If you don't want to do the data lookups individually, you can just do a select * from the table(s) that have the data you'll be using, put that data into a dictionary, and then do lookups on the dictionary as you need to (mydict[key_from_text_file]).
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Hull, UK
    Rep Power
    I read this earlier but i couldn't deside if this was homework or not? Anyway if you're new to MySQL and Python i'd start by reading http://www.devshed.com/Server_Side/P...SQL/page1.html

    Also if you could attach a sample of the file your wanting to insert into MySQL that could be very helpful. Obviously the file's gonna have to go under the knife before we can do this.

    programming language development: www.netytan.com Hula

  6. #4
  7. Wacky hack
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    London, England
    Rep Power
    Also have a read of the MySQL docs at http://www.mysql.com/doc to work out how you will do this in terms of MySQL queries, and use the MySQL board in this forum to discuss that aspect of the problem.

IMN logo majestic logo threadwatch logo seochat tools logo