|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Wed Jan 26, 2011 12:48 am
%dbvalues stringlist order same as db record? |
Right now I'm running into a problem where I want to replace a record in a DB variable if its value is already there, instead of adding a new key=value pair in that instance. I can check for whether or not the value exists by creating a temporary string variable in the %ismember function using %dbvalues. What I'm wondering is, is the position returned by %ismember from that stringlist the same position of the record in the DB. I ask this rather than just test it to avoid running into problems of coincidence where it works sometimes and doesn't work others. Thanks.
|
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Jan 26, 2011 2:00 pm |
My understanding is that it is the same--until you change the db variable. There is no guarantee that order will be maintained when any element is added, deleted, or changed. But there is an easier way to get this information--the %isvalue() function.
It sounds like you are doing something very odd. Are you saying that you want to replace a key/value pair if the _value_ is the same as the one you want to put in? In other words, you want to delete the existing key/value pair, and add a new pair with the same value and a different key?
I assume there is a reason that you don't want to simply reverse the order in your variable, making your values the keys and vice versa. You need to also search for things by key, right? In that case, the most efficient method might be to have two db variables, set up to handle A=B and B=A. The tricky part is keeping them synchronized, of course, but that's not too hard as long as you consistently use one function to make the changes.
But you can certainly do it they way you are thinking, with the %isvalue() function. |
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Thu Jan 27, 2011 4:27 am |
Hmm, for some reason I wasn't considering the %isvalue function, but I can do that too. And yes, I need to operate on the values, which, in this one case, end up operating as my "keys" because I can only use the key portion of a db variable for pattern matching to my knowledge.
|
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|