Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Store flags in MySQL?

 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what's a good variable type to store flags?
I guess you can do TEXT or VARCHAR(255) and have unique words in it, but that's a little inefficient...
int bits are a bit confusing....

Anything you can suggest?
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should be posting this question in JDBC forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quite correct... moved.
 
Jason Steele
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well,
Since, generally flags are (on or off) or (1 or 0) or some similar pattern, I would go with tinyint. Could you be more specific?
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well... If for instance I wanted a whole bunch of flags, like "user owns this, user can delete this, user can modify this, etc", would I have to create a separate column for each and every one?
I mean as I go along, I might get more and more flags, and I don't think it would be cool to have 30 columns in there, most of which would be barely used...
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you create a FLAG_TABLE with 2 columns.
FLAG_ID
FLAG_DESC
Then wherever you needed a flag, use the FLAG_ID from the FLAG_TABLE.
 
Dana Hanna
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use bits on an INT (my preferred approach), or a seperate "USER_SECURITY" table, with tons of fields. Either way, abstract it in your code such that it can change later on.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic