Solved

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

Posted on 2000-03-29
4
124 Views
Last Modified: 2010-04-04
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
Comment
Question by:posconsultant
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Expert Comment

by:florisb
ID: 2668600
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
 

Expert Comment

by:mrissmann
ID: 2675349
I'll let you reinvent this too.
0
 
LVL 4

Accepted Solution

by:
Greg Rowland earned 150 total points
ID: 2728978
TBatchMove can be tamed into doing it.
0
 

Author Comment

by:posconsultant
ID: 2730675
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert GUI app into console app for Win32 Env 5 125
Convert a string into a TDateTime 5 72
Delphi Yen format 3 62
Drag & Drop... Data from one grid to another 2 47
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question