[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference 44.392::delphi_in_dec

Title:Borland Delphi conference
Moderator:BROUGH::DAVIES
Created:Tue Mar 12 1996
Last Modified:Fri May 30 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:33
Total number of notes:110

29.0. "Real SQL & Delphi ?" by BROUGH::DAVIES (Hype is a 4 letter word !) Thu Apr 03 1997 12:48

Does any reader of this conference know of a way to do the following:-

SQL commands such as CREATE TABLE can be done on the Database Desktop. I 
want to be able to do this from a delphi app. It seems that the SQL component
has to attact to a particular table but in this case the table does not exist.
Also the database desktop sql seems to be only a single shot device. By that
I mean that only 1 sql command can be contained in an SQL statement.

I could devise an application that uses a .ini file to create the tables but
this is not so portable. In my particular case, I have a whole bunch of
SQL scripts that build an ORACLE database and then populate it. With a bit of
minor editing (remove tablspace defs etc) I want to be able to run that into
a local database and create all the tables I need

Any thoughts ? I have scanned some sites on the web but I have not found
anything of use.

Stephen Davies


T.RTitleUserPersonal
Name
DateLines
29.145080::CWINPENNYThu May 15 1997 20:367
    
    I've taken to using ODBC and SQL and am staying clear of the specific
    Tdb controls which should make porting to any SQL database easier. I'll
    be coming across this pretty soon as the easiest way to delete a table
    is to drop it and create it again.
    
    Chris
29.245080::CWINPENNYFri May 16 1997 14:4144
    
    Start a new project and on the empty form create a standard button
    called bnCreate and add a query component called quCreate. 

    Fill in the DdatabaseName property of the query component. Double click
    on the button and enter the following code.

        procedure TfmCreate.bnCreateClick(Sender: TObject);
        begin

            quCreate.close;
            quCreate.sql.clear;
            quCreate.sql.add ('CREATE TABLE ITEMS        ');
            quCreate.sql.add ('(ItemNumber      int,     ');
            quCreate.sql.add (' Description     char(30),');
            quCreate.sql.add (' Price           float);  ');
            quCreate.ExecSql;

        end;

    Save and build the project and run the .exe from Explorer, see below.
    Clicking on the button will create the table ITEMS in your database.

    Alternatively you could use.

        quCreate.sql.LoadFromFile ('c:\project\create.txt');

    instead of the quCreate.sql.add where the file c:\project\create.txt
    contains your SQL code.

    Note that the only thing needed to start with is DatabaseName, this
    could be an empty database.

    Obviously the above template can be used to execute any SQL code you
    may need to use. By using the LoadFromFile it is possible to modify
    your SQL after the executable has been built with the disadvantage that
    so can end users.

    The only problem I've come across is that in this simple form of a
    quick example if the SQL isn't spot on, ie. you miss out a comma, then
    the program hangs. Therefore don't run it from within the development
    environment.

    Chris
29.3Import .txt === Good IdeaBROUGH::DAVIESHype is a 4 letter word !Tue May 27 1997 14:226
Chris,
	Thanks for the tip. I will not experience the SQL hanups though as
I will be importing files created by Paradox from working SQL.

Stephen Davies

29.445080::CWINPENNYTue May 27 1997 14:434
    
    The hangups probably came from not preparing the query properly.
    
    Chris