[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2000-03-29
4
Medium Priority
?
136 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 300 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

649 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