Solved

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

Posted on 2000-03-29
4
123 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:
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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 shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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…

856 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