MS SQL updatable Views
Posted: Sat 08 Jun 2013 20:26
MS SQL Server supports updatable views.
For example, we have a table TCustomers (Fid, FName) and view VCustomers (select Fid, FName from TCustomers)
So, we can write
and it will work. It’s very useful feature when user have restricted access to the tables (deny select / insert / update / delete for table TCustomers, but allow to do it with view VCustomers).
So, the problem is SDAC replaces the name of the view with appropriate table. If I write query like
and try to modify data, SDAC will generate code like
VCustomers was replased with TCustomers 
Of course the server will reject the transaction, because user doesn’t have permission to edit table TCustomers.
I wrote about a similar problem before (SQL Generator doesn't want to update VIEW http://forums.devart.com/viewtopic.php?f=6&t=24136)
I have to reading the forum and a little digging in the Sdac source code. So I found solution.
When query is opened, I manually replace table TCustomers with view VCustomers
After that sdac generated code is true:
The question in the following. Is it possible to disable replacing view with table? If not, how can I get origin view name (VCustomers) for a query instead of manually replacing it (TDBAccessUtils...TableName: = 'VCustomers'). May be sdac has a function like GetOrignUpdateTable? 
For example, we have a table TCustomers (Fid, FName) and view VCustomers (select Fid, FName from TCustomers)
So, we can write
Code: Select all
update VCustomers set FName = "Igor" where FId = 18
So, the problem is SDAC replaces the name of the view with appropriate table. If I write query like
Code: Select all
select * from VCustomers,
Code: Select all
update TCustomers set FName = "Igor" where FId = 18.

Of course the server will reject the transaction, because user doesn’t have permission to edit table TCustomers.
I wrote about a similar problem before (SQL Generator doesn't want to update VIEW http://forums.devart.com/viewtopic.php?f=6&t=24136)
I have to reading the forum and a little digging in the Sdac source code. So I found solution.
When query is opened, I manually replace table TCustomers with view VCustomers
Code: Select all
TDBAccessUtils.GetTablesInfo (TCustomDADataSet (DataSet)). Items [0]. TableName: = 'VCustomers';
Code: Select all
update VCustomers set FName = "Igor" where FId = 18 and.
