> Isn't irrelevant what Perl thinks of a variable's type when DB already knows/was told what the type of that column should be at create time? some testing on MariaDB
CREATE TABLE `t_test_type` ( `f_num` INT(11) NULL DEFAULT NULL, `f_str` CHAR(50) NULL DEFAULT NULL ) ENGINE=MyISAM ;
Ron

It looks like you could get what you want from the ansi information_schema and a query like the one below that worked for me under MySQL. I have read that not all DBMS support information_schema.

> SELECT column_name, data_type FROM information_schema.columns WHERE table_name = 't_test_type' AND column_name IN ('f_num', 'f_str') +; +-------------+-----------+ | column_name | data_type | +-------------+-----------+ | f_num | int | | f_str | char | +-------------+-----------+ 2 rows in set (0.00 sec)

DBI has a column_info method that seems to guarantee DATA_TYPE code and TYPE_NAME fields, if implemented by the driver which should be true for MariaDB based (only) on looking at the source.

#!/usr/bin/env perl use warnings; use strict; use DBI; my $dsn = "DBI:mysql:database=mysql"; my $dbh = DBI->connect($dsn, ... , #user name and password { RaiseError => 1 } ) or die $DBI::errstr; my $info = $dbh->column_info( undef, 'mysql', 't_test_type', '%' )->fetchall_hashref('COLUMN_NAME'); while (my ($col, $col_info) = each %$info) { print "$col $col_info->{ DATA_TYPE } $col_info->{ TYPE_NAME }\n"; }
Output:
f_str 1 CHAR f_num 4 INT
Ron

In reply to Re^5: Distiguishing arguments: number-strings vs real integer by mr_ron
in thread Distiguishing arguments: number-strings vs real integer by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.