Re: [sqlite] How to create a data of unsigned int?

2009-08-07 Thread Simon Slavin

On 7 Aug 2009, at 10:53am, liubin liu 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.

You may find it better just to store an IP number as a string, or as  
four integers.  Although it takes up more space you don't have to keep  
converting from one format to another.

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


Re: [sqlite] How to create a data of unsigned int?

2009-08-07 Thread Pavel Ivanov
SQLite doesn't support unsigned types. And int64 is not too wasting
for you unless you work with negative numbers (which you are not
because you work with unsigned numbers). It's because SQLite always
does compacting of integer numbers - if number fits into 1 byte then
it stores 1 byte, if it fits in 2 bytes then it stores 2 etc. So in
your case it most probably will store 5 bytes which is not too bad.
IIRC, only for negative numbers SQLite always uses 8 bytes.

Pavel

On Fri, Aug 7, 2009 at 9: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


Re: [sqlite] How to create a data of unsigned int?

2009-08-07 Thread liubin liu

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


Re: [sqlite] How to create a data of unsigned int?

2009-08-07 Thread Pavel Ivanov
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


[sqlite] How to create a data of unsigned int?

2009-08-07 Thread liubin liu

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