 |
Pega Magician
Joined: 08 Jan 2001 Posts: 341 Location: Singapore
|
Posted: Fri Apr 09, 2004 7:47 pm
Database Questions II |
Does anybody know of a way to extract a value from a record without evaluation?
I have a record with a value field which contains () around it. The parentheses disappear whenever I try to display or make use of it. For example, using %expanddb without extra parameters the parentheses remain, however when the additional fields are used in %expanddb, the parentheses disappear from the record values.
Perhaps there should be a zMUD command to extract the keys and values from database records into a zMUD variable ie. @temp instead of %val and %key? This would then enable proper scoping(?) of values to prevent unwanted evaluation.
These record values especially involve records stored in zMUD variables. |
|
|
 |
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Apr 10, 2004 5:03 pm |
For the current record.
#VAR temp %rec
For any record in the current database.
#VAR temp @21
For any record.
#VAR temp @17eq
You can also access the fields directly.
#SHOW @13it.Value |
|
|
 |
Pega Magician
Joined: 08 Jan 2001 Posts: 341 Location: Singapore
|
Posted: Mon Apr 12, 2004 5:58 am |
Thanks again Lightbulb! I have not yet made use of the @21 and @17eq syntax in my scripts.
However, I regret to say it hasn't solved the problem of parentheses being removed from the data. I have a set of data in the database some having () in them but most without it, so it does matter if () exists.
It does not solve the scoping or evaluation problem because for whatever reason, @db.key values seem to always evaluate the data stripping the parentheses contained.
From what I can see, assigning variable to variable does not remove the parentheses. This is different with database variables or when taking data from the database, the parentheses seem to be stripped every time. It happens in functions like %pos(), in commands like #show {}, and within #if expressions.
Do you know of a way to handle @17eq.desc or @dbrec.desc without the ()s in the data disappearing?
Would VBScript or JScript solve the problem?
Thanks! |
|
|
 |
jessew Apprentice
Joined: 03 Mar 2003 Posts: 141
|
Posted: Mon Apr 12, 2004 6:45 am |
That is weird, @17eq.desc will strip away the ()s but %db(17eq,desc) will not. So using %db instead of the short syntax should do what you want.
Edit.
As a note though using %db(%rec,desc) will strip the ()s
Jesse |
|
|
 |
Pega Magician
Joined: 08 Jan 2001 Posts: 341 Location: Singapore
|
Posted: Mon Apr 12, 2004 8:14 am |
Thanks jessew! That will help with the database access.
That leaves database records which are stored in zMUD variables. As I have mentioned at the bottom of my original post.
Sometimes I capture these data into a database variable for evaluation before storing them into the database. I guess I should just stick to using a pair of ordinary variable lists instead of a database record variable for this sort of thing.
Cheers |
|
|
 |
Greendale Beginner
Joined: 19 Mar 2004 Posts: 17 Location: Sweden
|
Posted: Mon Apr 12, 2004 2:29 pm |
Pega, you can use the same method for records stored in variables. I use it all the time, and it doesn't stip the ().
%db(@myrec,desc) |
|
|
 |
Pega Magician
Joined: 08 Jan 2001 Posts: 341 Location: Singapore
|
Posted: Mon Apr 12, 2004 3:20 pm |
I just tried it, and %db(@myrec,desc) does strip the ().
Whereas %db(3835eq,desc) does not strip the ().
I checked @myrec and it does contain ()s.
To be clear, in my general parsing settings I have only 4 boxes checked, they are Echo Commands/messages/scripts and Capture Commands.
Regards |
|
|
 |
jessew Apprentice
Joined: 03 Mar 2003 Posts: 141
|
Posted: Mon Apr 12, 2004 3:46 pm |
Yeah I Get the same thing too RecordVar.Key or %db(RecordVar, Key) strips the ()s. Only If I access the Database directly %db(17eq, Key) will it return it correctly. It's storing the Value right in the variable when using %rec, or %dbget though. Num2.dName(test)
Jesse |
|
|
 |
Greendale Beginner
Joined: 19 Mar 2004 Posts: 17 Location: Sweden
|
Posted: Mon Apr 12, 2004 4:06 pm |
Then something is different in our setups. I'm on 7.05 by the way.
|
|
|
 |
Pega Magician
Joined: 08 Jan 2001 Posts: 341 Location: Singapore
|
Posted: Mon Apr 12, 2004 4:18 pm |
I am on 7.05 too.
From my first post if my memory serves me right, %expanddb(@s) does not strip ()s, but %expanddb(@s,x) and %expanddb(@s,x,y) both strip ()s. |
|
|
 |
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Apr 12, 2004 5:09 pm |
Recent versions have allowed nesting one record variable (database variable) inside another record variable. zMUD uses ()'s around the value to indicate that the value is a nested record.
Unfortunately, this means you'll have problems with values which are surrounded by ()'s that aren't nested records. |
|
|
 |
Greendale Beginner
Joined: 19 Mar 2004 Posts: 17 Location: Sweden
|
Posted: Mon Apr 12, 2004 5:27 pm |
OK, I'm sorry. I have record variables with () in them, but not with ( in the first position. I see now that there is a difference. My bad.
|
|
|
 |
jessew Apprentice
Joined: 03 Mar 2003 Posts: 141
|
Posted: Mon Apr 12, 2004 5:38 pm |
For a sloppy fix, if you know your working with a record that doesn't contain nested records you can write a function like this to get your ()s. Only if need to use record variables and dealing with the database record directly is not an option.
#FUNCTION pdb {%db(%replace(%replace(%1,"(","(("),")","))"),%2)}
Use it in place of %db
For Example
@pdb(%rec,desc)
Cheesy, but works by doubling the ()s, outer ones are parsed away leaving the inners
I'd recommend just requesting the key values from the database directly though %db(17eq,desc)
Jesse |
|
|
 |
|
|