Board index » delphi » Insert a new record (query/table)

Insert a new record (query/table)

Hell all,

When I use a query (IBquery) to add a new reocrds I can insert duplicate reords without any error message. But using table (IBtable) I get primary key exception error.
Why is that different?
Which one (query /  table) is better to insert, update records?
How can I display customize message?

Thanks.

 

Re:Insert a new record (query/table)


Hi Alan,
Never use IBTable on c/s develompent, the best component that
suite your needs id IBDataset....
Ciao!

Marco Kregar

"Alan" <alpric...@hotmail.com> ha scritto nel messaggio
news:3ee7333d$1@newsgroups.borland.com...

Quote

> Hell all,

> When I use a query (IBquery) to add a new reocrds I can insert duplicate

reords without any error message. But using table (IBtable) I get primary
key exception error.

Quote
> Why is that different?
> Which one (query /  table) is better to insert, update records?
> How can I display customize message?

> Thanks.

---
Outgoing mail is certified Virus Free!

Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.489 / Virus Database: 288 - Release Date: 10/06/2003

Re:Insert a new record (query/table)


Why didn't I get exception error in the query? How can I prevent duplicate primary key entry in the record?

Thanks.
Alan

Quote
"Marco" <mkre...@esys.it> wrote:
>Hi Alan,
>Never use IBTable on c/s develompent, the best component that
>suite your needs id IBDataset....
>Ciao!

>Marco Kregar

>"Alan" <alpric...@hotmail.com> ha scritto nel messaggio
>news:3ee7333d$1@newsgroups.borland.com...

>> Hell all,

>> When I use a query (IBquery) to add a new reocrds I can insert duplicate
>reords without any error message. But using table (IBtable) I get primary
>key exception error.
>> Why is that different?
>> Which one (query /  table) is better to insert, update records?
>> How can I display customize message?

>> Thanks.

>---
>Outgoing mail is certified Virus Free!

>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.489 / Virus Database: 288 - Release Date: 10/06/2003

Re:Insert a new record (query/table)


Quote
Alan wrote:
> Why didn't I get exception error in the query? How can I prevent
> duplicate primary key entry in the record?

If there is a unique or primary index/constraint then you certainly should.
Have you confirmed the duplicate record was actually inserted? Have you put
a try/except block around the insert?

--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
Powered by Delphi and IB: http://www.logicfundamentals.com/RadBooks.html
"Democracy, without that guarantee of liberty, is merely a method of
selecting tyrants." - Alan Nitikman

Re:Insert a new record (query/table)


Yes I included try/except block

Here is my code
  try
   IBTransaction1.StartTransaction;
   CustQry.Close;
   CustQry.ParamByName('CustID').AsString   := CustID;
   CustQry.ParamByName('Customer').AsString := Customer;
   CustQry.ExecSQL;
   IBTransaction1.Commit;
  except
    IBTransaction1.Rollback;
  end;

CustQry  -
Insert into customer (CustID,Customer)
values (:CustID,:Customer)

"Wayne Niddery [TeamB]" <wnidd...@chaff.aci.on.ca> wrote:

Quote
>Alan wrote:
>> Why didn't I get exception error in the query? How can I prevent
>> duplicate primary key entry in the record?

>If there is a unique or primary index/constraint then you certainly should.
>Have you confirmed the duplicate record was actually inserted? Have you put
>a try/except block around the insert?

>--
>Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
>Powered by Delphi and IB: http://www.logicfundamentals.com/RadBooks.html
>"Democracy, without that guarantee of liberty, is merely a method of
>selecting tyrants." - Alan Nitikman

Re:Insert a new record (query/table)


Quote
Alan wrote:
> Yes I included try/except block

> Here is my code
>   try
>    IBTransaction1.StartTransaction;
>    CustQry.Close;
>    CustQry.ParamByName('CustID').AsString   := CustID;
>    CustQry.ParamByName('Customer').AsString := Customer;
>    CustQry.ExecSQL;
>    IBTransaction1.Commit;
>   except
>     IBTransaction1.Rollback;
>   end;

> CustQry  -
> Insert into customer (CustID,Customer)
> values (:CustID,:Customer)

Ok, so on an exception it should get rolled back. What are you seeing
*instead* of that? What are you expecting to see? Again can you confirm the
record is actually being inserted despite being a duplicate? I would find
that difficult to believe since that would indicate a bug in Interbase -
enforcing unique or primary constraints is pretty basic.

--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
Powered by Delphi and IB: http://www.logicfundamentals.com/RadBooks.html
"Democracy, without that guarantee of liberty, is merely a method of
selecting tyrants." - Alan Nitikman

Other Threads