Re: [sqlite] cidr data type

2008-04-20 Thread John Stanton
What stops you from building in the 128 bit address logic?

Christof Meerwald wrote:
> On Fri, 18 Apr 2008 15:59:14 -0600, Dennis Cote wrote:
> 
>>Christof Meerwald wrote:
>>
>>>Currently, I am thinking of storing start and end IP addresses as a blob in
>>>the database - that way I would be able to use the "between" operator in
>>>selects, e.g.
>>>  select X'c0a81234' between X'c0a8' and X'c0a8';
> 
> [...]
> 
>>I would store the IP addresses, network addresses, and subnet width as 
>>integers. Then create a few custom function to manipulate them.
> 
> 
> Ok, that would work for IPv4 addresses, but if I ever wanted to use IPv6
> addresses, then I would have to go back to using blobs - as integers are
> limited to 64 bits in SQLite.
> 
> 
> Christof
> 

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


Re: [sqlite] multiple writers for in-memory datastore

2008-04-20 Thread James Gregurich

for those who may be interested:

I ran a test with SQLite version: 3.5.8


I tried the scheme described earlier with each thread sharing a  
connection but writing into its own attached in-memory db on that  
connection.   Didn't work. all but the first writer thread failed with  
a SQLITE_ERROR

oh well.

I think I will go with CoreData on MacOSX and figure out something  
else to do on Windows later.


my thanks to all who attempted to provide a solution.


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


Re: [sqlite] how to build sqlite under winxp?

2008-04-20 Thread Dimitri
Hi,

> NO make file found in that zip, downloaded from the official website...

Which exact ZIP file?

-- 
Dimitri

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


Re: [sqlite] multiple writers for in-memory datastore

2008-04-20 Thread Dan

On Apr 20, 2008, at 12:29 AM, James Gregurich wrote:

>
> oh good! That isn't the version that ships with Leopard, but I can
> live with deploying my own version as part of my app.
>
> Will l get the writer parallelism I'm after as long as each thread
> writes exclusively into its own attached db?
>
>
> in other wordstwo bulk insert operations going on simultaneously
> on the same connection but each insert operation going into a
> different attached in-memory db.

Probably not. Each sqlite3* handle has a single mutex that it uses
to serialize operations.

Dan.


>
>
> On Apr 19, 2008, at 9:20 AM, Dan wrote:
>
>>
>> On Apr 19, 2008, at 6:06 AM, James Gregurich wrote:
>>
>>>
>>> I'll ask this question. The answer is probably "no," but I'll ask it
>>> for the sake of completeness.
>>>
>>>
>>> Suppose I created an in-memory db. I use the attach command to
>>> associate an additional in-memory db. Suppose I assign the main  
>>> db to
>>> thread 1 and the associated db to thread 2. Can I share the
>>> connection
>>> across the 2 threads if each thread works exclusively in its own db?
>>>
>>> I am aware that the connection is generally not threadsafe, but will
>>> it work if the two threads don't operate on the same db at the same
>>> time?
>>
>> As of 3.5, sqlite connections are threadsafe by default. With
>> earlier versions, this trick will not work.
>>
>> Dan.
>>
>>
>> ___
>> 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-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] cidr data type

2008-04-20 Thread Florian Weimer
* 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.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] EXISTS operator doesn't seem to work

2008-04-20 Thread pinco palletto
It works now, thanks!

P.P.



> From: [EMAIL PROTECTED]
> To: sqlite-users@sqlite.org
> Date: Sat, 19 Apr 2008 08:43:42 -0400
> Subject: Re: [sqlite] EXISTS operator doesn't seem to work
> 
> 
> On Apr 19, 2008, at 7:06 AM, pinco palletto wrote:
> 
> > update register
> > set note = (select ORT.note from old_register ORT
> > where ORT.person_id = person_id and ORT.document_id = document_id)
> > where exists (
> > select ORT.* from old_register ORT
> > where ORT.person_id = person_id and ORT.document_id = document_id);
> 
> 
> update register
> set note = (select ORT.note from old_register ORT
>  where ORT.person_id = register.person_id
>and ORT.document_id = register.document_id)
>   where exists (select ORT.* from old_register ORT
>  where ORT.person_id = register.person_id
>and ORT.document_id = register. document_id);
> 
> 
> D. Richard Hipp
> [EMAIL PROTECTED]
> 
> 
> 
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

