Hi Gilles,

>> SELECT id AS Identification FROM foobar
>
> Thanks. This is what I already use for displaying the results, but
> then I'm stuck when I need to perform INSERT/UPDATES because I need to
> get the actual columns names :-/
>
> It'd be cool if each column in a table could have an internal name and
> an external name.

You can have multiple views into the same table (or joined tables).  
Each view can have its own column names as aliases for those in the  
underlying table(s) or even be the result of an expression using the  
underlying table columns. You probably know this.

You can also set up a view to pass on its inserts, updates and deletes  
to the underlying table(s), using "instead of" triggers.

This combination facilitates the creation of properly normalised  
"internal" tables (which are generally hard for human operators to  
conceptualise and work with), whilst providing nice looking human  
friendly "beautified" views on which human operators can browse and  
perform data entry.

So, you might have:

create table MyTable
(       ID integer primary key
,       Name text
)
;

create view MyView
as
select
        ID as Indentification
,       Name
)
;

create trigger "MyView Insert"
instead of insert
on MyView
begin
insert into MyTable( ID, Name )
select new.Identification, new.Name
;
end
;

create trigger "MyView Update"
instead of update
on MyView
begin
update MyTable
set
        ID = new.Identification
,       Name = new.Name
where ID = old.Identification
;
end
;

create trigger "MyView Delete"
instead of delete
on MyView
begin
delete from MyTable
where ID = old.Identification
;
end
;

Tom
BareFeet

  --
Comparison of SQLite GUI applications:
http://www.tandb.com.au/sqlite/compare/



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

Reply via email to