[sqlite] autoincrement and fts2?

2007-07-16 Thread Adam Megacz

Is there any way to use a INTEGER PRIMARY KEY AUTOINCREMENT on a table
that has FTS2?  Specifying it in the obvious manner looks like it
works, but the column just ends up with nulls in it.

  - a

-- 
PGP/GPG: 5C9F F366 C9CF 2145 E770  B1B8 EFB1 462D A146 C380

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] UPDATE during SELECT

2007-07-16 Thread Larry Lewis
If I am stepping through the results of a SELECT and want to UPDATE values in 
the currently selected row prior to completion of the SELECT query, will this 
work?

What if there is already a pending writer lock on the database from a different 
thread?

Thanks.
Larry



-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] sqlite3

2007-07-16 Thread Uma Krishnan
How about the various implementations to use SQLite in client server 
environment (based on wiki):

http://www.it77.de/sqlite/sqlite.htm
http://www.oneledger.co.uk/sql4sockets.html
http://users.iol.it/irwin/
http://sqlitedbms.sourceforge.net/

Does anyone have any experience any of these? Pros and cons?

Thanks

Uma




[EMAIL PROTECTED] wrote: Huber Privat  wrote:
> Guten Tag
> 
> Ich arbeite mit SQLite3 über ein Netzwerk.
> 
> Wenn 2 User zur gleichen Zeit arbeiten wird der
> Zugriff auf die SQLite3-Datenbank sehr langsam.
> 
> Was mache ich falsch.
> Bitte um Hilfe.
> 

SQLite tends to not work well on a network filesystem.
This is because network filesystems are themselves
slow.  This is especially true when you have multiple
processes attempting to access the database at the
same time.  A lot of traffic has to go back and
forth across the network in order to negotiate the
approriate locks.

If you have multiple clients access a single database
over a network, you are probably better off using a
client/server database engine.

--
D. Richard Hipp 


-
To unsubscribe, send email to [EMAIL PROTECTED]
-




[sqlite] Profiler/Monitor/Timer for SQLite

2007-07-16 Thread bash
 Hello all,
Im interesting in application that can profile/monitor/time SQLite
engines. Could you suggest some names/urls for me.
Thanks.

-- 
Biomechanical Artificial Sabotage Humanoid

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



RE: [sqlite] Does Transaction object roll back automatically on exceptions?

2007-07-16 Thread Ahmed Sulaiman
Hi all,

Is it necessary to run a "SELECT" command in between a transaction?  I
have few places in my code where I have a command that reads some data
from a table, and I wonder if I should begin/commit a transaction? Is
there any performance issues if I did or didn't do that?

Regards


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



RE: [sqlite] Does Transaction object roll back automatically on exceptions?

2007-07-16 Thread Robert Simpson
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> Sent: Monday, July 16, 2007 9:14 AM
> To: sqlite-users@sqlite.org
> Subject: Re: [sqlite] Does Transaction object roll back 
> automatically on exceptions?
> 
> "Ahmed Sulaiman" <[EMAIL PROTECTED]> wrote:
> > Hi all,
> > 
> > I have tried this question in the forum with no answer, so 
> I decide to
> > give it a try here :)
> > 
> > I am using the "Using" statements in C# to handle the 
> closing of SQLite
> > connection, transaction and command objects.  I have this setup in
> > different places in my code (Generic methods returning 
> SQLite objects)
> >   
> > using (IDbConnection conn = CreateConnection())
> >  {
> >conn.Open();
> >using (IDbTransaction transaction = conn.BeginTransaction())
> > {
> > Dosomething();
> > transaction.Commit();
> > }  
> >} 
> > 
> > My question, what happens if there was an exception inside the
> > transaction using block? I know that the transaction object would be
> > closed and disposed, but does the traction roll back 
> automatically by
> > the SQLite engine, or do I need to have special logic for 
> that? What is
> > the suggested best practices in this case?
> >  
> 
> In the equivalent code in TCL, the transaction would
> rollback automatically.  But I do not know anything
> about the C# bindings that you are using, so I do not
> know what will happen in your case.  Have you tried it
> to see?  What does the documentation that comes with
> your SQLite C# bindings say?  It is the C# bindings,
> not the SQLite core, that will determine this behavior.

