Re: [sqlite] Re: - [sqlite] can anyone reproduce ticket# 1540 (failure to create a primary key)?

2005-11-29 Thread Kurt Welgehausen
> ... and then query the sqlite_master for the
> names of other indexes ...

Or use PRAGMA index_list(table-name) and PRAGMA index_info(index-name)

Regards



RE: [sqlite] Re: - [sqlite] can anyone reproduce ticket# 1540 (failure to create a primary key)?

2005-11-28 Thread Bogdan Ureche
Thanks to all who replied, I appreciate all your help. The problem is now
solved. The ticket 1540 is indeed invalid (the primary key IS created, even
when it is not visible in sqlite_master) and I got all the answers I needed.

To summarize: for getting information about all the indexes for a table, one
should use 

PRAGMA table_info(table_name) 

for extracting the primary key, and then query the sqlite_master for the
names of other indexes, ignoring any 'sqlite_autoindex_tablename_1' entries.


To answer Shane's question (if a constraint should be queriable or not), in
my opinion anything that can be set should be queriable, otherwise one could
not build an administration tool that works as expected. As far as sqlite is
concerned, almost anything can be queried without parsing the SQL. Why
'almost'? I still didn't figure out a way (other than parsing) to query the
collation sequence for a field, for example.

Done. Now I can finally go to bed.

Regards,

Bogdan




Re: [sqlite] Re: - [sqlite] can anyone reproduce ticket# 1540 (failure to create a primary key)?

2005-11-28 Thread Derrell . Lipman
"Bogdan Ureche" <[EMAIL PROTECTED]> writes:

> I am beginning to believe that maybe I was wrong in my assumption that 'if a
> table has an index, that index shows in sqlite_master'. Then my problem is
> now to find another way to get index information for a table. Any
> suggestions?

An index for an INTEGER PRIMARY KEY does not show in sqlite_master.  Instead,
you can find the primary key of a table using:

  PRAGMA table_info(table_name);

The field(s) marked with pk=1 are primary key field(s).

  % sqlite3 /tmp/xxx.db
  SQLite version 3.2.1
  Enter ".help" for instructions
  sqlite> CREATE TABLE test_table
 ...> (
 ...>   my_primary_keyINTEGER PRIMARY KEY,
 ...>   some_other_field  TEXT
 ...> );
  sqlite> .mode line
  sqlite> PRAGMA table_info(test_table);
 cid = 0
name = my_primary_key
type = INTEGER
 notnull = 0
  dflt_value = 
  pk = 1

 cid = 1
name = some_other_field
type = TEXT
 notnull = 0
  dflt_value = 
  pk = 0

With more than one field composing the primary key:

  sqlite> CREATE TABLE t2 (f1 INTEGER, f2 TEXT, f3 TEXT, PRIMARY KEY(f1, f2));
  sqlite> PRAGMA table_info(t2);
 cid = 0
name = f1
type = INTEGER
 notnull = 0
  dflt_value = 
  pk = 1

 cid = 1
name = f2
type = TEXT
 notnull = 0
  dflt_value = 
  pk = 1

 cid = 2
name = f3
type = TEXT
 notnull = 0
  dflt_value = 
  pk = 0
  sqlite>

With a non INTEGER PRIMARY KEY (which you *can* have, contrary to a comment
made previously by someone):

  sqlite> CREATE TABLE t3 (f1 TEXT PRIMARY KEY, f2 INTEGER);
  sqlite> PRAGMA table_info(t3);
 cid = 0
name = f1
type = TEXT
 notnull = 0
  dflt_value = 
  pk = 1

 cid = 1
name = f2
type = INTEGER
 notnull = 0
  dflt_value = 
  pk = 0

Note that any primary key fields *other than* a single INTEGER PRIMARY KEY are
also in sqlite_master:

  sqlite> select * from sqlite_master;
  type = table
  name = test_table
  tbl_name = test_table
  rootpage = 2
   sql = CREATE TABLE test_table
  (
my_primary_keyINTEGER PRIMARY KEY,
some_other_field  TEXT
  )

  type = table
  name = t2
  tbl_name = t2
  rootpage = 3
   sql = CREATE TABLE t2 (f1 INTEGER, f2 TEXT, f3 TEXT, PRIMARY KEY(f1, f2))

  type = index
  name = sqlite_autoindex_t2_1
  tbl_name = t2
  rootpage = 4
   sql = 

  type = table
  name = t3
  tbl_name = t3
  rootpage = 5
   sql = CREATE TABLE t3 (f1 TEXT PRIMARY KEY, f2 INTEGER)

  type = index
  name = sqlite_autoindex_t3_1
  tbl_name = t3
  rootpage = 6
   sql = 
  sqlite>


RE: [sqlite] Re: - [sqlite] can anyone reproduce ticket# 1540 (failure to create a primary key)?

2005-11-28 Thread Thomas Briggs
 
> I am beginning to believe that maybe I was wrong in my 
> assumption that 'if a table has an index, that index shows in 
> sqlite_master'. Then my problem is now to find another way to 
> get index information for a table. Any suggestions?

   Your assumption is correct.  Where you are incorrect is assuming that
defining a column as INTEGER PRIMARY KEY results in the creation of an
index.  See the docs on the web site (particularly the syntax for CREATE
TABLE, IIRC) for an explanation.

   -Tom



RE: [sqlite] Re: - [sqlite] can anyone reproduce ticket# 1540 (failure to create a primary key)?

2005-11-28 Thread Bogdan Ureche
Thanks for the reply. To answer your question, semi-colons are not needed
when executing a single SQL statement.

As regarding the other matter, the table is indeed created and accepts
insertion of NULL values, but that was not the problem.

I am beginning to believe that maybe I was wrong in my assumption that 'if a
table has an index, that index shows in sqlite_master'. Then my problem is
now to find another way to get index information for a table. Any
suggestions?

Regards,

Bogdan




[sqlite] Re: - [sqlite] can anyone reproduce ticket# 1540 (failure to create a primary key)?

2005-11-28 Thread rbundy

I cannot reproduce the problem. Table is created and accepts insertion of
NULL values as expected. However, you do not include semi-colons at the end
of the statements your samples - is this of any significance?

Regards.

rayB




** PLEASE CONSIDER OUR ENVIRONMENT BEFORE PRINTING *
*** Confidentiality and Privilege Notice ***

This e-mail is intended only to be read or used by the addressee. It is
confidential and may contain legally privileged information. If you are not
the addressee indicated in this message (or responsible for delivery of the
message to such person), you may not copy or deliver this message to anyone,
and you should destroy this message and kindly notify the sender by reply
e-mail. Confidentiality and legal privilege are not waived or lost by reason
of mistaken delivery to you.

Qantas Airways Limited
ABN 16 009 661 901

Visit Qantas online at http://qantas.com