• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 137
  • Last Modified:

How do I create a database on the fly in an install program?

I'm doing an install program in Delphi 5.  I need to create a DB on the fly for Oracle 7/8 and SQL Server 6.5/7 via scripts.  I have experience doing data manipulation stuff in Delphi but not DDL.  Anyone who can point me in the right direction?  
0
posconsultant
Asked:
posconsultant
1 Solution
 
florisbCommented:
some source to create a table run-time. It's being build from an ascii file. I don't know about this for SQL Server / Oracle specific. Hope to be of some help.

Good luck,
Floris.

procedure TForm1.personAsciiToTabel(personAsciiNaam: TFileName);
var
   Naam, tmp, seperator {afdelingstr }: string;
   personeels_nummer, i, waarde, telefoon, afdeling, badge, pin : integer;
   PersonBestand: TStringList;

begin
seperator := ';';
with tblPersoon do
  begin
  Close;
  DatabaseName := tempData;
  TableName := 'persoon.db';
  TableType := ttParadox;
  Exclusive := False; {Meerdere gebruikers mogen de tabellen benaderen, toch ??!?!?!?}
  with FieldDefs do
    begin
    Clear;
    Add('Naam', ftString, 25, True);
    Add('Salarisnr', ftInteger, 0, True);
//    Add('Afdeling', ftInteger, 0, True);
    end;
  try
     CreateTable;
  except on EDBEngineError do
         error(12);
  end; {einde try}
  Close;
  Open;
  Edit;
  end; {with}

PersonBestand := TStringList.Create;

if not(fileexists(personASCIINaam)) then
   error(13);


try
   PersonBestand.LoadFromFile(PersonASCIINaam);
except on EFOpenError do
   error(14);
end; {try}

for i := 0 to PersonBestand.Count-1 do
  try
    begin
    tmp := PersonBestand.Strings[i];
    pin  := StrToInt(LeesVeld(tmp,false,seperator));
    badge := StrToInt(LeesVeld(tmp,false,seperator));
    waarde := StrToInt(LeesVeld(tmp,false,seperator));
    Naam := LeesVeld(tmp,false,seperator) + ', ' + LeesVeld(tmp,false,seperator);
    Afdeling  := StrToInt(LeesVeld(tmp,false,seperator));
    LeesVeld(tmp,false,seperator);
    Telefoon := StrToInt(LeesVeld(tmp,false,seperator));
    personeels_nummer := Waarde + Telefoon - Afdeling - Badge + PIN;
    /// Afdeling aanpassen, alleen laatste 4 cijfers nodig:
{    afdelingstr := inttostr(afdeling);
    Afdelingstr := Copy(afdelingstr, length(afdelingstr)-3, length(afdelingstr) );
    afdeling := strToInt(afdelingstr);}
    try
       tblPersoon.AppendRecord([Naam, Personeels_nummer]);
    except on EDatabaseError do
           error(15);
    end;
    end;
  except on EConvertError do
         error(16);
  end; {try}

try
  tblPersoon.Active := true;
except on EDatabaseError do
       error(17);
end;
end;
0
 
mrissmannCommented:
I'll let you reinvent this too.
0
 
Greg RowlandSoftware Designer, SysDBA, WebMaster OwnerCommented:
TBatchMove can be tamed into doing it.
0
 
posconsultantAuthor Commented:
OK, figured this out:

begin
  //do we need to install?
  case DBInstallType of
    idInstallLater:  exit;
    idAlreadyInstalled: exit;//deprecated
    idInstallNow:
      begin
        try
          tempDB := TDatabase.Create(nil);
          tempQuery := TQuery.Create(nil);
          tempDB.AliasName := 'abc';
          tempDB.LoginPrompt := false;
          tempDB.DatabaseName := 'tempDB';
          tempDB.params.Add('USER NAME:bob');//UserName
          tempDB.params.Add('PASSWORD:bob');//+DBPassword
          tempQuery.DatabaseName := 'tempDB';
          tempDB.connected := true;
          scriptPath :=  GetDestDir + '\abc\Server\Scripts';
          tempStringList := TStringList.Create;
       
          with tempQuery do
          begin
            sql.loadfromFile( scriptPath + '\test.sql');
            //sqlStatement := sql.Text;
            Prepare;
            ExecSQL;
            SQL.Clear;
            tempStringList.Clear;
            tempStringList.LoadFromFile( scriptPath + '\def.sql');
           // SQL.loadfromFile scriptPath + '\VDMS.sql');// Text := tempStringList.Text;
            Prepare;
            ExecSQL;
            SQL.Clear;
            tempStringList.Clear;
            tempStringList.LoadFromFile( scriptPath + '\ghi.sql');
            SQL.Add(tempStringList.Text);
            Prepare;
            ExecSQL;
          end;
          showMessage('Database created');
          tempDB.connected := false;
          tempDB.free;
          tempStringList.free;
          tempQuery.free;
        except
          on E: Exception do
          begin
            tempDB.free;
            tempStringList.free;
            tempQuery.free;
            MessageDlg(E.Message, mtError, [mbOk], 0);
          end;
        end;
      end;
    end;
end;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now