aalneyperl has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, As we all know MySQL has evolved over years, from 3.x to 5.1.I want to execute statments depending on the version which is running on the server. Can you show me how can we do this. Like
3.x Show variables; 4.x Show variables; 5.0 Show global variables 5.1+ Select * from information_schema.global_variables order by 1; sub var { my $sgv = $dbh->prepare("show variables"); $sgv->execute(); while (my ($keyword, $value) = $sgv->fetchrow_array()) { $variables{$keyword} = $value; } $sgv->finish(); }

Replies are listed 'Best First'.
Re: Execute statement based on version.
by Corion (Patriarch) on Dec 27, 2007 at 09:36 UTC

    I would send different statements to MySQL, based on the MySQL version.

    my ($major,$minor) = get_my_sql_version(); my $statement; if ($major < 5) { $statement = 'show variables'; } elsif ("$major.$minor" eq "5.0") { $statement = 'show global variables'; } elsif ("$major.$minor" gt "5.0") { $statement = 'Select * from information_schema.global_variables or +der by 1'; }; $dbh->execute($statement); ...

    The implementation of get_my_sql_version() is left as an exercise to the reader. As literature, I recommend get mysql version.

Re: Execute statement based on version.
by Burak (Chaplain) on Dec 27, 2007 at 09:38 UTC
    You can do a "select version()" to get the server version.
Re: Execute statement based on version.
by suaveant (Parson) on Dec 27, 2007 at 15:53 UTC
    There is also a way to make version sensitive queries to MySQL...

    go here, bottom of the page.

                    - Ant
                    - Some of my best work - (1 2 3)