Solved

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

Posted on 2000-03-29
4
119 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
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:
SurferJoe 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now