Recent

Author Topic: Error Handlicng when Table Doesn't Exists  (Read 663 times)

Weitentaaal

  • Jr. Member
  • **
  • Posts: 88
Error Handlicng when Table Doesn't Exists
« on: November 17, 2020, 02:51:42 pm »
Hey Guys,

So i Got This Code:

Code: Pascal  [Select][+][-]
  1. try
  2.      MacAd := dbHist.FieldByName('ProgID').AsString;
  3. except
  4.       on E : EDatabaseError do begin
  5.            //ShowMessage('DB ERROR:' + ' ' + E.ClassName + ' ' + E.Message);
  6.           //If This Table (RollBK) Doesnt Exists, then create it -->
  7.           //SQL := 'CREATE TABLE ROLLBK (Td DATE, Tt TIME, Zeichnung INTEGER, Part INTEGER, Act INTEGER, Pid TEXT(20));';
  8.       end;
  9.    end;
  10.  

Any1 any Idea how i Can do this ?

Thanks A Lot :)

Zvoni

  • Sr. Member
  • ****
  • Posts: 433
Re: Error Handlicng when Table Doesn't Exists
« Reply #1 on: November 17, 2020, 03:29:33 pm »
One System to rule them all, One IDE to find them,
One Code to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
People call me crazy, because i'm jumping out of perfectly fine aircraft

Weitentaaal

  • Jr. Member
  • **
  • Posts: 88
Re: Error Handlicng when Table Doesn't Exists
« Reply #2 on: November 18, 2020, 10:31:55 am »
i just searched for the Wrong Thing Sorry :o

rvk

  • Hero Member
  • *****
  • Posts: 4453
Re: Error Handlicng when Table Doesn't Exists
« Reply #3 on: November 18, 2020, 10:38:48 am »
And besides that... you have the try/except around the wrong code. That will only trigger the except if there is no FIELD ProgID.

If you use a table which doesn't exists (like stated in your title) you need to put the sql.open (with SELECT) inside try/except. Then you can examine the exception if it contains "table not found" or something (depending on your database).

Checking beforehand with gettablenames would indeed be preferable over exceptionhandling.

Weitentaaal

  • Jr. Member
  • **
  • Posts: 88
Re: Error Handlicng when Table Doesn't Exists
« Reply #4 on: November 25, 2020, 10:26:26 am »
Thanks rvk :)

Understand this whole thing better now.
I went with the gettablenames :)

 

TinyPortal © 2005-2018