Getting MySQL table info in perl script

Discussion in 'Perl Misc' started by Occidental, Nov 3, 2007.

  1. Occidental

    Occidental Guest

    ...ie the column name, definitions (varchar(100) etc). The most
    obvious way is to parse the output from describe table_name. Is there
    an easier way? My goal is to create a generic INSERT sub, which takes
    as args table_name and a hash reference, eg:

    $table_name = "TheTable";
    $hash(Int1) = 99;
    $hash(Float2) = 1.54;
    $hash(String7) = "Goodbye cruel world";

    ...where Float2, Int1, String7 are some but not all cols in mysql table
    TheTable. The sub is invoked as follows:

    DoInsert($table_name, \%hash);

    DoInsert will generate and execute the INSERT statement, NULLing out
    fields not in %hash, single quoting string fields, etc., maybe even
    doing data tyep compatibility tests. I would be happy to learn that
    some one has beaten me to it, and a procedure like DoInsert already
    exists.
     
    Occidental, Nov 3, 2007
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wet Basement
    Replies:
    1
    Views:
    2,795
    BobMonk
    Jul 15, 2003
  2. dpackwood
    Replies:
    3
    Views:
    2,150
  3. julian
    Replies:
    8
    Views:
    699
    Avatar
    Apr 6, 2006
  4. pj
    Replies:
    3
    Views:
    446
  5. J M
    Replies:
    2
    Views:
    199
    Tad McClellan
    Nov 6, 2004
  6. Petterson Mikael

    Execute another perl script from my perl script

    Petterson Mikael, Jan 5, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    275
    Paul Lalli
    Jan 5, 2005
  7. Replies:
    20
    Views:
    1,294
    Gunnar Hjalmarsson
    Jan 18, 2005
  8. Sam
    Replies:
    4
    Views:
    183
    Mark Lawrence
    Jan 17, 2014
Loading...