Solved

How are Queries Interpreted?

Posted on 2002-07-17
2
246 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
Comment Utility
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
Comment Utility
Thanks! This should definitely help me understand.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
IBM Server MegaRAID Bios Utility RAID 10 setup with 8 drives 9 855
websphere 5 311
Hylafax server 4 185
Help troubleshoot failed logins 4 168
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…
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 …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now