For those of you that don’t know, way back in v12.5, Sybase added the static global variables @@version_number and @@version_as_integer. The purpose was to make it easier for programmers to write code that incorporate the new features of ASE 12.5 while still being able to support the older v12.0 servers.
How is this done? In ASE 12.0 and earlier, we were forced to determine the version of the Sybase ASE DBMS server by parsing the output of @@version. During the v11.5 through v12.0 years, the format of the @@version static variable changed. The location of certain fields within the string kept being moved around. IIRC, it was about the time that v188.8.131.52 came out that the format was set in stone.
OLD way of determining the version of the ASE server for use in your application:
my $version_str = dbS::Sybase::Queries::selectrow_array($dbh, 'select @@version'); my @version = split ///, $version_str; print "ASE version: $version\\n";
OUTPUT:ASE version: 15.0.2
In this case, we are assuming that the second field in @@version is the part that contains “15.0.2” but there is absolutely no guarantee. Granted, we could be a bit more proactive with our parsing and determine that a field with one or more digits followed by a period and more digits (there can be more than one of these sets of \\d+\\.\\d+). It can be confusing for those people not used to using regular expressions (regex’s). Why complicate things just for a version string?
my $version = dbS::Sybase::Queries::selectrow_array($dbh, 'select @@version_number'); print "ASE version: $version\\n";
OUTPUT:ASE version: 15020
Here we ask for the version as a number, and we receive it. It is easier to work with the number ‘15020’ than the string ‘15.0.2’ to determine if a code chunk requires a minimum of 184.108.40.206 (12504).
What if you’re only looking for the major version number? Basically, if the ASE version is 11x, 12x, or 15x. Easily done:
my $version = dbS::Sybase::Queries::selectrow_array($dbh, 'select @@version_as_integer'); print "ASE version: $version\\n";
OUTPUT:ASE version: 15000
That’s it 🙂