Solved

How are Queries Interpreted?

Posted on 2002-07-17
2
247 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Group Policy Objects 5 193
Stuck thread in application running in Welogic 10.3.5 13 379
users are accessing the application at the particular time 5 207
wmware 10 329
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

10 Experts available now in Live!

Get 1:1 Help Now