Answered on the SQLite.NET forums.  The ADO.NET wrapper automatically roll
back as well.

Robert



-
To unsubscribe, send email to [EMAIL PROTECTED]
-



RE: [sqlite] Does Transaction object roll back automatically on exceptions?

2007-07-16 Thread Ahmed Sulaiman
Thanks for the reply.  I have got the code for the binding and it
actually does roll back automatically in case of exceptions. :)

Ahmed

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 16, 2007 12:14 PM
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] Does Transaction object roll back automatically on
exceptions?

"Ahmed Sulaiman" <[EMAIL PROTECTED]> wrote:
> Hi all,
> 
> I have tried this question in the forum with no answer, so I decide to
> give it a try here :)
> 
> I am using the "Using" statements in C# to handle the closing of
SQLite
> connection, transaction and command objects.  I have this setup in
> different places in my code (Generic methods returning SQLite objects)
>   
> using (IDbConnection conn = CreateConnection())
>  {
>conn.Open();
>using (IDbTransaction transaction = conn.BeginTransaction())
> {
> Dosomething();
> transaction.Commit();
> }  
>} 
> 
> My question, what happens if there was an exception inside the
> transaction using block? I know that the transaction object would be
> closed and disposed, but does the traction roll back automatically by
> the SQLite engine, or do I need to have special logic for that? What
is
> the suggested best practices in this case?
>  

In the equivalent code in TCL, the transaction would
rollback automatically.  But I do not know anything
about the C# bindings that you are using, so I do not
know what will happen in your case.  Have you tried it
to see?  What does the documentation that comes with
your SQLite C# bindings say?  It is the C# bindings,
not the SQLite core, that will determine this behavior.

--
D. Richard Hipp <[EMAIL PROTECTED]>



-
To unsubscribe, send email to [EMAIL PROTECTED]

-




-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] Inconsistent PRAGMA locking_mode command output

2007-07-16 Thread Ken
Why does the command:
 Pragma locking_mode = EXCLUSIVE;
 
 generate output of "exclusive"
 
 where other pragmas such as 
 Pragma synchrous = off; 
 
 do not generate any output whatsoever? 
 
 
 Thanks,
 Ken
 
 
 



RE: [sqlite] Does Transaction object roll back automatically on exceptions?

2007-07-16 Thread Samuel R. Neff

Rollback is automatic if no Commit is issued in SQLite.NET.

If you want custom logic, such as including additional exception
information, then use try/catch

BeginTransaction();
try {
  ..
  Commit();
} catch(Exception ex) {
  RollBack();
  throw new Exception("An exception occurred and the transaction has been
rolled back.", ex);
}


HTH,

Sam


---
We're Hiring! Seeking a passionate developer to join our team building
products. Position is in the Washington D.C. metro area. If interested
contact [EMAIL PROTECTED]
 
-Original Message-
From: Ahmed Sulaiman [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 16, 2007 10:52 AM
To: sqlite-users@sqlite.org
Subject: [sqlite] Does Transaction object roll back automatically on
exceptions?

Hi all,

I have tried this question in the forum with no answer, so I decide to
give it a try here :)

I am using the "Using" statements in C# to handle the closing of SQLite
connection, transaction and command objects.  I have this setup in
different places in my code (Generic methods returning SQLite objects)
  
using (IDbConnection conn = CreateConnection())
 {
   conn.Open();
   using (IDbTransaction transaction = conn.BeginTransaction())
{
Dosomething();
transaction.Commit();
}  
   } 

My question, what happens if there was an exception inside the
transaction using block? I know that the transaction object would be
closed and disposed, but does the traction roll back automatically by
the SQLite engine, or do I need to have special logic for that? What is
the suggested best practices in this case?
 
Cheers


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] Re: Re: inner join

