You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Rick Wayne <fe...@facstaff.wisc.edu> on 2001/02/13 00:27:00 UTC

difficulty w/URI parameters in an ESQL-using document

hi all,

i have a problem with esql and URI parameters.  i'm trying to do a pretty
simple data download, where a user picks weather params (e.g., max air
temp)
from a form, which then calls an XML doc with esql in it.  the URI looks 
something like: 
  
  ...getData.xml?data_table=t_411&data_field=theDate&data_field=DMxTAir...

my problem is that i can't seem to get any of the params passed in the URI
to esql.  i tried using <xsp:logic> and request.getParameter() to build up
an sql query string, but when i passed it into my esql doc, i get bupkis
back.  likewise if i try with <request:get-parameter>.

i should note that i also pass the query string out so that the stylesheet
can print it; it looks fine.  if i take the same string and wire it into 
the XML source for the query, it works fine.  but if i build a StringBuffer
called query in code, then embed it in the esql stuff...nada.

likewise if i try with <request:get-parameter>.

looked in the FAQ and as much of the list archives as i could stand to wade
through...if this is the Popular Newbie Question Of The Week, you have my
apologies. cocoon 1.8.2, jakarta-tomcat standalone 3.2.1.

here's an example; thanks for any help!

<?xml version="1.0"?>
<?cocoon-process type="xsp"?>
<?xml-stylesheet type="text/xsl" href="dataOutput.xsl"?>

<!-- Change log

$Log: getData.xml,v $
Revision 1.1  2001/02/01 23:38:38  wayne
Initial revision

 -->
<xsp:page
  xmlns:xsp="http://www.apache.org/1999/XSP/Core"
  xmlns:esql="http://apache.org/cocoon/SQL/v2"
  xmlns:request="http://www.apache.org/1999/XSP/Request"
>

  <page>
  <xsp:logic>
    String dataFields[] = request.getParameterValues("data_field");
    String tableName = request.getParameter("table_name");
    StringBuffer queryDataFields = new StringBuffer("no_fields_available");
    if (tableName == null) tableName = "t_412";
    queryDataFields = new StringBuffer(dataFields[0]);
    for (int ii=1; ii &lt; dataFields.length; ii++) {
      queryDataFields.append(",");
      queryDataFields.append(dataFields[ii]);
    }
    StringBuffer query = new StringBuffer("select ");
    query.append(queryDataFields.toString());
    query.append(" from ");
    query.append(tableName);
    <!-- DEBUG ONLY -->
    query.append(" where stnid=4713 and theDate='1986-07-15';");
    <query>
        <!-- <xsp:expr>query</xsp:expr> -->
        select theDate,DMnBatt,DMxTAir from <request:get-parameter
name="table_name"/> where stnid=4713 and theDate='1986-07-15';
    </query>
    <columnNameList><xsp:expr>dataFields</xsp:expr></columnNameList>

    <esql:connection>
      <!-- insert real database stuff in here -->
      <esql:driver>   blah   </esql:driver>
      <esql:dburl>    foo    </esql:dburl>
      <esql:username> woof   </esql:username>
      <esql:password> eef    </esql:password>

      <esql:execute-query>
        <esql:query>
	  <!-- this does not work -->
          <xsp:expr>query</xsp:expr>
	  <!-- Nor this, neither -->
          <!-- select theDate,DMnBatt,DMxTAir from
<esql:parameter><request:get-parameter name="table_name"/></esql:parameter>
where stnid=4713 and theDate='1986-07-15'; -->
	  <!-- But this works fine -->
          <!-- select theDate,DMnBatt,DMxTAir from t_411 where stnid=4713
and theDate='1986-07-15'; -->
        </esql:query>
        <esql:results>
          <data-lines>
            <esql:row-results>
              <data-line>
              <esql:get-columns/>
              <!-- <request:get-parameter name="table_name"/> -->
              </data-line>
            </esql:row-results>
          </data-lines>
        </esql:results>
      </esql:execute-query>
    </esql:connection>
  </xsp:logic>
  </page>
</xsp:page>
-- 
rw

"And down under all those piles of stuff, the secret was written: 
We build our computers the way we build our cities -- 
over time, without a plan, on top of ruins."

Ellen Ullman, The Dumbing-down Of Programming, Salon Magazine

Re: difficulty w/URI parameters in an ESQL-using document

Posted by Donald Ball <ba...@webslingerZ.com>.
On Mon, 12 Feb 2001, Rick Wayne wrote:

> hi all,
>
> i have a problem with esql and URI parameters.  i'm trying to do a pretty
> simple data download, where a user picks weather params (e.g., max air
> temp)
> from a form, which then calls an XML doc with esql in it.  the URI looks
> something like:
>
>   ...getData.xml?data_table=t_411&data_field=theDate&data_field=DMxTAir...
>
> my problem is that i can't seem to get any of the params passed in the URI
> to esql.  i tried using <xsp:logic> and request.getParameter() to build up
> an sql query string, but when i passed it into my esql doc, i get bupkis
> back.  likewise if i try with <request:get-parameter>.
>
> i should note that i also pass the query string out so that the stylesheet
> can print it; it looks fine.  if i take the same string and wire it into
> the XML source for the query, it works fine.  but if i build a StringBuffer
> called query in code, then embed it in the esql stuff...nada.

but if you do this:

<esql:query><xsp:expr>query.toString()</xsp:expr></esql:query>

i bet you'll find success. i personally generally recommend that you build
the query using esql:parameter's, but i don't think that you can
substitute the table name as a variable in a prepared statement.

- donald