_
Vuoi diventare il numero 1 della community? Scarica il gadget!
http://votalospaces.spaces.live.com/
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] cidr data type

2008-04-20 Thread Jay A. Kreibich
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

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

"'People who live in bamboo houses should not throw pandas.' Jesus said that."
   - "The Ninja", www.AskANinja.com, "Special Delivery 10: Pop!Tech 2006"
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] cidr data type

2008-04-20 Thread John Stanton
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


Re: [sqlite] cidr data type

2008-04-20 Thread Dennis Cote
Florian Weimer wrote:
>
> Is this Java or C?  For C, this breaks if network_size == 32.
>   

It is SQL (with SQLite extensions which are modeled after C).  SQLite 
has a 64 bit integer type so the bit shifting works as expected for all 
values up to 63. The same logic can be used in other languages.

This was intended to work for IPv4 addresses only as shown in the OP 
example. For these addresses the practical range of network width is 
from 2, not really very practical, but a legal minimum subnet width, to 
25, the entire range of a class A network.

Dennis Cote


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


Re: [sqlite] cidr data type

2008-04-20 Thread Dennis Cote
Jay A. Kreibich wrote:
>
>   It breaks for everything except network_size == 16.
>   
Why do you say that?
>   You want something closer to (ip_addr & (~(~0 << network_size)))
>   
In SQLite ~0 is -1.

sqlite> select ~0;
-1

So your inner expression is only a more complicated way of saying the 
same thing.

By complementing the result of the inner expression you have generated 
an invalid netmask pattern with zeros in the high bits and ones in the 
low bit positions. This can' t be used to mask off the network portion 
of an IP adresss. It would return the host address within the network 
which can't be used to test if the original IP address is within a 
particular network.
 
>   Again, that only works for v4.  
>   
It was only intended to work for IPv4 as shown in the OP.

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


Re: [sqlite] multiple writers for in-memory datastore

2008-04-20 Thread Dennis Cote
James Gregurich wrote:
> I think I will go with CoreData on MacOSX and figure out something  
> else to do on Windows later.
>
>
>   
You do know that CoreData uses SQLite for its persistant storage.

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


Re: [sqlite] a suggestion to write tutorial for sqlite

2008-04-20 Thread Toby Roworth
I'm sorry if this reply seems jumbled - I wrote the middle bit (about 
the sugested content) after the bits above and below it.

Jay A. Kreibich wrote:
> On Sat, Apr 19, 2008 at 05:40:45PM +0100, Toby Roworth scratched on the wall:
>   
>> mikeobe wrote:
>> 
>>> i found it boring to learn how to use sqlite, maybe we can write a
>>> tutorial for it, with examples, it will be much easier for the
>>> beginner to start with sqlite.
>>>   
>> Agreed - I had to learn from the 5 minute introduction (which I was 
>> later told was a poor way of doing it), and then by using the reference, 
>> which leaves a lot to be desired when it comes to having little 
>> knowledge of SQLite - and it's still giving me trouble now!
>> 
>
>   What are we looking for?  A 60 minute introduction?
>
>   Any thoughts on specific topics, or is the main thing just
>   covering the basics of the API in vanilla situations?
>   
I think that's exactly what we need - how to run a SQL statement and 
return/print the results.

