[sqlite] per-context resources for user-defined function

2013-03-11 Thread James K. Lowden
Hello all, 

I'm not sure how to manage the lifetime of ancillary data for a
user-defined function added by sqlite3_create_function ().  

Consider a median() function.  The data are captured on each
xStep, then sorted and the median produced in xFinal.  

Suppose sqlite3_realloc() fails during one xStep.  The 
computation will be invalidated.  Will xStep be called again after it
raises an error?   Will xFinal be called?  If I know xFinal will be
called, ISTM I should raise an error there, too.  That would also
make xFinal a convenient place to reinitalize the data structures.  

Suppose xStep doesn't fail, but another query is executing
simultaneously, also using the median() UDF.  I need one data structure
per context.  I don't see support for that in the SQLite API.  Am I
expected to maintain my own global associative array?  

Many thanks for you guidance.  

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


Re: [sqlite] per-context resources for user-defined function

2013-03-11 Thread Clemens Ladisch
James K. Lowden wrote:
> I'm not sure how to manage the lifetime of ancillary data for a
> user-defined function added by sqlite3_create_function ().
> [...]
> Suppose xStep doesn't fail, but another query is executing
> simultaneously, also using the median() UDF.  I need one data structure
> per context.  I don't see support for that in the SQLite API.

http://www.sqlite.org/c3ref/aggregate_context.html

> Suppose sqlite3_realloc() fails during one xStep.  The
> computation will be invalidated.  Will xStep be called again after it
> raises an error?

xStep does not raise an error.  Set a flag, and return an error in
xFinish.

> Will xFinal be called?

Yes.


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


Re: [sqlite] per-context resources for user-defined function

2013-03-11 Thread kyan
On Mon, Mar 11, 2013 at 12:52 PM, James K. Lowden
 wrote:
> I need one data structure
> per context.  I don't see support for that in the SQLite API.  Am I
> expected to maintain my own global associative array?

Not if you use sqlite3_aggregate_context(). See
http://www.sqlite.org/c3ref/aggregate_context.html

HTH

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


Re: [sqlite] per-context resources for user-defined function

2013-03-11 Thread Ryan Johnson

On 11/03/2013 7:47 AM, Clemens Ladisch wrote:

James K. Lowden wrote:

I'm not sure how to manage the lifetime of ancillary data for a
user-defined function added by sqlite3_create_function ().
[...]
Suppose xStep doesn't fail, but another query is executing
simultaneously, also using the median() UDF.  I need one data structure
per context.  I don't see support for that in the SQLite API.

http://www.sqlite.org/c3ref/aggregate_context.html

Just be careful, because that API doesn't let you resize the allocation...

Ryan

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


Re: [sqlite] TCL Test failures on ARM

2013-03-11 Thread bkk
Any one knows how to fix it  ?



--
View this message in context: 
http://sqlite.1065341.n5.nabble.com/TCL-Test-failures-on-ARM-tp67612p67621.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] per-context resources for user-defined function

2013-03-11 Thread James K. Lowden
On Mon, 11 Mar 2013 12:47:02 +0100
Clemens Ladisch  wrote:

> James K. Lowden wrote:
> > I'm not sure how to manage the lifetime of ancillary data for a
> > user-defined function added by sqlite3_create_function ().
> 
> http://www.sqlite.org/c3ref/aggregate_context.html
> 
> > Will xStep be called again after it raises an error?
> 
> xStep does not raise an error.  Set a flag, and return an error in
> xFinish.

Many thanks, Clemens.  That does the trick nicely.  

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


Re: [sqlite] SQLite 3.7.16 beta

2013-03-11 Thread Richard Hipp
Thanks, everyone, for your help in testing 3.7.16.  A number of problems
have been found and fixed.  Because of these problems, the anticipated
release of 3.7.16 has been delayed until one week from today (2013-03-18).

The draft website, and especially the amalgamation snapshot on the
http://www.sqlite.org/draft/download.html page, has been updated.  Please
continue to test (using the latest snapshot) and let us know as soon as
possible if find any further issues.  Thanks.

On Sat, Mar 2, 2013 at 11:29 AM, Richard Hipp  wrote:

