Juan J. Sánchez":18xy8cn9 said:
Also, I have a question. I'm making a database for a set of items that can happen multiple days a week. I decided, in order to save space, I would make 7 boolean-type columns, one for each day of the week. Is there a better way to do this? Originally I thought of using a single string-type column containing a character for each day of the week. Would this be a better choice?
What platform?
I'd say the best option is to store them as a single 8-bit char type and using 7 of those bits as a mask for each day of the week.
Monday would be 0x01, Tuesday 0x02, Wednesday 0x04, Thursday 0x08, Friday 0x10, Saturday 0x20, Sunday 0x40
You'd use a logical AND & to test for days of the week and a logical OR | to set days of the week and to remove a day you'd AND & it with the NOT ~ of the day you want to remove.
days = 0 // Initialise to no days set
days |= ( 0x1 | 0x2 ) // Monday and Tuesday set
isMonday = ( days & 0x1 ) // check if Monday is set
days &= ~0x2 // Remove Tuesday
That would be the most efficient method. Unless your database software automatically uses integer bit masks for booleans (which would be awesome) - in which case might as well use 7 booleans.