Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The script doesn't treat my parameters as variables

Status
Not open for further replies.

royzhang

Programmer
Aug 29, 2011
9
US
Hi,
I'm pretty new in tcl. I made the following proc log_event. There are three parameters passed: "msgid, state and status".
When I called "log_event dkflj fjlksd fdjls",
the script doesn't treat the parameter as variables! I appreciate if anyone can shed a light on it.

mysql> select * from logging;
+----+--------+--------+---------+------------+
| id | MID | STATE | STATUS | DATE |
+----+--------+--------+---------+------------+
| 51 | $msgid | $state | $status | 2011-08-29 |
+----+--------+--------+---------+------------+


----------------------------------------------------------
#!/cygdrive/c/Tcl/bin/tclsh

proc log_event {msgid state status} {

package require mysqltcl
global mysqlstatus

set port {3306}
set host {localhost}
set user {root}
set password {gofish}
set db {event_logging}

set handler [mysqlconnect -host $host -port $port -user $user -password $password -db $db]

mysqlexec $handler {insert into logging(mid,state,status,date) values('$msgid','$state','$status',now())}

set query [mysqlsel $handler {select * from logging} -flatlist]
puts $query
mysqlclose $handler

}

log_event dkflj fjlksd fdjls
----------------------------------------------------------------


$ ./2.tcl
51 {$msgid} {$state} {$status} 2011-08-29
 
Try using "" instead of {} in the mysqlexec call.

_________________
Bob Rashkin
 
Thanks million Bob, It's working!!! Can you give me a hint why the reason?
 
In Tcl there are varying levels of delayed substitution. That is, when you say, for instance, "$varname", at what point in the evaluation of the script will the current value of the variable named, "varname", be substituted for the placeholder, "$varname".

"" means immediately. {} means when the step is executed. In your case, I think the single quotes (' ') inside the brackets ({}) were essentially making the substitution permanently delayed. For an experiment, try returning to the brackets and take out the single quotes altogether.

_________________
Bob Rashkin
 
Good explanation!
I did put back the brackets and take out the single quotes, got unknown column error. Single quote may be necessary by sql.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top