"construct" sintax differs between 4 and 7 version
Posted in 2000
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
Hello! I would like to know if there is any parameter to configure how the construct returns the where text when you use a date field. Informix 4 uses " Informix 7 uses ´ ... where date_field >= "01/01/1999" I call some 4gl programs from another 4gl programs including several parameters. One of them is the "where" clause. Every parameter is separated with double quotes. I use the following shell script to execute but I have the problem with the single quotes with date fields. while [ $# -gt 0 ] do #llamada="$llamada \\"$1\\"" llamada="$llamada '$1'" #echo $llamada ; read a shift done # Generar instrucción de llamada llamada="exec $INFORMIXDIR/bin/fglgo $camino $llamada" # Ejecutar eval $llamada Solutions: make a function that change the ´ character by " on the where text. Any other? thanks in advance -- Evelio Martínez Tel: +34 96 337-95-80 Fax: +34 96 337-81-18
Evelio Martínez wrote: > I would like to know if there is any parameter to configure how the > construct returns the where text when you use a date field. > > Informix 4 uses " > Informix 7 uses ´ > > ... where date_field >= "01/01/1999" This change was necessary to prevent innocent programs from being screwed up by diabolical users (eg me) who might be tempted to set DELIMIDENT in the environment just to see how badly things get broken. Basically, ANSI SQL requires the single quotes around character strings; Informix allows you to use double quotes instead, except when DELIMIDENT is set (whereupon double quotes mark a delimited identifier and not a string). Try looking in the manual; there may (still?) be an environment variable that allows you to revert to the old double quote notation. > I call some 4gl programs from another 4gl programs including several > parameters. One of them is the "where" clause. Every parameter is > separated with double quotes. > > I use the following shell script to execute but I have the problem with > the single quotes with date fields. > > while [ $# -gt 0 ] > do > #llamada="$llamada \\"$1\\"" > llamada="$llamada '$1'" > #echo $llamada ; read a > shift > done > > # Generar instrucción de llamada > llamada="exec $INFORMIXDIR/bin/fglgo $camino $llamada" > > # Ejecutar > eval $llamada > > Solutions: > make a function that change the ´ character by " on the where text. That's certainly an option. Watch out for the quoting conventions for embedded single quotes ('there''s a single quote in here') and embedded double quotes ('this double quote (") is a problem too'). > Any other? Several...I tend to use a program of mine called escape which carefully wraps up its arguments so it won't be misinterpreted by the shell. Basically, if there's a special character (eg a space or a quote or a backslash) in the argument, it embeds the whole argument in single quotes, and replaces any embedded single quotes with the 4-character sequence '\\''. However, it may not be safe to use unless you know how and why it works; you have to know how many times the argument list will be processed for argument expansion. Trial and error usually ends up with the right answer! I'll post the code if there's interest. The resulting code is either: while [ $# -gt 0 ] do llamada="$llamada $(escape '$1')" #echo $llamada ; read a shift done Or, more succinctly: $llamada=$(escape "$@") I'm assuming you're using a POSIX.2 shell (Korn, Born Again, ...) shell which supports $(...) as well as backticks `...` for command execution. You'd the first version if you want to hack some of the arguments specially. Note that the original code could always be broken by some unkind soul (eg me) querying for a single quote in a character field; worse things could happen if I went searching for: '`rm -f * /*`' The first single quote quietly terminates your original string, exposing the backticks to the shell, and letting me execute an arbitrarily nasty command. The second single quote then puts the string back together so you wouldn't really realize what had happened until much later when nothing worked any more. -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v1.00.PC1 -- see http://www.perl.com/CPAN #include <disclaimer.h>