[sqlite] How to bind a tinyint so that actually uses 1 byte?

2008-10-24 Thread dbikash

Hi,

I am using tinyint in my schema, but while doing paramterized insertion, I
find that there is no specific bind API to insert a tinyint. So I used int
sqlite3_bind_int() instead.

However, the size of my database suggests that SQLite might actually be
using 4 bytes instead of 1. Is it? How can I insert tinyint's in a
parameterized query so that it takes only 1 byte of space?

Thanks,
dbikash
-- 
View this message in context: 
http://www.nabble.com/How-to-bind-a-tinyint-so-that-actually-uses-1-byte--tp20147265p20147265.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 bind a tinyint so that actually uses 1 byte?

2008-10-24 Thread Cory Nelson
On Fri, Oct 24, 2008 at 2:49 AM, dbikash [EMAIL PROTECTED] wrote:

 Hi,

 I am using tinyint in my schema, but while doing paramterized insertion, I
 find that there is no specific bind API to insert a tinyint. So I used int
 sqlite3_bind_int() instead.

 However, the size of my database suggests that SQLite might actually be
 using 4 bytes instead of 1. Is it? How can I insert tinyint's in a
 parameterized query so that it takes only 1 byte of space?


sqlite only has a single integer type - there is no tinyint.  sqlite
stores integers in a variable-length encoding.  1 byte stores 7 bits,
2 stores 14 bits, etc.  9 bytes maximum.

-- 
Cory Nelson
http://www.int64.org
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] How to bind a tinyint so that actually uses 1 byte?

2008-10-24 Thread Jay A. Kreibich
On Fri, Oct 24, 2008 at 02:49:14AM -0700, dbikash scratched on the wall:
 
 Hi,
 
 I am using tinyint in my schema, but while doing paramterized insertion, I
 find that there is no specific bind API to insert a tinyint. So I used int
 sqlite3_bind_int() instead.
 
 However, the size of my database suggests that SQLite might actually be
 using 4 bytes instead of 1. Is it? How can I insert tinyint's in a
 parameterized query so that it takes only 1 byte of space?

  As with strings, SQLite automatically adjusts the size of the
  stored integer to match the magnitude of the value.  All integers
  are signed, and SQLite supports sizes of 1-4, 6, or 8 bytes.

  As long as your values are within the range of -128 to +127, your
  integers will only take one byte of storage (plus common overhead).
 
-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] How to bind a tinyint so that actually uses 1 byte?

2008-10-24 Thread [EMAIL PROTECTED]



   As long as your values are within the range of -128 to +127, your
   integers will only take one byte of storage (plus common overhead).
 

There's an extra byte of meta data for each column value in each
row due to manifest typing, so an int will take at least 2 bytes 
of storage per column per row.

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

The exceptions are the special values 0 and 1 when using 

  pragma legacy_file_format=0;

then only 1 byte is required to store these values.


-- 
View this message in context: 
http://www.nabble.com/How-to-bind-a-tinyint-so-that-actually-uses-1-byte--tp20147265p20152977.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