[sqlite] (Lemon) (Patch) adding a -f option to Lemon to emit function prototypes

2013-01-05 Thread Tiago Rodrigues
Hello, all,

First, forgive me if this is the wrong medium for submitting this, but I'm
rather new at this patch submission business.  Anyway, I was using Lemon to
generate a few parsers for a program I'm writing (which uses SQLite, too,
for storage), and I noticed that the files I used to call the parser were
giving me a strange "Pointer made from integer without a cast" on
ParseAlloc(), which is strange, since ParseAlloc() returns a void *.  It
took me a while to figure out that ParseAlloc(), ParseFree() and Parse()
weren't actually declared anywhere, so the compiler was assuming they
received no parameters and returned int.  Since I have more than one parser
to work with, I decided to have lemon emit the function prototypes on the
header file upon a new (-f) flag.  Then I decided that I might as well
submit this back to the community and let it decide whether the inclusion
is useful or not.

This patch works against the current version of lemon.c, as linked to by
the Lemon page.  This is probably not correct, as the file is amalgamated
from other sources, but still might be useful to somebody.

Thanks for reading,

  -Tiago

-- 
In those days, in those distant days, in those nights, in those remote
nights, in those years, in those distant years...
  - Gilgamesh, Enkidu and the Underworld
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Multi thread questions

2013-01-05 Thread Krzysztof
Thanks :)
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Multi thread questions

2013-01-05 Thread Richard Hipp
On Sat, Jan 5, 2013 at 7:14 AM, Krzysztof  wrote:

> Hi,
>
> I'm reading documentation about multi threading. I just want to be sure:
> 1. I can safely create another thread (with new handle / connection) in my
> application and modify SAME database at the same time
>

Yes, as long as you don't take compile-time or run-time actions to make
SQLite single-threaded.  The default is to be multi-threaded.



> 2. I want use second connection in thread for importing while main thread
> working "normally". By import I mean not backup, but importing documents
> (CSV)
>

Yes.


> 3. Can user modify table while another thread importing to it (in
> transaction)? What are restrictions? What should I look out for?
>

Only one thread can be in a write transaction at a time.  If you have two
threads that need to write, they have to take turns.


> 4. Records inserted by second thread will be "visible" for first connection
> after second thread commit transaction?
>

Correct


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



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


Re: [sqlite] Don't passes next tests on FreeBSD: atof1-*

2013-01-05 Thread Richard Hipp
On Sat, Jan 5, 2013 at 1:40 AM, Pavel Volkov  wrote:

> Hello. Excuse me.
> I found the following errors when running tests in the operating
> system FreeBSD x32: (this is an example)
>


Please send the output of the following command:

cpp -dM /dev/null | sort

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


[sqlite] Multi thread questions

2013-01-05 Thread Krzysztof
Hi,

I'm reading documentation about multi threading. I just want to be sure:
1. I can safely create another thread (with new handle / connection) in my
application and modify SAME database at the same time
2. I want use second connection in thread for importing while main thread
working "normally". By import I mean not backup, but importing documents
(CSV)
3. Can user modify table while another thread importing to it (in
transaction)? What are restrictions? What should I look out for?
4. Records inserted by second thread will be "visible" for first connection
after second thread commit transaction?

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


Re: [sqlite] INSERT OR IGNORE - returning new or existing rowid

2013-01-05 Thread BareFeetWare
This kind of question often results in answers along the lines of application 
logic such as: "If the row exists get the ID else create it and then get the 
ID". But the SQL way of doing things is subtly different: "insert a new row 
where it doesn't already exist. Get the ID of the row".

Based on your description, it seems you have a schema something like this:

create table Countries
(   ID integer primary key not null
,   Name text collate nocase
)
;
create table Customers
(   ID integer primary key not null
,   Name text collate nocase
,   Surname text collate nocase
,   ID_Country integer references Countries (ID) on delete restrict on 
update cascade
)
;

And it seems you have a long list of CSV data that could be imported like this:

insert into Countries (Name)
select @Country where @Country not in (select Name from Countries)
;
insert into Customers (Name, Surname, ID_Country)
select @Name, @Surname, (select ID from Countries where Name = @Country)
;

Possibly a faster way to do it is to create a temporary table, import all your 
raw flat data into it, then run a single transaction to import it all into your 
normalised tables. If you imported it into a table called "Import", eg:

create temp table Import (Name, Surname, Country)

then your transaction to insert it into your normalised tables would be:

begin immediate
;
insert into Countries (Name)
select Country from Import where Country not in (select Name from Countries)
;
insert into Customers (Name, Surname, ID_Country)
select Name, Surname, (select ID from Countries where Name = Country)
from Import
;
commit
;

Tom

Tom Brodhurst-Hill
BareFeetWare

--
iPhone/iPad/iPod and Mac software development, specialising in databases
develo...@barefeetware.com
--
Follow us on Twitter: http://twitter.com/barefeetware/
Like us on Facebook: http://www.facebook.com/BareFeetWare


On 04/01/2013, at 11:08 PM, Krzysztof  wrote:

> Ok I have done this with two commnads where first check if record exist. I
> tried do this with one command because I want to speed up importing from
> csv. CSV has one table for example: name | surname | country. I want split
> repeated columns to dictionary tables like:
> 
> table customers
> - name
> - surname
> - id_country // FK to table countries
> 
> I'm looking for one command which before inserting to "customers" will look
> to table countries and check if country exists, if not then insert and
> return id, else return existing id.
> 


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