• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Bitwise use of SQL integer

 
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given JSP/servlet web-app:
Form with twelve checkboxes. I can store the state of each of the checkboxes as a bit set to 1 for box checked, in an SQL integer. I can retrieve the integer and loop through a shifted bit mask to reset the checkboxes in the form for editing.

The problem:
Ideally I'd like to perform a query like (SELECT (COUNT colBox) FROM tblBoxes WHERE colBox AND 3) would return a count of rows with bit 1 set in the integer.
The other choice is to select * colBox, && to a bitmask and count the good ones for 32 bitmasks thousands of times.

I'm sure there's an algorithm or query out there. Any ideas or references would be appreciated.
[ September 28, 2004: Message edited by: Howard Watson ]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

you haven't indicated what database you are using!

MySQL has a bitwise operator, and you'd do something like

SELECT * FROM table WHERE someBigIntField & 3;

hth
Roberto
 
Howard Watson
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pervasive SQL 2000i. I think my "Ideally" is supported by some database vendors, and may not be supported by mine. I posted there too.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic