views:

231

answers:

3

How do you fix a names mismatch problem, if the client-side names are keywords or reserved words in the server-side language you are using?

The DOJO JavaScript toolkit has a QueryReadStore class that you can subclass to submit REST patterned queries to the server. I'm using this in conjunction w/ the FilteringSelect Dijit.

I can subclass the QueryReadStore and specify the parameters and arguments getting passed to the server. But somewhere along the way, a "start" and "count" parameter are being passed from the client to the server. I went into the API and discovered that the QueryReadStore.js is sending those parameter names.

I'm using Fiddler to confirm what's actually being sent and brought back. The server response is telling me I have a parameter names mismatch, because of the "start" and "count" parameters. The problem is, I can't use "start" and "count" in PL/SQL.

Workaround or correct implementation advice would be appreciated...thx.

//I tried putting the code snippet in here, but since it's largely HTML, that didn't work so well.

+1  A: 

While it feels like the wrong thing to do, because I'm hacking at a well tested, nicely written JavaScript toolkit, this is how I fixed the problem:

I went into the DOJOX QueryReadStore.js and replaced the "start" and "count" references with acceptable (to the server-side language) parameter names.

I would have like to handled the issue via my PL/SQL (but I don't know how to get around reserved words) or client-side code (subclassing did not do the trick)...without getting into the internals of the library. But it works, and I can move on.

happyappa
A: 

As opposed to removing it from the API, as you mentioned, you can actually create a subclass with your own fetch, and remove start/count parameters (theoretically). Have a look at this URL for guidance:

http://www.sitepen.com/blog/2008/06/25/web-service-data-store/

Start and count are actually very useful because they allow you to pass params for the query that you can use to filter massive data sets, and it helps to manage client-side paging. I would try to subclass instead, intercept, and remove.

hal10001
A: 

Is your pl/sql program accessed via a URL and mod_plsql? If so, then you can use "flexible parameter passing" and the variables get assigned to an array of name/value pairs.

Define your package spec like this...

create or replace package pkg_name
    TYPE plsqltable
   IS
      TABLE OF VARCHAR2 (32000)
         INDEX BY BINARY_INTEGER;

   empty   plsqltable;
 PROCEDURE api (name_array IN plsqltable DEFAULT empty ,
                         value_array IN plsqltable DEFAULT empty
   );
END pkg_name;

Then the body:

    CREATE OR REPLACE PACKAGE BODY pkg_name AS
    l_count_value number;
    l_start_value number;
    PROCEDURE proc_name (name_array IN plsqltable DEFAULT empty,
                   value_array IN plsqltable DEFAULT empty) is
    ------------
    FUNCTION get_value (p_name IN VARCHAR) RETURN VARCHAR2 IS 
    BEGIN
    FOR i IN 1..name_array.COUNT LOOP
        IF UPPER(name_array(i)) = UPPER(p_name) THEN
           RETURN value_array(i);
        END IF;
    END LOOP;
    RETURN NULL;
    END get_value;
    ----------------------
    begin
    l_count_value := get_value('count');
    l_start_value := get_value('start');
    end api;
    end pkg_name;

Then you can call pkg_name.api using

http://server/dad/!pkg_name.api?start=3&count=3
MojoMark