luocl <
[email protected]> wrote:
in the following script, I can store a title with a space in it, but
I cann't select content from title which have a space in it.
What do you get back from your script? Because it works just fine
here.
package require sqlite3
catch [exec rm --force note.db]
It is unnecessary to exec an 'rm' when Tcl has "file delete" as a
builtin command.
variable tblname note
proc gettbl {} {
variable tblname
return $tblname
}
Why a proc to return a table name from a variable? Why not just use
the variable in the other proc's?
A slightly simplified version of your script that I am using:
Changes are:
1) uses file delete instead of exec rm
2) inserts delimiters <> around the variables in the puts in the query
proc.
$ cat luocl
package require sqlite3
file delete -force note.db
namespace eval db::note {
sqlite3 db note.db
variable colnames
lappend colnames {title text} {parent text} {content text}
variable tblname note
proc gettbl {} {
variable tblname
return $tblname
}
proc getcolname col {
variable colnames
return [lindex $colnames $col 0]
}
proc create {} {
variable colnames
db eval "CREATE TABLE [gettbl]([join $colnames ,])"
}
proc query {} {
db eval [list SELECT * FROM [gettbl]] {
puts "title=<$title> parent=<$parent> content?<$content>"
}
}
proc insert { title parent content} {
db eval [list INSERT INTO [gettbl] VALUES(:title,:parent,:content)]
}
proc content {title} {
db eval [list SELECT content FROM [gettbl] where title=':title'] {
return $content
}
}
}
So, now I run the script:
$ rlwrap tclsh
% source luocl
% db::note::create
% db::note::insert {de bug} {} {please help me!!}
% db::note::query
title=<de bug> parent=<> content?<please help me!!>
% exit
And the title returns perfectly, embedded spaces and all.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)