Re: dynamic database name
Posted in 1998
Thai Nguyen wrote: > Is there any way to prepare an dynamic SQL for database names so > that I can declare, open and fetch a cursor passing to database > name as USING my_variables. I am using ESQL for my program that > required to read through all available databases for a certain > query. For example: > > "select some columns from %s:mytable" > > where %s is dynamic datatabse name. > > So that, I am able to "open mycur cursor using mydbname", for example. You can use a question mark in some places to indicate a placeholder for a value in a statement: "SELECT Some, Columns FROM SomeTable WHERE Key = ?" However, there are many places where you cannot use the placeholder notation, and that includes any part of a statement which references a table name. Given that you're using ESQL/C, you can arrange to sprintf the statement before using prepare, declare, open, ... It isn't too bad until you start realizing that for your one table query, you have to do 1 database name substitution, but for a two-table query, you have to do 2 substitutions, etc. I have some ghastly queries which have to do 17 database name substitutions! -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v0.60 -- see http://www.perl.com/CPAN #include <disclaimer.h>