Re: [sqlite] Newbie what does & do.

2009-03-28 Thread Kees Nuyt
On Sat, 28 Mar 2009 09:42:59 +, Dermot
 wrote:

>2009/3/28 Jay A. Kreibich :
>> On Fri, Mar 27, 2009 at 05:37:49PM +, Dermot scratched on the wall:
>>
>>> The statement is:
>>>
>>> SELECT COUNT(*) FROM products WHERE productid=808800033 AND
>>> (allowcountry2 & 0x0001)
>>> SELECT COUNT(*) FROM products WHERE productid=808800033 AND
>>> (allowcountry1 & 0x8000)
>>>
>>> I believe the allowcountry part is a bit pattern lookup but I can't
>>> find a definition for the & and so I am not sure what the statement
>>> does bar count the results.
>>
>>  To actually answer your question, yes, "&" in SQLite and some other
>>  DBs is a bitwise "and" operator, just like the C/C++ "&" operator.
>>  "|" is a bitwise "or".
>>
>>  It is my understanding that these operators are not part of the
>>  SQL standard, but a number of databases implement the operator.
>
>First off, sorry it was such an off-topic question. Thank you Jay for
>the answer.
>
>I can't find any reference to the ampersand's usage in my new book, my
>copy of learning MySQL or the SQLite Syntax documentation. I would
>have expected symbols to be listed before A in the index myself. There
>are references to bitmap indices. Symbols refer to the BNF notation
>but without reference to &. I have posted to SQLQueries.  Hopefully I
>can get an understanding of what that statement means from there.

For future reference, here's an explanation of all binary
operators, that is the

-> [expr] -> (binary-operator) -> [expr] ->

part of the expr BNF diagram on 
http://www.sqlite.org/lang_expr.html

A few of those are bitwise.

pre-
ce-
den- opera-
ce   toroperation
 -- ---
1|| concatenation
2*  multiplication
2/  division
2%  modulo (remainder of integer division)
3+  addition
3-  subtraction
4<< bitwise shift left
4>> bitwise shift right
4&  bitwise AND
4|  bitwise OR
5<  less than
5<= less than or equal
5>  greater than
5>= greater than or equal
6=  equal
6== equal
6!= not equal
6<> not equal
6IN subset of
6LIKE   case insensitive equality 
with % and _ wildcards
6GLOB   case sensitive equality
with Unix style file globbing syntax
6MATCH  reserved for user C function match()
6REGEXP reserved for user C function regexp()
7ANDboolean (logical) AND
8OR boolean (logical) OR


(Note to the SQLite developers: I could put this in the wiki
but it might be better to update the
http://www.sqlite.org/lang_expr.html#binaryops page itself)

> Again sorry for the post.

No problem.

>Dp.
-- 
  (  Kees Nuyt
  )
c[_]
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Newbie what does & do.

2009-03-28 Thread Dermot
2009/3/28 Jay A. Kreibich :
> On Fri, Mar 27, 2009 at 05:37:49PM +, Dermot scratched on the wall:
>
>> The statement is:
>>
>> SELECT COUNT(*) FROM products WHERE productid=808800033 AND
>> (allowcountry2 & 0x0001)
>> SELECT COUNT(*) FROM products WHERE productid=808800033 AND
>> (allowcountry1 & 0x8000)
>>
>> I believe the allowcountry part is a bit pattern lookup but I can't
>> find a definition for the & and so I am not sure what the statement
>> does bar count the results.
>
>  To actually answer your question, yes, "&" in SQLite and some other
>  DBs is a bitwise "and" operator, just like the C/C++ "&" operator.
>  "|" is a bitwise "or".
>
>  It is my understanding that these operators are not part of the
>  SQL standard, but a number of databases implement the operator.

First off, sorry it was such an off-topic question. Thank you Jay for
the answer.

I can't find any reference to the ampersand's usage in my new book, my
copy of learning MySQL or the SQLite Syntax documentation. I would
have expected symbols to be listed before A in the index myself. There
are references to bitmap indices. Symbols refer to the BNF notation
but without reference to &. I have posted to SQLQueries.  Hopefully I
can get an understanding of what that statement means from there.

Again sorry for the post.
Dp.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Newbie what does & do.

2009-03-27 Thread Jay A. Kreibich
On Fri, Mar 27, 2009 at 05:37:49PM +, Dermot scratched on the wall:

> The statement is:
> 
> SELECT COUNT(*) FROM products WHERE productid=808800033 AND
> (allowcountry2 & 0x0001)
> SELECT COUNT(*) FROM products WHERE productid=808800033 AND
> (allowcountry1 & 0x8000)
> 
> I believe the allowcountry part is a bit pattern lookup but I can't
> find a definition for the & and so I am not sure what the statement
> does bar count the results.

  To actually answer your question, yes, "&" in SQLite and some other
  DBs is a bitwise "and" operator, just like the C/C++ "&" operator.
  "|" is a bitwise "or".

  It is my understanding that these operators are not part of the
  SQL standard, but a number of databases implement the operator.

   -j

-- 
Jay A. Kreibich < J A Y  @  K R E I B I.C H >

"Our opponent is an alien starship packed with atomic bombs.  We have
 a protractor."   "I'll go home and see if I can scrounge up a ruler
 and a piece of string."  --from Anathem by Neal Stephenson
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Newbie what does & do.

2009-03-27 Thread John Machin
On 28/03/2009 4:37 AM, Dermot wrote:
> Hi,
> 
> I just bough my "Introduction to SQL 4th edition" as per a list
> member's advice.
> 
> Before I had a chance to take it home and start going through it I
> came across an SQL statement that I could use some help understanding.
> 
> The statement is:
> 
> SELECT COUNT(*) FROM products WHERE productid=808800033 AND
> (allowcountry2 & 0x0001)
> SELECT COUNT(*) FROM products WHERE productid=808800033 AND
> (allowcountry1 & 0x8000)
> 
> I believe the allowcountry part is a bit pattern lookup but I can't
> find a definition for the & and so I am not sure what the statement
> does bar count the results.
> 
> Can someone enlighten me? I should point out that this command is used
> on a MySQL DB.

Here's some meta-advice:

Check for an index at the back of the book.
If none, ask for a refund.
"&" should be listed either under a "Symbols" (or similar) section 
before the letter "A", or under "operators".
If not, ask for a refund.

HTH,
John
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Newbie what does & do.

2009-03-27 Thread Dermot
Hi,

I just bough my "Introduction to SQL 4th edition" as per a list
member's advice.

Before I had a chance to take it home and start going through it I
came across an SQL statement that I could use some help understanding.

The statement is:

SELECT COUNT(*) FROM products WHERE productid=808800033 AND
(allowcountry2 & 0x0001)
SELECT COUNT(*) FROM products WHERE productid=808800033 AND
(allowcountry1 & 0x8000)

I believe the allowcountry part is a bit pattern lookup but I can't
find a definition for the & and so I am not sure what the statement
does bar count the results.

Can someone enlighten me? I should point out that this command is used
on a MySQL DB.

Thanx,
Dp.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users