Re: [sqlite] Re: How to check if the table has some specific values

2007-12-13 Thread Trevor Talbot
I think Joanne's example may be simplified, and the question was
really more general...


On 12/12/07, Joanne Pham <[EMAIL PROTECTED]> wrote:

> Basiclly there is no SQL logic in SQLite.

Right, there's nothing like T-SQL. Even in other databases, most
procedural logic along IF..THEN lines is done with a dedicated
language used for functions or stored procedures, not part of the
primary SQL interface. SQLite does have a limited form of procedural
logic in its trigger statements.

Keep in mind that because SQLite is an embedded database, it's
considered normal to do such logic within the application as
necessary. There isn't any overhead for a network protocol or similar,
and you generally don't need to deal with arbitrary applications
accessing your database, so there's less gain for pushing things into
the database interface itself. After all, the database is inside your
application already.

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



Re: [sqlite] Re: How to check if the table has some specific values

2007-12-13 Thread Kees Nuyt

Hi Joanne,

On Wed, 12 Dec 2007 16:20:17 -0800 (PST), Joanne Pham
<[EMAIL PROTECTED]> wrote:

>Hi Igor,
>Thanks for the response.
>Basiclly there is no SQL logic in SQLite.

I'm not sure what you mean here.

>I would like to check if the database version is xyz
>then I will have different action and if then database
>version is abc then I will have different action. 
>So SQLite doesn't allow this luxury.

Sure it does, it even gives you a choice:
- use the schema version SQLite automatically maintains.
- set and use your own version number;
The only thing you can't do is use the version directly in SQL,
that is:
SELECT * FROM test1 WHERE ID = (PRAGMA schema_version);
is not a valid statement.

Both techniques are demonstrated below.

sqlite_version():3.5.3

CREATE TABLE test1 (
  ID INTEGER PRIMARY KEY NOT NULL,
  t1_name text
);
PRAGMA schema_version;
: 1
PRAGMA user_version;
: 0

PRAGMA user_version = 6001;

CREATE INDEX idx_t1_name ON test1 (t1_name);

PRAGMA schema_version;
: 2
PRAGMA user_version;
: 6001

CREATE TABLE test2 (
  ID INTEGER PRIMARY KEY NOT NULL,
  t2_name text
);

PRAGMA schema_version;
: 3
PRAGMA user_version;
: 6001

PRAGMA user_version = 6002;
INSERT INTO test1 VALUES (1,'alpha');
INSERT INTO test2 VALUES (2,'beta');

PRAGMA schema_version;
: 3
PRAGMA user_version;
: 6002

>Thanks,
>JP

I hope this helps,
-- 
  (  Kees Nuyt
  )
c[_]

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



Re: [sqlite] Re: How to check if the table has some specific values

2007-12-12 Thread Joanne Pham
Hi Igor,
Thanks for the response.
Basiclly there is no SQL logic in SQLite.
I would like to check if the database version is xyz then I will have different 
action and if then database version is abc then I will have different action. 
So SQLite doesn't allow this luxury.
Thanks,
JP


- Original Message 
From: Igor Tandetnik <[EMAIL PROTECTED]>
To: SQLite <sqlite-users@sqlite.org>
Sent: Wednesday, December 12, 2007 4:14:08 PM
Subject: [sqlite] Re: How to check if the table has some specific values

Joanne Pham  wrote:
> I have been working on MSSQL server and SQLite is new to me. I
> usually did the following in MSQL server to check of the specific row
>  is existed in the table and have different action depending on the
> result of the check. For example: Create table versionTable
> (dbVersion varchar(20) insert into versionTable values('6, 0, 0, 1');
> Now the table is created and it has one row(6, 0, 0, 1).
> I usually do the following to check the content of the table
>
> If NOT EXISTS ( select 1 from versionTable where dbVersion = '6, 0,
>  0, 1') insert into versionTable values('6, 0, 0, 2');
> ELSE
>update versionTable set dbVersion = '6, 0, 0, 2';
>
> I really don't know how to convert these syntax from MSSQL server to
> SQLite.

delete from versionTable;
insert into versionTable values ('6, 0, 0, 2');


Specifically for maintaining a version number in the database file, see 
also

PRAGMA user_version

at http://sqlite.org/pragma.html

Igor Tandetnik 


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


  

Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping

[sqlite] Re: How to check if the table has some specific values

2007-12-12 Thread Igor Tandetnik

Joanne Pham  wrote:

I have been working on MSSQL server and SQLite is new to me. I
usually did the following in MSQL server to check of the specific row
  is existed in the table and have different action depending on the
result of the check. For example: Create table versionTable
(dbVersion varchar(20) insert into versionTable values('6, 0, 0, 1');
Now the table is created and it has one row(6, 0, 0, 1).
I usually do the following to check the content of the table

If NOT EXISTS ( select 1 from versionTable where dbVersion = '6, 0,
 0, 1') insert into versionTable values('6, 0, 0, 2');
ELSE
update versionTable set dbVersion = '6, 0, 0, 2';

I really don't know how to convert these syntax from MSSQL server to
SQLite.


delete from versionTable;
insert into versionTable values ('6, 0, 0, 2');


Specifically for maintaining a version number in the database file, see 
also


PRAGMA user_version

at http://sqlite.org/pragma.html

Igor Tandetnik 



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