> The anticipated release date for SQLite 3.7.16 is currently 2013-03-12.
> Additional information about the forthcoming 3.7.16 release:
>
>(1)  http://www.sqlite.org/draft/releaselog/3_7_16.html
>(2)  http://www.sqlite.org/draft/download.html
>(3)  http://www.sqlite.org/checklists/3071600
>
> See a summary of changes at (1).  Download a snapshot of the latest code
> (in the form of an amalgamation "sqlite3.c" source file) from (2).  The
> status board at (3) will show the current state of release testing.  When
> the status board goes all green, we will cut the release.  The links above,
> and indeed the entire http://www.sqlite.org/draft/ sub-website, will be
> updated periodically between now and the official release so check back
> frequently.
>
> Please report any problems encountered.
>
> --
> D. Richard Hipp
> d...@sqlite.org




-- 
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] Fuzzy joins

2013-03-11 Thread David Bicking
This is a weird request. I have a table of data with no natural primary key. I 
need to update this table from a prior table, but some of the data fields can 
change over time, so I must be flexible on how I match.

So the matching I need to do is something like this,

if Key1 is unique in both table, then match these records
if Key1||Key2 is unique in both tables, then match these.
if Key1||Key2||Key3 is unique in both tables, then match.
if Key1||Key2||Key3||Key4 is unique in both tables, then match.

The best I can think is to run 4 queries:

UPDATE Table1 Set Value = (Select Value from Table2
                where Key1 = Table1.Key1
                and    Key2 = Table1.Key2
                and    Key3 = Table1.Key3
                and    Key4 = Table1.Key4
                Group By Key1,
                Key2,
                Key3,
                Key4
                Having Count(*)=1);
UPDATE Table1 Set Value = (Select Value from Table2
                where Key1 = Table1.Key1
                and    Key2 = Table1.Key2
                and    Key3 = Table1.Key3
                Group By Key1,
                Key2,
                Key3
                Having Count(*)=1);
UPDATE Table1 Set Value = (Select Value from Table2
                where Key1 = Table1.Key1
                and    Key2 = Table1.Key2
                Group By Key1,
                Key2
                Having Count(*)=1);
UPDATE Table1 Set Value = (Select Value from Table2
                where Key1 = Table1.Key1
                Group By Key1
                Having Count(*)=1);


It doesn't check that the match is unique on the Table1 side, but I think I can 
live with that.

Am I missing an obviously better way to do it? 
A way that can easily be expanded when they come back to me and say if I looked 
at a fifth column, you'd have been able to match it

And if this is something better handled in the application code, can you show 
me some pseudo-code showing what that algorithm would look like? (Application 
will be written in Basic.)

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


Re: [sqlite] SQLite 3.7.16 beta

2013-03-11 Thread Simon Slavin

On 11 Mar 2013, at 3:48pm, Richard Hipp  wrote:

> http://www.sqlite.org/draft/download.html

I'm afraid all I can help with is point out a grammatical problem:

"and templates (2) is used"

I think should have 'templates' in the singular.

I add a note that release 3.7.4 was back in 2010.  Given that the naming 
convention has been in place for 2.5 years it may be time to remove the first 
two sentences from the 'Build Product Names' section.  Or it may not.

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


[sqlite] Windows-Specific 2-c-files Amalgamation?

2013-03-11 Thread Dominique Devienne
I understand the "deployment" ease and performance advantage of the
amalgamation. I like it.

Except I can't debug it... 'Cause I'm primarily on Windows, which has a
well-known limitation in the way it stores Debug Information (uses 16-bit
integer for the line number, so limited to ~64K lines, whereas the
amalgamation is much larger).

Could there be another amalgamation, perhaps Windows specific, that spreads
the sole .c file into 2 or 3?

I'm sure it's work, and perhaps even requires another "private" header to
share non-public data structures between the two or more C files, but given
SQLite's clean architecture and layers (Pager, VDBE, etc...), I'm assuming
it's at least "possible", no? Might even not loose much of that little
performance advantage the amalgamation brings???

I for one would be able to dive deeper into the code, without resorting to
the not-recommended full build (which is more Linux than Windows friendly)

I don't have much hope for this (any more than MS fixing its
tool-chain...), but I thought I might as well ask ;). Perhaps someone knows
a trick or two to work-around that MS debugging issue?

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


Re: [sqlite] Windows-Specific 2-c-files Amalgamation?

