View · Search · Index
No registered users in community xowiki
in last 10 minutes

[Xotcl] Sqlite command inside NX object

From: Victor Mayevski <vitick_at_gmail.com>
Date: Thu, 28 Jul 2011 17:24:34 -0700

#I am confused about the following behaviour of Sqlite command inside
NX object.

Object create o;
o require namespace;
sqlite3 o::db /tmp/my.db
o db eval {create table mytable (data)};
o public method insert {data} {:db eval {insert into mytable values ($data)} };

#In the above, sqlite sees the variable $data as being empty (or non-existent);
#If I rewrite the method in a following way (using double quotes
instead of braces), it works:

o public method insert {data} {:db eval "insert into mytable values ($data)" };

#The problem is that I might want to insert binary/BLOB data etc,
therefore use the : _at_ $ prefix for variables, I have to use braces,
not double quotes.
#After much trial and error I got the following to work:

o public method insert {data} {[self]::db eval {insert into mytable
values ($data)} };

#why doesn't sqlite see the variable with :db AND braces syntax but it
works fine with [self]::db or :db + double quotes syntax ?
#as far as I am concerned, the problem is solved, I am just curious
what is going on here.