A brief explanation of:
sqlite3_open_v2()
sqlite3_prepare_v2()
sqlite3_step()
sqlite3_finalize()
sqlite3_close()
and any other important ones
might be nice, in slightly more friendlier terms then the API reference, 
then an example thet puts them toggether.
>   I have a great deal of interest in this area, and would love to hear
>   from anyone that has thoughts, ideas, or comments.  I would
>   especially like to hear if there is a specific area or concept that
>   confused folks when they were learning SQLite.
>   
Ideally, the tutorial would allow someone who has very limited/no 
database knowledge to be able to use SQLite in a simple application, EG 
an address book:
1: Database design (in sqlite3 program?) (creating the table containing 
name, address, telehone)
2: queries to run (finding all people living at an address, finding 
someone's phone number, possible annother)
3: The above bit - run down of frequently used functions
4: putting it all toggether into a C program
5: code listing (could be in 4)

I think something along these lines could work weel, as long as it is 
well written
>   SQLite tends to get used by a lot of people that have a stronger
>   background in software development than in databases, so I would
>   expect there to be some confusion about "database things" like table
>   design and complex query commands.  Solid introductory materials need
>   to take that into account, but we need to gather some more
>   information on precisely what that difference means.
>   
Should a separate SQL/databases introduction be available - this could 
be quite useful, but would it be duplicating what's already available 
elsewhere (see above point)
>
>   This is a bit off-topic for the mailing list, so please feel free
>   to send stuff directly to the address below.
>
>-j
>
>
>   

-- 

Sent by Toby Roworth ([EMAIL PROTECTED])
This message is intended for the named reciepients only, and should not 
be forwarded without permission
The conents of this message may be ©Toby Roworth


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


Re: [sqlite] multiple writers for in-memory datastore

2008-04-20 Thread James Gregurich

yes. However, CoreData queues up modified managed objects in a managed  
object context and then commits them all in one shot making sure the  
serialization is done on the back side.

So, it does basically what someone here recommended earlier. I just  
don't have to write the mechanism myself.


Actually, CoreData is what I intended to use at first. However, I have  
explored the possibility of directly using SQLite instead to keep my  
document readers and their data management cross-platform.

On Apr 20, 2008, at 8:31 AM, Dennis Cote wrote:

> James Gregurich wrote:
>> I think I will go with CoreData on MacOSX and figure out something
>> else to do on Windows later.
>>
>>
>>
> You do know that CoreData uses SQLite for its persistant storage.
>
> Dennis Cote
> ___
> 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] Status of SQLite's full-text search (and Python 2.5 support?)

2008-04-20 Thread python
I'm trying to figure out the status of SQLite's support for full-text
search.

It appears that full-text support was provisionally added to SQLite in
late 2006 via an extension module. It sounds like this early version was
experimental only.

After more googling it appears that there are two add-on modules for
full text search: FTS1 and FTS2.

Is SQLite's full text ready for production use yet?

I'm also wondering where I can find out if the version of SQLite that
ships as part of Python 2.5 includes automatic support for full text
search.

Thank you,
Malcolm
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Status of SQLite's full-text search (and Python 2.5 support?)

2008-04-20 Thread P Kishor
On 4/20/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I'm trying to figure out the status of SQLite's support for full-text
>  search.
>
>  It appears that full-text support was provisionally added to SQLite in
>  late 2006 via an extension module. It sounds like this early version was
>  experimental only.
>
>  After more googling it appears that there are two add-on modules for
>  full text search: FTS1 and FTS2.
>
>  Is SQLite's full text ready for production use yet?

as ready as it will be. FTS 1/2 are deprecated. Use FTS3 that is a
part of the main distro now.


>
>  I'm also wondering where I can find out if the version of SQLite that
>  ships as part of Python 2.5 includes automatic support for full text
>  search.
>
>  Thank you,
>  Malcolm
>  ___
>  sqlite-users mailing list
>  sqlite-users@sqlite.org
>  http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>