2013-03-11 Thread Richard Hipp
On Mon, Mar 11, 2013 at 12:17 PM, Dominique Devienne wrote:

>  Perhaps someone knows
> a trick or two to work-around that MS debugging issue?
>

Run:  "make sqlite3-all.c" to build an amalgamation composed of smaller
files.

See the http://www.sqlite.org/draft/download.html for a "32K" amalgamation
of the latest 3.7.16 beta.


-- 
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] Windows-Specific 2-c-files Amalgamation?

2013-03-11 Thread Michael Black
Richard...he split is missing the 5 split files. I thought the small size
was suspicious.

-Original Message-
From: sqlite-users-boun...@sqlite.org
[mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Richard Hipp
Sent: Monday, March 11, 2013 11:42 AM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] Windows-Specific 2-c-files Amalgamation?

On Mon, Mar 11, 2013 at 12:17 PM, Dominique Devienne
wrote:

>  Perhaps someone knows
> a trick or two to work-around that MS debugging issue?
>

Run:  "make sqlite3-all.c" to build an amalgamation composed of smaller
files.

See the http://www.sqlite.org/draft/download.html for a "32K" amalgamation
of the latest 3.7.16 beta.


-- 
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-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Windows-Specific 2-c-files Amalgamation?

2013-03-11 Thread Richard Hipp
On Mon, Mar 11, 2013 at 1:33 PM, Michael Black  wrote:

> Richard...he split is missing the 5 split files. I thought the small size
> was suspicious.
>

Fixed.

-- 
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] Windows-Specific 2-c-files Amalgamation?

2013-03-11 Thread Michael Black
Can't you just wait to fix things until "patch Tuesday"??? :-)
Sheesh...we can't handle things this quickly...

-Original Message-
From: sqlite-users-boun...@sqlite.org
[mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Richard Hipp
Sent: Monday, March 11, 2013 12:37 PM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] Windows-Specific 2-c-files Amalgamation?

On Mon, Mar 11, 2013 at 1:33 PM, Michael Black  wrote:

> Richard...he split is missing the 5 split files. I thought the small size
> was suspicious.
>

Fixed.

-- 
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-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Changed behavior in SQLite 3.7.16 beta

2013-03-11 Thread Peter Aronson
OK, downloaded and built from this and the problem went away, including the 
more 
complex case the submitted case was cut down from.  We'll run our autotests 
again and see if anything else pops up.  Thanks for all the hard work!

Peter

- Original Message 
> From: Richard Hipp 
> To: General Discussion of SQLite Database 
> Sent: Sat, March 9, 2013 7:58:27 AM
> Subject: Re: [sqlite] Changed behavior in SQLite 3.7.16 beta
> 
> Please try again with the latest 3.7.16 beta.  You can download an
> amalgamation snapshot from http://www.sqlite.org/test/download.html
> 
> The testing checklist (http://www.sqlite.org/checklists/3071600) has been
> restarted once again on account of this issue.
> 
> On Thu, Mar 7, 2013 at 7:07 PM, Peter Aronson  wrote:
> 
> > I've encountered the following changed behavior (which I believe is a
> > bug).  The
> > following script works at 3.7.15.2 but fails at 3.6.16 beta:
> >
> > create table qa_data_edit (str_col text,int_col integer,rowidcol integer);
> > insert into qa_data_edit values ('this',1000,1);
> > insert into qa_data_edit values ('that',3000,2);
> > create view qa_data_edit_evw as select str_col,int_col,rowidcol from
> > qa_data_edit;
> >
> > create trigger qa_data_edit_view_update instead of update on
> > qa_data_edit_evw
> > BEGIN
> >  update or replace qa_data_edit
> >  set str_col = new.str_col,
> >      int_col = new.int_col
> >  where rowidcol = old.rowidcol;
> > END;
> > select * from qa_data_edit;
> > update main.qa_data_edit_evw
> > set str_col = 'fred',
> >    int_col = 5000
> > where main.qa_data_edit_evw.rowidcol = 1;
> > select * from qa_data_edit;
> >
> > Output:
> >
> > SQLite version 3.7.16 2013-03-06 01:55:27
> > Enter ".help" for instructions
> > Enter SQL statements terminated with a ";"
> > sqlite> .read test.sql
> > this|1000|1
> > that|3000|2
> > Error: near line 17: no such column: main.qa_data_edit_evw.rowidcol
> > this|1000|1
> > that|3000|2
> >
> > SQLite version 3.7.15.2 2013-01-09 11:53:05
> > Enter ".help" for instructions
> > Enter SQL statements terminated with a ";"
> > sqlite> .read test.sql
> > this|1000|1
> > that|3000|2
> > fred|5000|1
> > that|3000|2
> >
> > Using an unqualified ROWIDCOL in the update causes the error to go away.
> > However, database.table.column is a legal expression element according the
> > the
> > syntax diagrams.
> >
> > Tested on Windows XP and Solaris 9.
> >
> > Peter
> > ___
> > 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
> 
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] SQLite 3.7.16 beta

