Solved

How are Queries Interpreted?

Posted on 2002-07-17
2
248 Views
Last Modified: 2012-05-04
How does StoryServer return queries for example if

SEARCH TABLE foo INTO t SQL [concat "select * from " $table]
foreach x $t {
 set id [lindex [lindex $x 1] 0]
 set curl [CURL $template $id]
 ....
 append f {  } <B>[lindex [lindex $x 1] 1]</B>\n<BR>
}
 
Problem is that we are not currently running StoryServer anymore and I am converting TCL code into ColdFusion. So I am trying to understand how TCL works
How does lindex work with queries ?
 Any help would be great!
0
Comment
Question by:DorianP
2 Comments
 
LVL 1

Accepted Solution

by:
hooker042299 earned 50 total points
ID: 7165152
Here is a fully fleeced out example:

Let's say we have a database like this:

TABLE emp
id name
== ====
1  john
2  bill
3  bob

Say we have a bit of code like this:
SEARCH TABLE x INTO y SQL "SELECT * FROM emp"

what happens is that Vignette takes the parameter "x" and creates a hidden variable called "_Schema_x" which is a tcl list containing the order of the columns returned by the SQL - do in this case "id name"

Then into y it places the data returned by the SQL and it places it in a tcl list with a reference to which _Schema_ hidden variable to reference to get the column names.
So, in this example the variable y would contain this:
{x 1 john} {x 2 bill} {x 3 bob}

We could then do something like this:
"foreach z $y {
set id [lindex $z 1]
set name [lindex $name 2]
}".


Returning to your example:
SEARCH TABLE foo INTO t SQL [concat "select * from " $table]
foreach x $t {
set id [lindex [lindex $x 1] 0]
set curl [CURL $template $id]
....
append f {  } <B>[lindex [lindex $x 1] 1]</B>\n<BR>
}

Your SQL is being created dynamically based on the value of the variable "table".
Then the "foreach" command is iterating through each row in the variable "t" and assigning that row to the variable "x"

Then, it sets the variable "id" to be the value at position 1 in the row (position 0 will be "foo" in each row - telling internal commands like "FIELD" to look at the hidden variable _Schema_foo as suggested previously).
The outer use of "lindex", "[lindex [lindex $x 1] 0]", rather than just "[lindex $x 1]" suggests that the data returned is itself a list. In the simplified example above, the outer "lindex" would not be necessary.
"set curl [CURL $template $id]" is setting a variable to be a custom url to the path value of variable "template" passing in "id" as the OID.
The line "append f {  } <B>[lindex [lindex $x 1] 1]</B>\n<BR>" confirms that the data returned by the SQL is not as simple as that which I did in my example because there are two elements in it - the id and whatever the developer wants to put in the html in variable "f".

To get a clearer picture, put the command "ERROR_TRACE" or "ERROR_TRACE $x" at various points in the code to understand the values of the various variables set.

Hope this helps.
0
 

Author Comment

by:DorianP
ID: 7165384
Thanks! This should definitely help me understand.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert websphere application server default chained Certificates from 1024 to 2048 keysize or higher size and also you can change signatureAlgorithm . Please make sure Websphere Application Server fixpack 7.0.0.23 or Above. The following steps a…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question