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. Advertising

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. dpackwood
    Replies:
    3
    Views:
    1,784
  2. Savas Ates

    getting info from temp table

    Savas Ates, Sep 10, 2004, in forum: ASP General
    Replies:
    3
    Views:
    151
    Tibor Karaszi
    Sep 10, 2004
  3. julian
    Replies:
    8
    Views:
    446
    Avatar
    Apr 6, 2006
  4. J M
    Replies:
    2
    Views:
    108
    Tad McClellan
    Nov 6, 2004
  5. Sam
    Replies:
    4
    Views:
    71
    Mark Lawrence
    Jan 17, 2014
Loading...

Share This Page