2013-03-11 Thread Kevin Benson
On Mon, Mar 11, 2013 at 11:48 AM, Richard Hipp  wrote:

>
>
> On Sat, Mar 2, 2013 at 11:29 AM, Richard Hipp  wrote:
> >
> > Please report any problems encountered.
> >
> > --
> > D. Richard Hipp
> > d...@sqlite.org


Some lunchtime reading resulted in this minutiae:

http://www.sqlite.org/draft/atomiccommit.html

S//from the one describe in this article//from the one described in this
article//

S//if a power lose or OS crash occurs//if a power loss or OS crash occurs//

S//This would make it appears as if//This would make it appear as if//

S//The idea behind a reserved locks is//The idea behind a reserved lock is//

S//takes up most the time required//takes up most of the time required//

S//described later make it appears as if//described later make it appear as
if//

S//The rollback journal exist.//The rollback journal exists.//

S//write that content back to were it//write that content back to where it//

S//where deleting a file is expense.//where deleting a file is expensive.//

S//journal is no long hot after this step.//journal is no longer hot after
this step.//

S//prevents other processes for accessing//prevents other processes from
accessing//

S//device manufactures with more control//device manufacturers with more
control//

S//during step 3.10 above//during step 3.10
above//

S//in step 3.7 is//in step 3.7 is//

S//in section 3.2 above//in section 3.2 above//

S//at step 4.2//at step
4.2


CHEERS
--
   --
  --
 --Ô¿Ô--
K e V i N
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Fuzzy joins

2013-03-11 Thread Petite Abeille

On Mar 11, 2013, at 4:54 PM, David Bicking  wrote:

> Am I missing an obviously better way to do it? 
> A way that can easily be expanded when they come back to me and say if I 
> looked at a fifth column, you'd have been able to match it….

As they stand, your updates will always match whatever was computed last as you 
don't have a where clause in your update statements. Most likely not what you 
want.

If only SQLite had a merge statement, this would all be much easier.

Anyhow, personally, I would decompose the problem into two steps: 


(1) How to join Table1 to Table2 considering these various keys.
(2) How to update Table2 with Table2's value given (1)


For (1), you have two main options: (a) keys concatenation  or (b) a series of 
left joins 


(warning: pseudo code ahead)


(a)

selectTable1.row_id as t1_row_id,
  Table2.value
from  (
select  rowid as row_id,
key1 || '.' || key2 || '.' || key3 || '.' || key4 || '.' || 
key5 as key
fromTable1
  )
asTable1

left join (
select  rowid as row_id,
key1 || '.' || key2 || '.' || key3 || '.' || key4 || '.' || 
key5 as key,
value
fromTable2
  )
asTable2
onTable2.key = Table1.key

The above will always result in two full table scan.


(b) 

selectTable1.rowid as t1_row_id,
  coalesce( Level5.value, Level4.value, Level3.value, Level2.value, 
Level1.value ) as value
from  Table1

left join Table2
asLevel5
onLevel5.key1 = Table1.key1
and   Level5.key2 = Table1.key2
and   Level5.key3 = Table1.key3
and   Level5.key4 = Table1.key4
and   Level5.key5 = Table1.key5

left join Table2
asLevel4
onLevel4.key1 = Table1.key1
and   Level4.key2 = Table1.key2
and   Level4.key3 = Table1.key3
and   Level4.key4 = Table1.key4
and   Level5.key1 is null