-- 
Puneet Kishor http://punkish.eidesis.org/
Nelson Institute for Environmental Studies http://www.nelson.wisc.edu/
Open Source Geospatial Foundation (OSGeo) http://www.osgeo.org/
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Status of SQLite's full-text search (and Python 2.5 support?)

2008-04-20 Thread python
>>  Is SQLite's full text ready for production use yet?

> as ready as it will be. FTS 1/2 are deprecated. 

You don't sound too thrilled :) Are there any limitations that one
should be aware of?

Thank you,

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


Re: [sqlite] Status of SQLite's full-text search (and Python 2.5 support?)

2008-04-20 Thread P Kishor
On 4/20/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >>  Is SQLite's full text ready for production use yet?
>
>  > as ready as it will be. FTS 1/2 are deprecated.
>
>
> You don't sound too thrilled :) Are there any limitations that one
>  should be aware of?

I have no idea how I conveyed that impression. I think FTS3 is really
wonderful, and have implemented it in my own personal website. I
firmly believe in the "Why file when you can full-text search"
doctrine.

The folks ** who developed it are on this list and answer development
related questions pretty responsively. FTS3 works very well for me.

** (afaik, they work for a large company located in the zip code 900913)


>
>
>  Thank you,
>
>  Malcolm
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Status of SQLite's full-text search (and Python 2.5 support?)

2008-04-20 Thread python
P Kishor,

> I have no idea how I conveyed that impression. I think FTS3 is really 
> wonderful, and have implemented it in my own personal website. I firmly 
> believe in the "Why file when you can full-text search" doctrine.

Excellent! Thanks for the follow-up. You answered my questions. And put
my mind at ease.

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


[sqlite] sqlite and NAN

2008-04-20 Thread Justin Greenfield
I'm trying to figure out how to insert and retrieve a NAN value from  
an sqlite database. I'm on Mac OS X 10.5 which is using sqlite3 3.4.0.

Obviously, using the sqlite3 command line tool, this is what I get:

$ sqlite3 nantest.db
SQLite version 3.4.0
Enter ".help" for instructions
sqlite> CREATE TABLE IF NOT EXISTS nantest (x double);
sqlite> INSERT INTO nantest VALUES(123.4);
sqlite> INSERT INTO nantest VALUES(NAN);
SQL error: no such column: NAN

Ok, so maybe it's my lack of knowledge of SQL syntax, but I really  
want to do this from code, so on to a more relevant example.

Here's a sample of my code:

sqlite3* db;
sqlite3_open("nantest.db", );
sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS nantest (x double);",  
0,0,0);
sqlite3_stmt* stmt;
char* nanChars = "INSERT INTO nantest VALUES(?);";
int rc = ::sqlite3_prepare(db, nanChars, -1, , 0);
rc = ::sqlite3_bind_double(stmt, 1, 123.4);
rc = ::sqlite3_step(stmt);
rc = ::sqlite3_reset(stmt);

rc = ::sqlite3_prepare(db, nanChars, -1, , 0);
rc = ::sqlite3_bind_double(stmt, 1, NAN);
rc = ::sqlite3_step(stmt);
rc = ::sqlite3_reset(stmt);

rc = ::sqlite3_prepare(db, "SELECT x FROM nantest;", -1, , 0);

while ((rc = ::sqlite3_step(stmt)) == SQLITE_ROW)
{
double x = ::sqlite3_column_double(stmt, 0);
printf("%5.5f %d\n", x, isnan(x));
}

sqlite3_close(db);


Binding NAN to a statement works fine.  The inserts are successful.   
But what I put in as NAN comes back out as 0.0.

Is there any way to insert a NAN and get a NAN back out of an sqlite  
database?

Thanks,
Justin

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


Re: [sqlite] cidr data type

2008-04-20 Thread Florian Weimer
* Jay A. Kreibich:

>> Is this Java or C?  For C, this breaks if network_size == 32.
>
>   It breaks for everything except network_size == 16.

I was alluding to the fact that a popular architecture implements
modulo-32 shifts for 32-bit integers (and modulo-64 shifts for 64-bit
integers), for example:

