UniScript and MS Access

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
oz8hp
Posts: 151
Joined: Mon 18 Feb 2008 13:28
Location: Denmark
Contact:

UniScript and MS Access

Post by oz8hp » Sun 22 Nov 2009 19:22

I am trying to create a method of keeping my customers database up to date with new tables and fields needed for new versions of my programs.

But for MS Access there is no CREATE TABLE IF NOT EXISTS available.

What method can then be used?

oz8hp
Posts: 151
Joined: Mon 18 Feb 2008 13:28
Location: Denmark
Contact:

Post by oz8hp » Mon 23 Nov 2009 06:15

My code looks like this at the moment. My problem is now that the error in Execute is caught by UniDAC and not by my code.

Procedure DB_Create_Table(aTable : String);
Var
CreateTable : TUniScript;
Begin
CreateTable := TUniScript.Create(Nil);
CreateTable.Connection := frmDataConnection.conDBserver;
Try
With CreateTable Do
Begin
SQL.Clear;
SQL.Add( ' {IF ACCESS} ');
SQL.Add( ' CREATE TABLE ' + aTable );
SQL.Add( ' {ELSE} ');
SQL.Add( ' CREATE TABLE IF NOT EXISTS ' + aTable );
SQL.Add(' {ENDIF}');
SQL.Add(' (ID INTEGER NOT NULL PRIMARY KEY)');
SQL.Add( ' {IF MYSQL} ');
SQL.Add(' (ENGINE=InnoDB DEFAULT CHARSET=latin1');
SQL.Add(' {ENDIF}');
Try
Execute
Except
On E:Exception Do
Begin
Log_Error(E.Message);
End
End;
End;
Finally
CreateTable.Free;
End;
End;

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Mon 23 Nov 2009 08:06

You can use the OnError event to control what to do on errors.

Set the Action parameter of the OnError handler to eaContinue to ignore the error and continue.

oz8hp
Posts: 151
Joined: Mon 18 Feb 2008 13:28
Location: Denmark
Contact:

Post by oz8hp » Mon 23 Nov 2009 08:23

And where to put that?

(I am still learning all the wonderfull things UniDAC can do)

oz8hp
Posts: 151
Joined: Mon 18 Feb 2008 13:28
Location: Denmark
Contact:

Post by oz8hp » Mon 23 Nov 2009 08:56

I can do it if a put a visual UniScript component on my main form.

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 24 Nov 2009 09:26

After you have created an event handler for the TUniScript component on the form, you can delete the component from the form. The procedure that is created for the event is left in the unit. So you can assign the procedure name to the OnError property in your code.

oz8hp
Posts: 151
Joined: Mon 18 Feb 2008 13:28
Location: Denmark
Contact:

Post by oz8hp » Tue 24 Nov 2009 09:36

My code is not in a form unit - it is in a codeunit.

So I have no idea of how to do it :D but for now it is working. Then the tweaking can come later on.

Post Reply