Simple way to store lots of boolean data

Miklos_HollenderMiklos_Hollender Member Posts: 1,598
edited 2006-10-11 in NAV Tips & Tricks
As an idea that occured to me in this topic: http://www.mibuso.com/forum/viewtopic.php?t=13671

If you have lots of boolean, yes/no information, you don't need to create a field for each of them, you can also store them all in one integer, by borrowing the idea from Unix security.

For example, you have information that looks like false, false, true, false, true. You can write it as 00101 which is a binary number, and in decimal it is 5. (1 times 2 power 0 + 1 times 2 power 2) So you can store each combination as an integer value.

For example, this is how Microsoft CRM stores security, like, you can edit a given record (true) but not delete it (false).

Comments

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    True, good tip!

    Only problem I can think of it that you need to recaclulate the values and maybe even change code if you want to add a new filtervalue.
  • SteveOSteveO Member Posts: 164
    edited 2006-09-13
    This is what the BitVector32 Structure in .NET does.
    You can access each invidual bit of a 4 byte int (32 bits). You can make each bit significant in it's own way and use a mask to determine which bits are on and which are off.

    If someone wants to wrap this structure or reimplement it in Navision (using some funky binary maths) then that would probably be a way to go to achieve this functionality. (or use BlackTiger's approach which is just as feasible, if not simpler!!)
    This isn't a signature, I type this at the bottom of every message
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    That's also a solution.

    Have you ever tested the performance of filtering with ??? in the filter?
  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    BlackTiger,

    Yes, no filtering in the usual way. It's rather useful for security, for deciding what a given user can do with a given record/file, this is why MSCRM/Unix is using it. In the topic I linked above, the guy who opened it asked about security filters, and this gave me the idea.

    P.S. Last week I signed a contract in the UK with the help of Steve D., the guy we both know. He really has good contacts...
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Congrats :mrgreen:

    You'll need to change you flag :D
  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    You'll need to change you flag

    Nope. That reflects my nationality, not my location. I changed my location, that should be enough :)
  • KowaKowa Member Posts: 923
    Good luck from me too ! I hope you have made the right choice.
    Kai Kowalewski
Sign In or Register to comment.