No registered users in community xowiki
in last 10 minutes
in last 10 minutes
Re: [Xotcl] Sqlite command inside NX object
From: Gustaf Neumann <neumann_at_wu.ac.at>
Date: Mon, 01 Aug 2011 14:19:45 +0200
Dear Victor,
The confusion is in part due to the fact, that mysql uses the tcl idiom
"eval" and varnames looking like tcl varnames, but it provides its
semantics with its own machinery. One can use
db1 eval {insert into mytable values ($data)}
but one cannot use syntactically e.g.
db1 eval {insert into mytable values (${data})}
since the sqlite sql parser does not know about braced var-names, and the
"eval" after "db1" is no "eval" in the Tcl sense.
I would recommend to let sqlite create its own objects, and address
these with their full path.
sqlite3 ::db1 /tmp/my.db
::db1 eval {create table mytable (data)}
Object create o
o public method insert {data} {::db1 eval {insert into mytable values ($data)} }
In case, you need/want databases per object/class, you can certainly use
[self] inside the database handle. This is essentially the same what you
found out.
-gustaf neumann
Am 29.07.11 02:24, schrieb Victor Mayevski:
> #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.
Date: Mon, 01 Aug 2011 14:19:45 +0200
Dear Victor,
The confusion is in part due to the fact, that mysql uses the tcl idiom
"eval" and varnames looking like tcl varnames, but it provides its
semantics with its own machinery. One can use
db1 eval {insert into mytable values ($data)}
but one cannot use syntactically e.g.
db1 eval {insert into mytable values (${data})}
since the sqlite sql parser does not know about braced var-names, and the
"eval" after "db1" is no "eval" in the Tcl sense.
I would recommend to let sqlite create its own objects, and address
these with their full path.
sqlite3 ::db1 /tmp/my.db
::db1 eval {create table mytable (data)}
Object create o
o public method insert {data} {::db1 eval {insert into mytable values ($data)} }
In case, you need/want databases per object/class, you can certainly use
[self] inside the database handle. This is essentially the same what you
found out.
-gustaf neumann
Am 29.07.11 02:24, schrieb Victor Mayevski:
> #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.
-- Univ.Prof. Dr. Gustaf Neumann Institute of Information Systems and New Media WU Vienna Augasse 2-6, A-1090 Vienna, AUSTRIA