V
V
Viktoria Smirnova2018-04-05 07:47:50
MySQL
Viktoria Smirnova, 2018-04-05 07:47:50

Loop in db query?

I send a query to the MySQL database in the form of the string "10110010", 0 and 1 are my on / off checkboxes, the fields in the database store 1 and 0, Question: how to do without a bit mask and bit operations in the request? For example, split the line

String str = “10110010”
char[] chars = str.toCharArray();


then loop through the query

SELECT * FROM table WHERE …

Is it possible? How to do it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
awesomer, 2018-04-05
@awesomer

You don't have to cycle through the database .
to extract or set bits from a bit mask - it will be many orders of magnitude faster than receiving an answer to an extra request from the DBMS.
why string bits?
it is much more convenient to work with digital ones using masks.

E
Eugene, 2018-04-05
@eGenius18

hmm ... not very clear what it is for and why such difficulties? but I'll assume it's just a set of checkboxes. then we just store the set in the database in 1 field 01010010100, read it and convert it to an array like this:
"01010010100".split("").map(Number)
and then place the checks

F
forspamonly2, 2018-04-06
@forspamonly2

bitwise operations (and operations on substrings) are not humanly indexed.
for boolean fields, the index is also low-selective, but if there are much fewer ticks in a particular query than there are ticks in total, then it will be useful.
so it's better to decompose the checkboxes into separate fields.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question