sqlite> SELECT 1 << 64;
1
sqlite> 

(I wasn't aware that SQLite supports bitwise operators.)
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Delete inside Select+Step

2008-04-20 Thread Neville Franks
Use the latest SQLite Version can you do:

  select clma from tablea;
  while( sqlite3_step() )
  {
if ( clma == somevalue )
  delete from tablea clma=somevalue;
else
   process row;
  }

ie. Delete a row while stepping through the results of a select and
know the remaining sqlite3_step()'s will work correctly?
  

-- 
Best regards,
  Neville Franks, http://www.surfulater.com http://blog.surfulater.com
 

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


[sqlite] NUMERIC affinity and unwanted conversions

2008-04-20 Thread Aladdin Lampé

Hi!
I've just created my own "DECIMAL" set of user functions using the IBM 
decNumber library.
I would like to assign my decimal columns the type "DECIMAL([precision])", but 
they are given the NUMERIC affinity, and numbers are converted when inserted in 
TEXT format... That's exactly what I'm trying to prevent because this would 
mess the DECIMAL results!
I've thought to name my decimal type "DECIMAL_TEXT([precision])" in order to 
force the TEXT affinity (no conversion) but I'm not very pleased with this 
solution.
Does somebody have a better one? Could somebody point me where to patch SQLite 
in order to avoid that?
Thank you,
Aladdin

_
Découvrez les profils Messenger de vos amis !
http://home.services.spaces.live.com/
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Select TOP n

2008-04-20 Thread James Dodd
Hi,
 
(Newbie to sqlite, some experience with SQL Server 2000). I tried to do a
"SELECT TOP 10 * FROM tab1" and sqlite3 complained. Then I looked at the SQL
syntax page and indeed TOP doesn't seem to be there. Is there a reason for
this and, better still, is there a way to get around it? Or is it there and
I've missed it?
 
TIA,
 
James

No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.524 / Virus Database: 269.23.2/1387 - Release Date: 19/4/2008
11:31
 
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Select TOP n

2008-04-20 Thread David Baird
On Sun, Apr 20, 2008 at 5:07 PM, James Dodd <[EMAIL PROTECTED]> wrote:
> Hi,
>
>  (Newbie to sqlite, some experience with SQL Server 2000). I tried to do a
>  "SELECT TOP 10 * FROM tab1" and sqlite3 complained. Then I looked at the SQL
>  syntax page and indeed TOP doesn't seem to be there. Is there a reason for
>  this and, better still, is there a way to get around it? Or is it there and
>  I've missed it?

Perhaps this?

SELECT * FROM tab1 LIMIT 10;

You might also want to throw in an ORDER BY clause.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] cidr data type

2008-04-20 Thread Jay A. Kreibich
On Sun, Apr 20, 2008 at 09:29:34AM -0600, Dennis Cote scratched on the wall:
> Jay A. Kreibich wrote:
> >
> >  It breaks for everything except network_size == 16.
> >  
> Why do you say that?
> >  You want something closer to (ip_addr & (~(~0 << network_size)))
> >  
> In SQLite ~0 is -1.
> 
>sqlite> select ~0;
>-1
>
> So your inner expression is only a more complicated way of saying the 
> same thing.

  Each is a simple literal with a unary operator.  How is that more complex?

  ~0 is also a bit-level operator that works with both signed and
  unsigned types, while -1 depends on a specific signed integer
  representation.

> By complementing the result of the inner expression you have generated 
> an invalid netmask pattern with zeros in the high bits and ones in the 
> low bit positions. 

  Yeah, I screwed that up.  I was too caught up on the other error.

  In the original function (-1 << network_size) returns the wrong bit
  mask.  For example, 10.0.0.0/8 should return a netmask of 255.0.0.0,
  or 0xFF00.  The original function will return 255.255.255.0,
  which is a /24 mask.

  My mind was thinking "you need to flip that", but did the wrong
  thing.  We're looking for (ip_addr & (~0 << (32 - network_size))).

  Technically, you also need to mask the network side, as it is an
  acceptable notation to have a network like "10.0.0.1/8".