2007-07-16 Thread bartsmissaert
Thanks for that.
I looked there, but overlooked it.

RBS


> RB Smissaert <[EMAIL PROTECTED]>
> wrote:
>> Where could I find documentation about coalesce?
>
> http://sqlite.org/lang_expr.html
>
> Near the bottom where all the built-in functions are described.
>
> Igor Tandetnik
>
> -
> To unsubscribe, send email to [EMAIL PROTECTED]
> -
>
>
>




-
To unsubscribe, send email to [EMAIL PROTECTED]
-



RE: [sqlite] Re: inner join

2007-07-16 Thread Joe Wilson
Let's assume we're using this schema:

 CREATE TABLE A(Id INTEGER PRIMARY KEY, Field1, Flag);
 CREATE TABLE B(Id INTEGER PRIMARY KEY, Field_Temp, Price);
 CREATE INDEX B2 on B(Field_Temp, Price);
 CREATE INDEX A1 on A(Field1, Id);

You can extend Igor's pattern for more than 1 column:

 explain query plan
 update A set Flag = coalesce(
(select 'DONE' from B
 where A.Field1 = B.Field_Temp and B.Price > 0),
Flag),
  Id = coalesce(
(select Id from B
 where A.Field1 = B.Field_Temp and B.Price > 0),
Id);

  0|0|TABLE A
  0|0|TABLE B WITH INDEX B2
  0|0|TABLE B WITH INDEX B2

When more than a few columns are being modified it is simpler and
more efficient to use REPLACE INTO:

 -- adjust the columns in the select to match the order of
 -- the columns in the table to be updated
 explain query plan
 replace into A 
   select B.Id, A.Field1, 'DONE' 
   from A, B 
   where A.Field1 = B.Field_Temp 
   and B.Price > 0;

 0|0|TABLE A
 1|1|TABLE B WITH INDEX B2

--- Andre du Plessis <[EMAIL PROTECTED]> wrote:

> The Id piece works great thanks! If I want to update 2 fields on table
> A, the following syntax doesn't work as expected, as it updates all to
> records to 'DONE'.
>  
> update A set Flag = 'DONE',
> Id = coalesce(
> (select Id from B
>  where A.Field1 = B.Field_Temp and B.Price > 0),
> Id);
> 
> -Original Message-
> From: Andre du Plessis 
> Sent: 16 July 2007 02:30 PM
> To: Gavin McGuinness
> Subject: FW: [sqlite] Re: inner join
> 
> Here you go
> It was answered by the mighty Igor, he's like THEE guru, guru's turn to
> him for help, so don't question just follow :)
> 
> -Original Message-
> From: Igor Tandetnik [mailto:[EMAIL PROTECTED] 
> Sent: 16 July 2007 01:49 PM
> To: SQLite
> Subject: [sqlite] Re: inner join
> 
> Andre du Plessis <[EMAIL PROTECTED]> wrote:
> > I would like to be able to accomplish the following but don't see any
> > support for inner joins on update queries.
> > 
> > update A
> > set Id = B.Id
> > from A inner join B
> > on A.Field1 = B.Field_Temp
> > where B.Price > 0
> 
> update A set Id = coalesce(
> (select Id from B
>  where A.Field1 = B.Field_Temp and B.Price > 0),
> Id);
> 
> Igor Tandetnik
> 
> 
> -
> To unsubscribe, send email to [EMAIL PROTECTED]
> 
> -
> 
> 
> -
> To unsubscribe, send email to [EMAIL PROTECTED]
> -
> 
> 



 

Now that's room service!  Choose from over 150,000 hotels
in 45,000 destinations on Yahoo! Travel to find your fit.
http://farechase.yahoo.com/promo-generic-14795097

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] Re: Can ORDER-BY perform Case-Insensitive comparison?

