Hi,I am looking to make some variable names act like reserved words sothat users cannot change them.An example of its use would be to stop users from redefining the symor date variable in a hdb q process.Any ideas of how to do this?Thanks
One way to do it is define your variables in the .q namespace (\d .q)-AjayOn Dec 15, 8:55?am, Daniel <cas…> wrote:> Hi,>> I am looking to make some variable names act like reserved words so> that users cannot change them.> An example of its use would be to stop users from redefining the sym> or date variable in a hdb q process.>> Any ideas of how to do this?>> Thanks</cas…>
q is actually a wrapper around k. ?look at the value of count:
q)count
#:
that is, (count) is (#:) in k. ?if you try to assign to count:
q)count:1
'assign
now the q wrapper is open-source and you can find it in q.k?
in the?q install (say,?C:\q\q.k on windows). ?just patch q.k
to do what you require! ?easy :)
ajay’s suggestion might be more sensible!
This seems want I want but the q namespace seems to apply a value towhatever I assign it to?q)sym:A
BCq).q.sym:symq).q.symq)
AB
Cq)sym’Cq)sym:4’assignTried assigning .q.sym to sym but it didnt become reserved.q).q.sym:
symq)symA
B`Cq)sym:4q)sym4Any ideas?On Dec 15, 12:07?pm, Ajay <rathore.a…> wrote:> One way to do it is define your variables in the .q namespace (\d .q)>> -Ajay>> On Dec 15, 8:55?am, Daniel <cas…> wrote:>>>>>>>> > Hi,>> > I am looking to make some variable names act like reserved words so> > that users cannot change them.> > An example of its use would be to stop users from redefining the sym> > or date variable in a hdb q process.>> > Any ideas of how to do this?>> > Thanks</cas…></rathore.a…>
there is no such explicit constraint.
charset=us-ascii
X-Mailer: iPhone Mail (9A405)
In-Reply-To: <21f16338-b3c5-489b-90e1-5cbc40d86500@e8g2000prb.googlegroups.com>
Message-Id: <3B02B30C-1987-4CA3-9BB8-3517FE258C0B@gmail.com>
Date: Thu, 15 Dec 2011 00:04:29 -0500
To: “personal-kdbplus@googlegroups.com”
Mime-Version: 1.0 (1.0)
http://code.kx.com/wiki/Reference/Cmdlineb
Thanks Timothy but I am looking to only restrict certain variables.
As if you reassign the sym variable in a HDB then the data wont
display properly unless you reload it.
charset=us-ascii
X-Mailer: iPhone Mail (9A405)
In-Reply-To: <5fb0e516-7a6a-489e-80f0-c8f762bd2c91@v31g2000prg.googlegroups.com>
Message-Id: <079F1004-553D-4DD7-B9D6-A90E092746A5@gmail.com>
Date: Thu, 15 Dec 2011 00:58:42 -0500
To: “personal-kdbplus@googlegroups.com”
Mime-Version: 1.0 (1.0)
In that case you can:
1) Implement fine grained controls yourself using the query callbacks (ie .=
z.pg/ps etc) and manually check what’s being done via the parse trees. This i=
s difficult to do correctly and will take quite a bit of time to code up.
2) Use a gateway that only allows canned queries/functions.
3) You can also use .z.vs to implement a very crude version by keeping a “se=
cret” backup and restoring on modification.
4) Another poor choice is to reload your data/environment after each query (=
\l .). Not optimal or bullet proof. You could also do an xinetd type thing w=
here you spawn a q process per query. Again, not awesome.
Did some testing of this and adding .q.sym does not effect the HDBreloading or enumeration.HDB is setup enumerated with H F G and I.q)sym:A
BCq).q.sym:
12q)sym:dsad'assignq)\l .q).q:
sym _ .qq)symH
FG
ISo it appears the reloading of the HDB can reassign the underlying symvalue without doing anything to .q.sym.Also when the HDB is unenumerating it also seems to use the symvariable rather than the .q.sym.Hence this seems to be what I want as the user cannot redefine sym butreloading the hdb will redefine sym and the unenumeration seems to beuneffected.On Dec 15, 12:21?pm, Daniel <cas…> wrote:> This seems want I want but the q namespace seems to apply a value to> whatever I assign it to?>> q)sym:A
BC> q).q.sym:sym> q).q.sym> q)
AB
C> q)sym> 'C> q)sym:4> 'assign>> Tried assigning .q.sym to sym but it didnt become reserved.>> q).q.sym:
sym> q)sym> A
B`C> q)sym:4> q)sym> 4>> Any ideas?>> On Dec 15, 12:07?pm, Ajay <rathore.a…> wrote:>>>>>>>> > One way to do it is define your variables in the .q namespace (\d .q)>> > -Ajay>> > On Dec 15, 8:55?am, Daniel <cas…> wrote:>> > > Hi,>> > > I am looking to make some variable names act like reserved words so> > > that users cannot change them.> > > An example of its use would be to stop users from redefining the sym> > > or date variable in a hdb q process.>> > > Any ideas of how to do this?>> > > Thanks</cas…></rathore.a…></cas…>
Adding your own stuff to .q namespace is certainly not recommended, for several reasons.
This “trick” of blocking assigns only works with the most simple of syntaxes, e.g.
sym set
rt
y
will not be caught.
Also this can confuse others later (during debug) whether the value is read from k or q, e.g.
q)value `s
k
oi
p
q)s
'c
q)k)s
k
oi
p
q).q.s
a
b`c
You’re likely better off either screening incoming queries for illegal calls or hooking .z.vs.