Solved

How are Queries Interpreted?

Posted on 2002-07-17
2
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

632 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