2007-07-16 Thread Igor Tandetnik

Bharath Booshan L
<[EMAIL PROTECTED]> wrote: 

Consider following query

SELECT  Name
FROM People
ORDER BY Name ASC;

will result as

Rajesh
Rakesh
raj
ramesh

But where as I need the output to be sorted alphabetically
irrespective of 
its CASE as shown below.


ORDER BY Name COLLATE NOCASE ASC

Igor Tandetnik

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] Re: Re: inner join

2007-07-16 Thread Igor Tandetnik

Andre du Plessis <[EMAIL PROTECTED]> wrote:

The Id piece works great thanks! If I want to update 2 fields on table
A, the following syntax doesn't work as expected, as it updates all to
records to 'DONE'.

update A set Flag = 'DONE',
Id = coalesce(
(select Id from B
 where A.Field1 = B.Field_Temp and B.Price > 0),
Id);


Of course. What do you want it to do? What exactly are you trying to 
achieve?


Igor Tandetnik 



-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] Does Transaction object roll back automatically on exceptions?

2007-07-16 Thread drh
"Ahmed Sulaiman" <[EMAIL PROTECTED]> wrote:
> Hi all,
> 
> I have tried this question in the forum with no answer, so I decide to
> give it a try here :)
> 
> I am using the "Using" statements in C# to handle the closing of SQLite
> connection, transaction and command objects.  I have this setup in
> different places in my code (Generic methods returning SQLite objects)
>   
> using (IDbConnection conn = CreateConnection())
>  {
>conn.Open();
>using (IDbTransaction transaction = conn.BeginTransaction())
> {
> Dosomething();
> transaction.Commit();
> }  
>} 
> 
> My question, what happens if there was an exception inside the
> transaction using block? I know that the transaction object would be
> closed and disposed, but does the traction roll back automatically by
> the SQLite engine, or do I need to have special logic for that? What is
> the suggested best practices in this case?
>  

In the equivalent code in TCL, the transaction would
rollback automatically.  But I do not know anything
about the C# bindings that you are using, so I do not
know what will happen in your case.  Have you tried it
to see?  What does the documentation that comes with
your SQLite C# bindings say?  It is the C# bindings,
not the SQLite core, that will determine this behavior.

--
D. Richard Hipp <[EMAIL PROTECTED]>


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] Can ORDER-BY perform Case-Insensitive comparison?

2007-07-16 Thread drh
Bharath Booshan L <[EMAIL PROTECTED]> wrote:
> 
>  Consider following query
> 
>  SELECT  Name 
>  FROM People
>  ORDER BY Name ASC;
> 

SELECT Name
  FROM People
 ORDER BY Name ASC COLLATE nocase;

The nocase collating sequence only works for US-ASCII
characters.  If you need UTF-8 you will need to use
a different collating sequence.  But the principle
is the same.

--
D. Richard Hipp <[EMAIL PROTECTED]>


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] sqlite3

2007-07-16 Thread drh
Huber Privat <[EMAIL PROTECTED]> wrote:
> Guten Tag
> 
> Ich arbeite mit SQLite3 über ein Netzwerk.
> 
> Wenn 2 User zur gleichen Zeit arbeiten wird der
> Zugriff auf die SQLite3-Datenbank sehr langsam.
> 
> Was mache ich falsch.
> Bitte um Hilfe.
> 

SQLite tends to not work well on a network filesystem.
This is because network filesystems are themselves
slow.  This is especially true when you have multiple
processes attempting to access the database at the
same time.  A lot of traffic has to go back and
forth across the network in order to negotiate the
approriate locks.

If you have multiple clients access a single database
over a network, you are probably better off using a
client/server database engine.

--
D. Richard Hipp <[EMAIL PROTECTED]>


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] Re: inner join

2007-07-16 Thread Gerry Snyder

RB Smissaert wrote:

That is an interesting one.
Where could I find documentation about coalesce?

  

The basic description is to be found in the Core Functions section of:

http://sqlite.org/lang_expr.html

In a nutshell, the function returns the first non-null argument.


HTH,

Gerry

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] Re: Re: inner join

2007-07-16 Thread Igor Tandetnik

RB Smissaert <[EMAIL PROTECTED]>
wrote: 

Where could I find documentation about coalesce?


http://sqlite.org/lang_expr.html

Near the bottom where all the built-in functions are described.

Igor Tandetnik

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



RE: [sqlite] Re: inner join

2007-07-16 Thread Andre du Plessis
The Id piece works great thanks! If I want to update 2 fields on table
A, the following syntax doesn't work as expected, as it updates all to
records to 'DONE'.
 
update A set Flag = 'DONE',
Id = coalesce(
(select Id from B
 where A.Field1 = B.Field_Temp and B.Price > 0),
Id);

-Original Message-
From: Andre du Plessis 
Sent: 16 July 2007 02:30 PM
To: Gavin McGuinness
Subject: FW: [sqlite] Re: inner join

Here you go
It was answered by the mighty Igor, he's like THEE guru, guru's turn to
him for help, so don't question just follow :)

-Original Message-
From: Igor Tandetnik [mailto:[EMAIL PROTECTED] 
Sent: 16 July 2007 01:49 PM
To: SQLite
Subject: [sqlite] Re: inner join

Andre du Plessis <[EMAIL PROTECTED]> wrote:
> I would like to be able to accomplish the following but don't see any
> support for inner joins on update queries.
> 
> update A
> set Id = B.Id
> from A inner join B
> on A.Field1 = B.Field_Temp
> where B.Price > 0

update A set Id = coalesce(
(select Id from B
 where A.Field1 = B.Field_Temp and B.Price > 0),
Id);

Igor Tandetnik


-
To unsubscribe, send email to [EMAIL PROTECTED]

-


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] Can ORDER-BY perform Case-Insensitive comparison?

2007-07-16 Thread Bharath Booshan L
Hi All,

 Eg:

   People table  
  
  | EmpID | Name|
 21 Rajesh
 22 raj
 23 Rakesh 
 24 ramesh 

 Consider following query

 SELECT  Name 
 FROM People
 ORDER BY Name ASC;

 will result as 

 Rajesh
 Rakesh
 raj
 ramesh

 But where as I need the output to be sorted alphabetically irrespective of
its CASE as shown below.

ramesh
raj
Rajesh
Rakesh


Please anyone suggest me regarding this.

Thanks in advance,

Bharath Booshan L





---
Robosoft Technologies - Come home to Technology

Disclaimer: This email may contain confidential material. If you were not an 
intended recipient, please notify the sender and delete all copies. Emails to 
and from our network may be logged and monitored. This email and its 
attachments are scanned for virus by our scanners and are believed to be safe. 
However, no warranty is given that this email is free of malicious content or 
virus.




-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] sqlite3

2007-07-16 Thread Huber Privat

Guten Tag

Ich arbeite mit SQLite3 über ein Netzwerk.

Wenn 2 User zur gleichen Zeit arbeiten wird der
Zugriff auf die SQLite3-Datenbank sehr langsam.

Was mache ich falsch.
Bitte um Hilfe.

mfg
Huber Gerhard
[EMAIL PROTECTED]


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] Does Transaction object roll back automatically on exceptions?

2007-07-16 Thread Ahmed Sulaiman
Hi all,

I have tried this question in the forum with no answer, so I decide to
give it a try here :)

I am using the "Using" statements in C# to handle the closing of SQLite
connection, transaction and command objects.  I have this setup in
different places in my code (Generic methods returning SQLite objects)
  
using (IDbConnection conn = CreateConnection())
 {
   conn.Open();
   using (IDbTransaction transaction = conn.BeginTransaction())
{
Dosomething();
transaction.Commit();
}  
   } 