left join Table2
asLevel3
onLevel3.key1 = Table1.key1
and   Level3.key2 = Table1.key2
and   Level3.key3 = Table1.key3
and   Level4.key1 is null

left join Table2
asLevel4
onLevel4.key1 = Table1.key1
and   Level4.key2 = Table1.key2
and   Level3.key1 is null

left join Table2
asLevel5
onLevel5.key1 = Table1.key1
and   Level4.key1 is null


While the second option looks more verbose, it may be more appropriate if 
Table2 is small in relation to Table1, and Table1 can be pruned by key1 at the 
very least.


(2) Once you have the data joined, the update itself is much more 
straightforward. Wrap one of the select as a 'create temporary table t2t as' 
and use that in the update statement:

update  Table1
set value = ( select value from t2t where t2t.row_id = Table1.rowid )

where   exists
(
  select  1
  fromt2t
  where   t2t.row_id = Table1.rowid
)


As always, YMMV.



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


Re: [sqlite] Fuzzy joins

2013-03-11 Thread David Bicking
Ouch, I certainly did forget the where clauses!

Table1 and Table2 are going to be roughly the same size.
What I am trying to do, btw, is to take an extract from a prior period, which 
has had the "Value" added to it, and move that value in to the matching record 
in the new extract. There is a natural key in the table that is being 
extracted, but the columns that make up that natural key are not exposed to us 
mere mortals. Of the fields I have to play with, only key1 is actually part of 
the natural key in the source table. The others are fields which could be 
freely changed from one month to another. The higher the key number, the most 
likely it is to be changed from one month to another.

In your selects below, lets say we have two records in table2 which have 
exactly the same keys as a record in Table1, won't the select then spit out two 
values in the select? Or am I missing how that case is excluded?

And should I take it the two last Left joins should have been Level2 and 
Level1, and not repeat the use of Level4 and Level5?

And your option (a) is only one of 5 selects, each having one less key?


For (b), lets say:

Table1
Rowid|Key1 | Key2 | Key3 | Key4 | Key5
1 1  2 3 4 5

Table2
Rowid|Key1 | Key2 | Key3 | Key4 | Key5|Value
11    1 2 3 4 5 x

12        1     2 3 4   -5  y

Just  looking at levels 4 and 5 wouldn't the results be...

Table1.Rowid |   Level5.Rowid  | Level4.Rowid |  Value

1 11    12                        x    
(from level 5)1 null    11              
         y    (from level 4)
1 null    12   y    
(from level 4)


Or am I mis-interpreting what you wrote?

Um, I am wrong, cause I just tried it and sqlite only returns the level 5 
result. I have no clue why!

David



 From: Petite Abeille 
To: General Discussion of SQLite Database  
Sent: Monday, March 11, 2013 3:24 PM
Subject: Re: [sqlite] Fuzzy joins
 

On Mar 11, 2013, at 4:54 PM, David Bicking  wrote:

> Am I missing an obviously better way to do it? 
> A way that can easily be expanded when they come back to me and say if I 
> looked at a fifth column, you'd have been able to match it….

As they stand, your updates will always match whatever was computed last as you 
don't have a where clause in your update statements. Most likely not what you 
want.

If only SQLite had a merge statement, this would all be much easier.

Anyhow, personally, I would decompose the problem into two steps: 


(1) How to join Table1 to Table2 considering these various keys.
(2) How to update Table2 with Table2's value given (1)


For (1), you have two main options: (a) keys concatenation  or (b) a series of 
left joins 


(warning: pseudo code ahead)


(a)

select    Table1.row_id as t1_row_id,
          Table2.value
from      (
            select  rowid as row_id,
                    key1 || '.' || key2 || '.' || key3 || '.' || key4 || '.' || 
key5 as key
            from    Table1
          )
as        Table1

left join (
            select  rowid as row_id,
                    key1 || '.' || key2 || '.' || key3 || '.' || key4 || '.' || 
key5 as key,
                    value
            from    Table2
          )
as        Table2
on        Table2.key = Table1.key

The above will always result in two full table scan.


(b) 

select    Table1.rowid as t1_row_id,
          coalesce( Level5.value, Level4.value, Level3.value, Level2.value, 
Level1.value ) as value
from      Table1