> >  Again, that only works for v4.  
> >  
> It was only intended to work for IPv4 as shown in the OP.

  Clearly, although in a followup to one of your earlier posts the
  original poster said he was interested in both v4 and v6.  It would
  still be easy enough to build functions that can deal with those.



  This thread got me thinking, although not really about IP addresses.
  INET and CIDR are built-in types for Postgres, but part of the reason
  Postgres has so many weird types is that it is very easy to build
  user-defined types in the Postgres engine.  SQLite already allows you
  to put pretty much anything you want in the type field of a CREATE
  TABLE statement.  It also has the most flexible type systems of any
  RDBMS environment that I've worked with.  I'm wondering how hard it
  would be to create a "USER DEFINED TYPE" affinity that could be
  associated with a series of user-functions like "input text"->type,
  or type->"display text."  In many cases, I would assume the "storage
  type" would be a blob, but SQLite's manifest typing means it could be
  just about any native type.  Some other affinity conversion functions and
  collation functions and it might not be that hard to define arbitrary
  user types.  I don't understand the way SQLite tracks values types
  internally enough to really understand the cost... it just got me
  thinking.

  Given some of the unique ways that SQLite is used, there might be
  some value in user types.

   -j

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

"'People who live in bamboo houses should not throw pandas.' Jesus said that."
   - "The Ninja", www.AskANinja.com, "Special Delivery 10: Pop!Tech 2006"
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] NUMERIC affinity and unwanted conversions

2008-04-20 Thread John Stanton
I implemented a DECIMAL type and ended up making a small patch to Sqlite 
to stop it changing the type to numeric.  As I recall it was very simple.

Aladdin Lampé wrote:
> Hi!
> I've just created my own "DECIMAL" set of user functions using the IBM 
> decNumber library.
> I would like to assign my decimal columns the type "DECIMAL([precision])", 
> but they are given the NUMERIC affinity, and numbers are converted when 
> inserted in TEXT format... That's exactly what I'm trying to prevent because 
> this would mess the DECIMAL results!
> I've thought to name my decimal type "DECIMAL_TEXT([precision])" in order to 
> force the TEXT affinity (no conversion) but I'm not very pleased with this 
> solution.
> Does somebody have a better one? Could somebody point me where to patch 
> SQLite in order to avoid that?
> Thank you,
> Aladdin
> 
> _
> Découvrez les profils Messenger de vos amis !
> http://home.services.spaces.live.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] Delete inside Select+Step

2008-04-20 Thread BareFeet
Hi Neville,

> Use the latest SQLite Version can you do:
>
>  select clma from tablea;
>  while( sqlite3_step() )
>  {
>if ( clma == somevalue )
>  delete from tablea clma=somevalue;
>else
>   process row;
>  }
>
> ie. Delete a row while stepping through the results of a select and
> know the remaining sqlite3_step()'s will work correctly?

Is there any reason why you don't simply let SQL do the work for you:

delete from TableA where Clma == somevalue;

then process (the remaining) rows

Tom
BareFeet
http://www.tandb.com.au/sqlite/compare/

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


Re: [sqlite] Delete inside Select+Step

2008-04-20 Thread Neville Franks
Monday, April 21, 2008, 10:44:15 AM, you wrote:

>> I actually need to call a function for each iteration of  
>> sqlite3_step() and depending on what it returns, delete the row or
>> not.

B> Perhaps you could include your function in an example.

Well it is a function that calls various other functions which call
various other functions, none of which know anything about, nor do
anything with the SQLite DB. So I don't see it is relevant.

-- 
Best regards,
  Neville Franks, http://www.surfulater.com http://blog.surfulater.com
 

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