My question, what happens if there was an exception inside the
transaction using block? I know that the transaction object would be
closed and disposed, but does the traction roll back automatically by
the SQLite engine, or do I need to have special logic for that? What is
the suggested best practices in this case?
 
Cheers


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



RE: [sqlite] Re: inner join

2007-07-16 Thread RB Smissaert
That is an interesting one.
Where could I find documentation about coalesce?

RBS


-Original Message-
From: Igor Tandetnik [mailto:[EMAIL PROTECTED] 
Sent: 16 July 2007 12:49
To: SQLite
Subject: [sqlite] Re: inner join

Andre du Plessis <[EMAIL PROTECTED]> wrote:
> I would like to be able to accomplish the following but don't see any
> support for inner joins on update queries.
> 
> update A
> set Id = B.Id
> from A inner join B
> on A.Field1 = B.Field_Temp
> where B.Price > 0

update A set Id = coalesce(
(select Id from B
 where A.Field1 = B.Field_Temp and B.Price > 0),
Id);

Igor Tandetnik


-
To unsubscribe, send email to [EMAIL PROTECTED]

-




-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] Re: inner join

2007-07-16 Thread Igor Tandetnik

Andre du Plessis <[EMAIL PROTECTED]> wrote:

I would like to be able to accomplish the following but don't see any
support for inner joins on update queries.

update A
set Id = B.Id
from A inner join B
on A.Field1 = B.Field_Temp
where B.Price > 0


update A set Id = coalesce(
   (select Id from B
where A.Field1 = B.Field_Temp and B.Price > 0),
   Id);

Igor Tandetnik

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



RE: [sqlite] Sharing an in-memory database between applications

2007-07-16 Thread Dennis Povshedny
Hi Rob! 

Maybe standard windows feature memory-mapping-file can help you?

Regards


Xeepe Phone Solution Team
http://en.xeepe.com

-Original Message-
From: Rob Richardson [mailto:[EMAIL PROTECTED] 
Sent: Friday, July 13, 2007 7:35 PM
To: sqlite-users@sqlite.org
Subject: [sqlite] Sharing an in-memory database between applications


Greetings!

We are using an SQLite database to store process data that will
eventually be displayed on a graph.  The database design is simple,
including only six tables, but the table containing the data points for
the graph could contain a few million records.  By using the simplest
possible query and asking for the bare minimum of data I need at any one
point, I've managed to get the time to display the graph down from a few
minutes to about 15 seconds for a sample database with 1.3 million
records.  

But I'm wondering if I can use an in-memory database to improve this
dramatically.  The data is collected by a Windows service that collects
data and adds it to the database once a minute.  If the service would
also store the data into an in-memory database, and the graphing
application could somehow read the same database, I ought to be able to
get unbelievable speed.  Is this feasible?  If so, how would I set it
up?

Another possibility might be to read the entire database from disk into
an in-memory database when the graphing application starts up, if
there's a way to do that that is much faster than a set of INSERT INTO
newtable SELECT * FROM oldtable (or whatever -- you get the idea)
statements.

Thank you very much.

Rob Richardson
RAD-CON INC.


No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.476 / Virus Database: 269.10.2/894 - Release Date:
10.07.2007 17:44
 


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] Get the data from previous months: please, help me to optimize the query...

2007-07-16 Thread Marco NOVARO

Dear both (Christian and Joe),

(I'm the original author of the first mail, I'm just using my "usual" mail,
now... :D ).

Thanks for the replies: both works fine: I have no problem in adding new
data to the DB, but the performance IS an issue.
I tested your solutions, and I got the data in 200ms, that is really good
(compared to the one before).

Thanks again
Marco


2007/7/13, Joe Wilson <[EMAIL PROTECTED]>:


--- Christian Smith <[EMAIL PROTECTED]> wrote:

> > Much faster - add 3 new fields in CustomerData which you can populate
> > via SQLite's trigger mechanism, or an explicit UPDATE prior to your
> > SELECT:
> >
> >  MonthRef-- populate from Months table
> >  MonthRef2   -- date(Months.MonthRef, '-1 year')
> >  MonthRef3   -- date(Months.MonthRef, 'start of year', '-1 month')
> >
> > This way you can avoid several joins with the Months table
> > and avoid the use of the slow view.
>
>
> This is leaving you open to data errors.

Fair enough - just use a temp table to close that loophole.

This is pretty much optimal without changing the original poster's
schema or any application logic concerning IDMonth and MonthRef:

CREATE TABLE Months (
  IDMonth  INTEGER PRIMARY KEY NOT NULL,
  MonthRef INTEGER
);

CREATE TABLE CustomerData (
IDCustomerData  INTEGER PRIMARY KEY NOT NULL,
IDMonth INTEGER,
NdgSingolo TEXT NOT NULL DEFAULT '0',
NdgCliente TEXT NOT NULL DEFAULT '0',
FatturatoNdg REAL DEFAULT 0 ,
FatturatoGruppo REAL DEFAULT 0  ,
MargineIntermediazioneLordo REAL DEFAULT 0  ,
MargineInteresse REAL DEFAULT 0 ,
MargineServizi REAL DEFAULT 0   ,
RaccoltaDirettaSM REAL DEFAULT 0,
RaccoltaIndirettaSM REAL DEFAULT 0  ,
ImpieghiSM REAL DEFAULT 0   ,
RaccoltaDirettaSP REAL DEFAULT 0
);

drop table CustomerData2 if exists;

create temp table CustomerData2 as
  SELECT MonthRef,
date(MonthRef, '-1 year') as MonthRef2,
date(MonthRef, 'start of year', '-1 month') as MonthRef3,
IDCustomerData,
Months.IDMonth IDMonth,
NdgSingolo,
NdgCliente,
FatturatoNdg,
FatturatoGruppo,
MargineIntermediazioneLordo,
MargineInteresse,
MargineServizi,
RaccoltaDirettaSM,
RaccoltaIndirettaSM,
ImpieghiSM,
RaccoltaDirettaSP
  FROM CustomerData, Months
  WHERE CustomerData.IDMonth = Months.IDMonth;

create index CustomerData2i on CustomerData2(NdgSingolo, NdgCliente,
MonthRef);

explain query plan
SELECT AC.*,
   M1.MargineIntermediazioneLordo AS MargineIntermediazioneLordo_m1,
   AP.MargineIntermediazioneLordo AS MargineIntermediazioneLordo_ap,
   M1.MargineInteresseAS MargineInteresse_m1,
   AP.MargineInteresseAS MargineInteresse_ap
FROM CustomerData2 AC
 LEFT OUTER JOIN CustomerData2 M1
   ON  AC.NdgSingolo = M1.NdgSingolo
   AND AC.NdgCliente = M1.NdgCliente
   AND M1.MonthRef = AC.MonthRef2
 LEFT OUTER JOIN CustomerData2 AP
   ON  AC.NdgSingolo = AP.NdgSingolo
   AND AC.NdgCliente = AP.NdgCliente
   AND AP.MonthRef = AC.MonthRef3;

-- 0|0|TABLE CustomerData2 AS AC
-- 1|1|TABLE CustomerData2 AS M1 WITH INDEX CustomerData2i
-- 2|2|TABLE CustomerData2 AS AP WITH INDEX CustomerData2i

-- optional - temp table will be destroyed by connection anyway
drop table CustomerData2;






Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated
for today's economy) at Yahoo! Games.
http://get.games.yahoo.com/proddesc?gamekey=monopolyherenow


-
To unsubscribe, send email to [EMAIL PROTECTED]

-




[sqlite] inner join

2007-07-16 Thread Andre du Plessis
 

I would like to be able to accomplish the following but don't see any
support for inner joins on update queries.

 

update A

set Id = B.Id

from A inner join B

on A.Field1 = B.Field_Temp

where B.Price > 0

 

Is this possible? What is the syntax of this query please?