Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How are Queries Interpreted?

Posted on 2002-07-17
2
Medium Priority
?
253 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 200 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

876 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