You probably want to either use sqlite3_bind_int64 to bind the 32-bit
IPv4 address as a positive 32-bit number (this will take between 1 and
5 bytes of space in the variable length integer format), or use
sqlite3_bind_blob and force storing the IP address as a fixed 4 byte
blob (in this case, you'd have to deal with endianness issues, but you
could just define a convention in this case, for example always
storing the IPv4 address as a 4-byte blob in network byte order).

If you use sqlite3_bind_int to bind a 32-bit integer to the statement,
then I believe sqlite would interpret any IP address with a first
octet >127 as a negative number, and therefore use the full 9 bytes of
space needed in the variable length integer format. That's probably
not what you want. Take a look at this for more information on the
variable length integer format:

http://www.sqlite.org/fileformat.html#varint_format

In short, SQLite uses the MSB of each byte in the integer as a continuation bit.

Ben

On Fri, Aug 7, 2009 at 6:11 AM, liubin liu<7101...@sina.com> wrote:
>
> Thanks, :)
>
> But now I think that's ok to use the int type to store the four byte.
> Because I could get the value by using forced conversion.
>
> But Do SQLite3 support the unsigned type?
>
> And You know that int64 is too wasting here.
>
>
>
> Pavel Ivanov-2 wrote:
>>
>> int64 type is okay to store data of type unsigned int. And int64 is
>> exactly the type used for all integers in SQLite.
>>
>> Pavel
>>
>> On Fri, Aug 7, 2009 at 5:53 AM, liubin liu<7101...@sina.com> wrote:
>>>
>>> I want to use a integer to save the ip address of ipv4. Because they all
>>> are
>>> 4 bytes.
>>>
>>> but it is better when the data type is unsigned int.
>>>
>>> How to create a data of unsigned int?
>>> 1334
>>> 1335     // tcp->gate_addr[0]是地址的高8位
>>> 1336     for ( i=0, m=1; i<4; i++, m*=0x100 )
>>> 1337         gateaddr = gateaddr + tcp->gate_addr[3-i] * m;
>>> 1338
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/How-to-create-a-data-of-unsigned-int--tp24861945p24861945.html
>>> Sent from the SQLite mailing list archive at Nabble.com.
>>>
>>> _______________________________________________
>>> sqlite-users mailing list
>>> sqlite-users@sqlite.org
>>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>>>
>> _______________________________________________
>> sqlite-users mailing list
>> sqlite-users@sqlite.org
>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>>
>>
>
> --
> View this message in context: 
> http://www.nabble.com/How-to-create-a-data-of-unsigned-int--tp24861945p24864619.html
> Sent from the SQLite mailing list archive at Nabble.com.
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to