left join Table2
as        Level5
on        Level5.key1 = Table1.key1
and       Level5.key2 = Table1.key2
and       Level5.key3 = Table1.key3
and       Level5.key4 = Table1.key4
and       Level5.key5 = Table1.key5

left join Table2
as        Level4
on        Level4.key1 = Table1.key1
and       Level4.key2 = Table1.key2
and       Level4.key3 = Table1.key3
and       Level4.key4 = Table1.key4
and       Level5.key1 is null

left join Table2
as        Level3
on        Level3.key1 = Table1.key1
and       Level3.key2 = Table1.key2
and       Level3.key3 = Table1.key3
and       Level4.key1 is null

left join Table2
as        Level4
on        Level4.key1 = Table1.key1
and       Level4.key2 = Table1.key2
and       Level3.key1 is null

left join Table2
as        Level5
on        Level5.key1 = Table1.key1
and       Level4.key1 is null


While the second option looks more verbose, it may be more appropriate if 
Table2 is small in relation to Table1, and Table1 can be pruned by key1 at the 
very least.


(2) Once you have the data joined, the update itself is much more 
straightforward. Wrap one of the select as a 'create temporary table t2t as' 
and use that in the update statement:

update  Table1
set     value = ( select value from t2t where t2t.row_id = Table1.rowid )

where   exists
        (

Re: [sqlite] Fuzzy joins

2013-03-11 Thread Petite Abeille

On Mar 11, 2013, at 10:32 PM, David Bicking  wrote:

> Um, I am wrong, cause I just tried it and sqlite only returns the level 5 
> result. I have no clue why!

The joins are setup from most specific to broadest. Each join is evaluated only 
if the previous one returns null (i.e. all these 'and PreviousLevel.Key is 
null').

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


Re: [sqlite] Fuzzy joins

2013-03-11 Thread David Bicking
Yeah, one benefit of a long commute is that I could puzzle it out and 
understand why it works.

select t1.*,
(
 select v from t2 where t2.k1=t1.k1 and t2.k2=t1.k2 and t2.k3=t1.k3 and 
t2.k4=t1.k4 and t2.k5=t1.k5
 group by k1,k2,k3,k4,k5
 having count(*)=1
 union
 select v from t2 where t2.k1=t1.k1 and t2.k2=t1.k2 and t2.k3=t1.k3 and 
t2.k4=t1.k4
 group by k1,k2,k3,k4
 having count(*)=1
 union
 select v from t2 where t2.k1=t1.k1 and t2.k2=t1.k2 and t2.k3=t1.k3
 group by k1,k2,k3
 having count(*)=1
 union
 select v from t2 where t2.k1=t1.k1 and t2.k2=t1.k2
 group by k1,k2
 having count(*)=1
 union
 select v from t2 where t2.k1=t1.k1
 group by k1
 having count(*)=1
)
from t1;

I haven't fully tested it, but it looks like this does almost what I want. 
Ideally if something is duplicated in t1, but is unique in t2, this will match 
the t2 record to both records in t1, and it shouldn't.

But I am really close now.

David




 From: Petite Abeille 
To: General Discussion of SQLite Database  
Sent: Monday, March 11, 2013 5:45 PM
Subject: Re: [sqlite] Fuzzy joins
 

On Mar 11, 2013, at 10:32 PM, David Bicking  wrote:

> Um, I am wrong, cause I just tried it and sqlite only returns the level 5 
> result. I have no clue why!

The joins are setup from most specific to broadest. Each join is evaluated only 
if the previous one returns null (i.e. all these 'and PreviousLevel.Key is 
null').

___
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] TCL Test failures on ARM

2013-03-11 Thread bkk
Has anyone came across same problem ? Appreciate if someone can point out
what’s going wrong with these tests 



--
View this message in context: 
http://sqlite.1065341.n5.nabble.com/TCL-Test-failures-on-ARM-tp67612p67637.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] TCL Test failures on ARM

2013-03-11 Thread Dan Kennedy

On 03/12/2013 10:48 AM, bkk wrote:

Has anyone came across same problem ? Appreciate if someone can point out
what’s going wrong with these tests


Is there something odd about trying to write to errno on this
platform? These tests depend on function tsIsFailErrno() in
file test_syscall.c being able to assign a value to errno.

Are you able to check with a debugger (or otherwise) if that
is actually working?

Dan.


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