Page 1 of 1
UniScript and MS Access
Posted: Sun 22 Nov 2009 19:22
by oz8hp
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?
Posted: Mon 23 Nov 2009 06:15
by oz8hp
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;
Posted: Mon 23 Nov 2009 08:06
by Plash
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.
Posted: Mon 23 Nov 2009 08:23
by oz8hp
And where to put that?
(I am still learning all the wonderfull things UniDAC can do)
Posted: Mon 23 Nov 2009 08:56
by oz8hp
I can do it if a put a visual UniScript component on my main form.
Posted: Tue 24 Nov 2009 09:26
by Plash
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.
Posted: Tue 24 Nov 2009 09:36
by oz8hp
My code is not in a form unit - it is in a codeunit.
So I have no idea of how to do it

but for now it is working. Then the tweaking can come later on.