Re: [sqlite] decoding a bitmask

2014-10-13 Thread Paul Sanderson
Thanks all - agree rookie mistake with xor, had this been a C++ exercise I would have have been OK - SQL seems to make my mind go blank... Thanks for the case explanation Mark - v helpful. Paul www.sandersonforensics.com skype: r3scue193 twitter: @sandersonforens Tel +44 (0)1326 572786

Re: [sqlite] decoding a bitmask

2014-10-13 Thread Mark Lawrence
My apologies for the previous completely wrong mesage. I got mixed up with operator meaning & precedence... On Mon Oct 13, 2014 at 02:39:40PM +0100, Paul Sanderson wrote: > > My actual code is as folows > > (CASE visits.transition & 0xFF00 WHEN 0x0080 THEN 'Blocked' > ELSE '' END

Re: [sqlite] decoding a bitmask

2014-10-13 Thread Doug Currie
> > The query is on a visits table from a google chrome history database. The > query seems to work OK if a single bit is set, but fails (a blank string is > returned) when multiple bits are set. Any ideas why? > It's because none of the WHEN 0x... cases, except 0xC0..., have multiple bits set.

Re: [sqlite] decoding a bitmask

2014-10-13 Thread Clemens Herschel
Hi, I used to bitwise stuff in Assembler in the 60's when disk space was dear. Do not know your environment. But maybe my observations will help. CASE stops after one conditions is met and does not test other cases. The next line executed is after the CASEs When I worked with bits, I would

Re: [sqlite] decoding a bitmask

2014-10-13 Thread Igor Tandetnik
On 10/13/2014 9:39 AM, Paul Sanderson wrote: The query seems to work OK if a single bit is set, but fails (a blank string is returned) when multiple bits are set. Any ideas why? CASE x WHEN y ... checks that x = y, not that x & y != 0. You are checking for equality with a one-bit value - so

Re: [sqlite] decoding a bitmask

2014-10-13 Thread RSmith
On 2014/10/13 15:39, Paul Sanderson wrote: Thanks all Clemens - I went initially for your solution as it fitsbetter with some other work i have done My actual code is as folows (CASE visits.transition & 0xFF00 WHEN 0x0080 THEN 'Blocked' ELSE '' END || CASE

Re: [sqlite] decoding a bitmask

2014-10-13 Thread RSmith
On 2014/10/13 16:51, Mark Lawrence wrote: On Mon Oct 13, 2014 at 02:39:40PM +0100, Paul Sanderson wrote: The query is on a visits table from a google chrome history database. The query seems to work OK if a single bit is set, but fails (a blank string is returned) when multiple bits are set.

Re: [sqlite] decoding a bitmask

2014-10-13 Thread Clemens Ladisch
Paul Sanderson wrote: > (CASE visits.transition & 0xFF00 WHEN 0x0080 THEN 'Blocked' > ELSE '' END || >CASE visits.transition & 0xFF00 WHEN 0x0100 THEN 'Forward_Back' > ELSE '' END || >... > > The query seems to work OK if a single bit is set, but fails (a blank

Re: [sqlite] decoding a bitmask

2014-10-13 Thread Mark Lawrence
On Mon Oct 13, 2014 at 04:51:16PM +0200, Mark Lawrence wrote: > On Mon Oct 13, 2014 at 02:39:40PM +0100, Paul Sanderson wrote: > > Perl equivalent: > > use feature 'say'; > my $a = 0x0080 | 0x0800; > > say $a & 0x0080; > say $a & 0x0800; > say $a & 0x0800

Re: [sqlite] decoding a bitmask

2014-10-13 Thread Mark Lawrence
On Mon Oct 13, 2014 at 02:39:40PM +0100, Paul Sanderson wrote: > > The query is on a visits table from a google chrome history database. The > query seems to work OK if a single bit is set, but fails (a blank string is > returned) when multiple bits are set. Any ideas why? I suspect it is a bug

Re: [sqlite] decoding a bitmask

2014-10-13 Thread Paul Sanderson
Thanks all Clemens - I went initially for your solution as it fitsbetter with some other work i have done My actual code is as folows (CASE visits.transition & 0xFF00 WHEN 0x0080 THEN 'Blocked' ELSE '' END || CASE visits.transition & 0xFF00 WHEN 0x0100 THEN

Re: [sqlite] decoding a bitmask

2014-10-13 Thread Clemens Ladisch
Paul Sanderson wrote: > I have a table with an integer value which is a bitmask. > > 0c01 readonly > 0x02 hidden > 0x04 system > 0x10 directory > 0x20 archive > > I'd like to create a query which would take an attribute, say 0x07 and spit > out "system, hidden, readonly" SELECT substr(CASE WHEN

Re: [sqlite] decoding a bitmask

2014-10-13 Thread RSmith
On 2014/10/13 13:52, Paul Sanderson wrote: I have a table with an integer value which is a bitmask. one or more of the bits can be set and each bit has a corresponding meaning. so using the windows file attribute as an example we have 0c01 readonly 0x02 hidden 0x04 system 0x10 directory 0x20

Re: [sqlite] decoding a bitmask

2014-10-13 Thread Richard Hipp
On Mon, Oct 13, 2014 at 7:52 AM, Paul Sanderson < sandersonforens...@gmail.com> wrote: > I have a table with an integer value which is a bitmask. one or more of the > bits can be set and each bit has a corresponding meaning. > > so using the windows file attribute as an example we have > > 0c01

[sqlite] decoding a bitmask

2014-10-13 Thread Paul Sanderson
I have a table with an integer value which is a bitmask. one or more of the bits can be set and each bit has a corresponding meaning. so using the windows file attribute as an example we have 0c01 readonly 0x02 hidden 0x04 system 0x10 directory 0x20 archive none, any or all could be set I'd