Jay A. Kreibich wrote:
> On Sun, Apr 20, 2008 at 11:13:56AM +0200, Florian Weimer scratched on the 
> wall:
> 
>>* Dennis Cote:
>>
>>
>>>This last function can be implemented using bit manipulation operators 
>>>in SQL or in a custom function in C.
>>>
>>>    containedIn(ip_addr, network_addr, network_size)
>>>
>>>can be replaced by
>>>
>>>    nework_addr == (ip_addr & (-1 << network_size))
>>>
>>>which will be true if the IP address is in the network.
>>
>>Is this Java or C?  For C, this breaks if network_size == 32.
> 
> 
>   It breaks for everything except network_size == 16.
> 
>   You want something closer to (ip_addr & (~(~0 << network_size)))
> 
>   Again, that only works for v4.  Part of the beauty of the INET and
>   CIDR types in PostgreSQL is that they take both v4 and v6
>   addresses/networks and all the operations work on both address types
>   automatically.
> 
>    -j
> 
There is nothing to stop you adding a CIDR type to Sqlite by using the 
declared type capability.  You could lift the IP address handling code 
from PostgreSQL if that made it simpler.  Just intercept the CIDR type 
in your wrapper.

You should always appreciate that Sqlite is not a database server, it is 
a kit of tools to implement embedded SQL in any number of ingenious 
ways.  If you want PostgreSQL functionality out of the box why not just 
use PostgreSQL?
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to