tags:

views:

330

answers:

2

I got a app developed in Delphi 6 with master/detail constrution. Both master and detail take TQuery to open the data source. It works fine when the master opens first, but after that an error message of "Table is not indexed" occured when the detail opens the data source.

The working account for app. is the SCHEMA_USER, which has a after login trigger to switch itself to SCHEMA_OWNER, it looks like this:

CREATE OR REPLACE TRIGGER AFTER_LOGON_TRG
AFTER LOGON ON SCHEME_USER.SCHEMA
BEGIN
  --switch to  SCHEMA_OWNER schema
  DBMS_APPLICATION_INFO.set_module(USER,'Inilialized');
  EXECUTE IMMEDIATE 'ALTER SESSION SET current_schema=SCHEMA_OWNER';

END;

I use SCHEMA_USER to login in DB and execute deltail's SQL, and it works fine. I don't know what's going wrong.

So, any idea is appreciated.

Thx adv.!!

David, Regards

+1  A: 

The error message tells you exactly what the problem is, I think.

An index on the detail table's linking field is required so that, when the master table's record pointer is moved, the appropriate rows in the detail table can be found. The error message indicates that there is no index on the necessary column in the detail table.

The solution is to add an index to the table before opening the detail table. You should only need to do this once (I say should because you didn't indicate which database you're using).

EDIT: After the third comment describing the schema details.

Your problem is here: "The detail query's SQL: ... WHERE order_no = :order_no", while you say "4) order_no & custID are the two-columns index". You're only using half of the index value, and the detail table can't figure out what to do.

You need to either:

1) Create a new index that's only on order_no (which seems like a bad idea)

or

2) (Preferred) Add the custID to the detail query's SQL:

WHERE order_no = :order_no AND custID = :custID
Ken White
Thanks for your reply. Tables come from Oracle 10g(10.2.0.4). An index is already added to the detail table, however, the error message still happens. Here is the detail's SQL:SELECT rowid, myDetail.* FROM myDetail WHERE order_no = :order_no ORDER BY cust_name The detail also already adds 'order_no' to params properties for lining to the master.The master's primary key is order_no, here is the SQL:SELECT myMaster.*, customer.ID FROM myMaster, customer WHERE myMaster.order_no = customer.order_no AND myMaster.custId = customer.custIdSo, what else I could do? David,regards
David
Is the index on the detail table on the ORDER_NO column? How are you connecting to the database (as Jeroen asked, BDE, ADO, AnyDac)? If you want help here, David, you need to provide the additional information we're asking you to provide...
Ken White
David
8.) The DLL of master table: create table SCHEMA_OWNER.Master(order_no varchar2(10) no null, custID varchar(20) not null, delivery_addr varchar2(200) not null);alter table myMaster add constraint myMaster_PK primary key (order_no) using index tablespace USERINDEX pctfree 10 initrans 2 maxtrans 255 storage ( initial 234M minextents 1 maxextents unlimited );-- Create/Recreate check constraints alter table myMaster add constraint myMaster_CK_cust_ID check (cust_id IN ('1','2','3','4','5','6'));
David
The DLL of deatil table: create table SCHEMA_OWNER.myDetail(order_no varchar2(10) not null, custId varchar2(20) not null, material_id varchar(50) not null, stock_qty int not null, process_state varchar2(2) not null, upd_date varchar2(8)); create index myDetail_AK1 on myDetail(order_no, custId) tablespace USERINDEX pctfree 10 initrans 2 maxtrans 255 storage ( initial 170M minextents 1 maxextents unlimited ); alter table myDetail add constraint myDetail_CK_custId check (custID IN ('1','2','3','4','5','6'));
David
9.) When th app starts, it logins into the DB by using SCHEMA_USER account. And then SCHEMA_USER will be switched to SCHEM_OWNER through the AFTER LOGON trigger defined above.
David
Check my answer for the edit I just made. :-)
Ken White
10.)The privileges of select, insert, update, delete on the myDetail table are granted to SCHEMA_USER already.
David
if any other infomation is needed to know, plz kindly to tell me. Thanks!
David
Thx Ken, I willl have your solution to try and then report the result back here!
David
A: 

Dear Gurus,

Finally we find out why Delphi shows the error message while App. logons as another user by setting CURRENT_SCHEMA on AFTER LOGON triiger.

The below is the steps to avoid the error :

  1. Using TTable instead of TQuery to be the DETAIL(Master is still the TQuery).
  2. Setting IndexFieldNames property instead of IndeName.

Then it works.

We guess that Delphi maybe uses USER_INDEXES view to query the indexes it could access rather than ALL_INDEXES view, so that Delphi cannot "correctly" get the indexes considered as that it should have. And that is!

Thanks guys!

David