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?
UniScript and MS Access
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;
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;