
Programming i!-Database Plus
13
i!-Database Plus and DBWizard
need to fill this out properly. See the section
Putting It All Together
section on page 28 for
reference. Also, call
DB_LISTBOX_INIT
to initialize your listbox.
(***********************************************************)
(* STARTUP CODE GOES BELOW *)
(***********************************************************)
DEFINE_START
(* INIT dB WEB CLIENT *)
DB_INIT_CLIENT (sDB_CLIENT,dvDB_CLIENT,'192.168.12.175',80,'/dB/CDExample.asp')
CREATE_BUFFER dvDB_CLIENT,sDB_CLIENT.strBUFF
(***********************************************************)
(* STARTUP CODE GOES BELOW *)
(***********************************************************)
DEFINE_START
DB_LISTBOX_INIT(sTitleListBox,10,1)
The next section of code reads the information from the web server and copies the data to the
structure you created to hold the results. The
DATA_EVENT
below has a couple of different parts.
The
ONERROR
section of the
DATA_EVENT
occurs whenever we encounter a communications
problem. The code here simply clears the buffer, calls
DB_GET_IP_ERROR
to return a text error
from our error code (held by
DATA.NUMBER
) and prints the error to the terminal.
The
ONLINE
section of the
DATA_EVENT
occurs whenever a connection to the web server is
established. The code here clears our buffer and calls
DB_BUILD_HTTP_GET
to format the request
for the web server. Send this request to the server and it will process the results and return the
information.
The
OFFLINE
section of the
DATA_EVENT
occurs whenever a connection to the web server is
dropped. A web server will normally drop the connection whenever is has finished processing the
request, so this is a great time for to interpret the results received. Normally, this would occur in a
STRING
section of a
DATA_EVENT
. The first thing to do is create a series of variables that needed
through the event. To kick off the processing, call
DB_PROCESS_HTTP_HEADER
which will parse
the HTTP header information from the response and deal with any cookies the web server wants
you to deal with. Once that has happened, drop into a select active to process the data.
The first active in your select active makes sure the HTTP return code is
200
. If not, some error has
occurred but luckily your call to
DB_PROCESS_HTTP_HEADER
has already processed all the errors
and printed those errors to terminal. This call will detect standard HTTP errors as well as ASP
script errors. ASP script errors may be generated by incorrect SQL so if something does not appear
to work, check the terminal for a description of the problem.
If
DB_PROCESS_HTTP_HEADER
has returned a value of 200 (this is a HTTP code meaning OK),
then there is data for to process. The first thing to do is look for your tag. This is the tag you sent
with the request with a few extra characters added. The first is the
</rs
which signifies then end of
an XML tag whose name is
rs<Our Tag>
where rs stands for record set. The trailing
>
is the end
of the XML tag. One of the things our call to
DB_PROCESS_HTTP_HEADER
did for you was find the
start of the XML packet. This is the point from which you begin your search.
Once we have identified what the response is to, we can process it. The next thing we do is pull out
the list box information contained in the XML by calling
DB_PROCESS_LISTBOX
. This function
returns the position to begin to parsing for more information. You should expect to see a series of
structures that represent your data. Simply loop as long as you can find
<struct>
in the XML