I am writing a Perl based application that converts an SQLite database into an Excel workbook and back again. It works as is, but is missing one small piece. I do not know how to determine if the UNIQUE constraint has been set for a specific column.
To get a list of tables in a database, I use:
select name from sqlite_master
where type = 'table'
and name <> 'sqlite_sequence' order by name;
Then to get column and constraint information for each table, I do:
PRAGMA table_info($TableName);
This tells me everything I need to know except if a column has the UNIQUE constraint enabled.
In case this is not clear, here is a trivial example. Suppose I create a database table by doing this:
CREATE TABLE DATA
(
ID integer primary key,
Invoice integer unique,
Product varchar,
Comment varchar
);
I want to know how I can subsequently interrogate the SQLite database table created in this manner to determine which columns have the UNIQUE constraint set. In this case, it would be the Invoice column.
Any suggestions?