Subject | Re: Firebird, Access and views, ODBC tracing |
---|---|
Author | ellsworth_eric |
Post date | 2004-09-21T13:10:32Z |
--- In firebird-support@yahoogroups.com, "Alan McDonald" <alan@m...>
wrote:
I certainly agree that the records reside in the table, but my
understanding is that Firebird allows records to be inserted through a
view.
Here's the SQL to create the table:
create table PAYMENTS(
PAYMENTID integer not null,
PAYMENTDATE date,
PAYMENTMETHOD varchar(50) not null,
CCTYPE varchar(50),
CCNAME varchar(200),
CCEXPIREMONTH varchar(20),
CCEXPIREYEAR varchar(10),
AMOUNT float not null,
CCNUMBER varchar(50),
NOTES blob sub_type 0 segment size 80,
PAYMENTFOR varchar(25) not null,
INVITEEID integer not null,
AUCTIONYEAR integer);
alter table PAYMENTS add constraint CHECK_PAYMENTFOR check (PAYMENTFOR
IN ("Item","Entrance Fee","Donation","Other"));
alter table PAYMENTS add constraint CHECKK_AUCTIONYEAR CHECK
(AUCTIONYEAR >= 2003);
/* Primary Key */
alter table PAYMENTS add constraint PK_PAYMENTS primary key (PAYMENTID);
/* Foreign Key */
alter table PAYMENTS add constraint FK1_PAYMENTS foreign key
(INVITEEID) references GUESTS(INVITEEID);
/* Triggers */
create trigger PAYMENTID_INCREMENT for PAYMENTS active before insert
position 0
as
begin
IF (PAYMENTS.PAYMENTID IS NULL) THEN
PAYMENTS.PAYMENTID = GEN_ID(PAYMENTID,1);
end
wrote:
> > I have a table Payments, which has these fields:using
> > PaymentID (int, connected to generator PaymentID)
> > PaymentDate (date)
> > PaymentMethod (varchar)
> > SaleYear (int)
> > I can successfully link tables and add entries ot them in Access,
> > the ODBC driver from:query in
> > http://www.firebirdsql.org/index.php?op=files&id=odbc
> > <http://www.firebirdsql.org/index.php?op=files&id=odbc>
> >
> > I also created a view:
> > CREATE VIEW CAT_PAYMENTS AS
> > SELECT * FROM Payments
> > WHERE SaleYear = EXTRACT(YEAR FROM CAST('NOW' AS DATE))
> > WITH CHECK OPTION;
> >
> > I would like to be able to use the view in Access so that a particular
> > user can only make entries for SaleYear being this year.
> >
> > I can successfully insert items into the view using Marathon's SQL
> > execution function, and succesfully SELECT data from this view. I can
> > also successfully insert items into the view using a pass-thru
> > Access. However, when I attempt to use a regular query to add data totable.
> > this view, I get the error:
> > "Single-row update/delete affected more than one row of a linked
> > Unique index contains duplicate values."I get
> >
> > Has anybody encountered this error or know anything about it? All
> > on the google newsgroups is stuff about checking for dupes, and Iam not
> > violating any unique indexes.the ODBC
> >
> > To try to trace this problem, I would like to enable tracing in
> > driver to figure out what SQL is sent to the server. However, therethe view.
> > don't appear to be any options in the driver dialog box for doing so.
> > Can anyone point me to resources on tracing ODBC calls?
> >
> > Many thanks,
> >
> > Eric
>
> You don't actually insert records into a view - you insert them into the
> table. Marathon is hiding this fact from you perhaps.
> This pass-thru query is also trying to insert into the table - not
> Your view is simple and only references one table so you may geterrors in
> future if/when your view become joins and reference more than one table.which , I
> In both of these successful cases, the tool is inserting a record
> suspect, omits the PK field and your trigger does not check for NULL, itHi Alan,
> just creates a gen value. This will be successful.
> If your trigger tests for NULL then you may have been able to insert one
> record only - is your gen field a PK? perhaps not also... it will accept
> NULLs if it is not a PK.
> Show us your table metadata including your trigger and generator.
>
> Alan
I certainly agree that the records reside in the table, but my
understanding is that Firebird allows records to be inserted through a
view.
Here's the SQL to create the table:
create table PAYMENTS(
PAYMENTID integer not null,
PAYMENTDATE date,
PAYMENTMETHOD varchar(50) not null,
CCTYPE varchar(50),
CCNAME varchar(200),
CCEXPIREMONTH varchar(20),
CCEXPIREYEAR varchar(10),
AMOUNT float not null,
CCNUMBER varchar(50),
NOTES blob sub_type 0 segment size 80,
PAYMENTFOR varchar(25) not null,
INVITEEID integer not null,
AUCTIONYEAR integer);
alter table PAYMENTS add constraint CHECK_PAYMENTFOR check (PAYMENTFOR
IN ("Item","Entrance Fee","Donation","Other"));
alter table PAYMENTS add constraint CHECKK_AUCTIONYEAR CHECK
(AUCTIONYEAR >= 2003);
/* Primary Key */
alter table PAYMENTS add constraint PK_PAYMENTS primary key (PAYMENTID);
/* Foreign Key */
alter table PAYMENTS add constraint FK1_PAYMENTS foreign key
(INVITEEID) references GUESTS(INVITEEID);
/* Triggers */
create trigger PAYMENTID_INCREMENT for PAYMENTS active before insert
position 0
as
begin
IF (PAYMENTS.PAYMENTID IS NULL) THEN
PAYMENTS.PAYMENTID = GEN_ID(PAYMENTID,1);
end