Re: ESQL/C problem
Posted in 1998
On Mon, 14 Sep 1998 icc@injersey.com wrote: > nguyenv@Cognos.COM (Vinhson) wrote: > > I want to determine the version number of my ESQL/C product > > within an ESQL/C program. Currently, I'm using ESQL/C 7.2x. > > > > Does anyone know how I could do that? > > Here's a quick and dirty under UNIX, assuming the esql -V gives you the info > you need. I might be wrong about esql -V, so somone can correct me or Vinhson > can just figure it out. Also this code segement was written on-the-fly, not > compiled or unit tested, i.e., its the idea I want to convey. > > #include <stdio.h> > > int > get_esql_vers(char *ver) > { > FILE *pipe; > > if ((pipe = popen("esql -V", "r")) == NULL) > return 0; > > fgets(ver, 25, pipe); > pclose(pipe); > > return 1; > } More or less OK -- the idea is certainly right, and the option to the esql command is correct. The version string should be at least 34 characters long to allow for the full text (which typically has two trailing blanks), the newline and the terminal null. Beware that the esql program may generate a message about broken pipe if you do this (it does for me on Solaris 2.6). Since the output from esql -V is only two lines, the easiest fix is to read both lines, though that implies some local buffer space. I think the size of the version string should be passed into the code and used in place of the magic 25: int get_esql_vers(char *ver, size_t len) { } This is a run-time check. It won't work if the machine has no ESQL/C compiler installed. It will give the wrong answer if you have a 6.00 ESQL/C binary running against a 7.24 INFORMIXDIR. The best way to avoid this is to compile the ESQL/C version string into the executable; this is what I do with DBD::Informix and current versions of SQLCMD. There is no documented way to get hold of the ESQL/C version number from the ESQL/C header files; the version numbers in those files are for other purposes. There also is no documented global variable which contains the version string. The closest approach is _esqvers or _sqvers, but they do not contain the final few letters (the C1 of 7.24.UC1, or C1X1 of 7.24.UC1X1). Yours, Jonathan Leffler (jleffler@informix.com) #include <witticism.h> Guardian of DBD::Informix v0.60 -- http://www.perl.com/CPAN Informix IDN for D4GL & Linux -- http://www.informix.com/idn