Subject Re: to check if a table is exist and create one
From Akshat Kapoor <akshat.kapoor@kapoorsons.in>
Date Thu, 19 Oct 2017 11:57:35 +0530
Newsgroups dbase.getting-started

On 18/10/2017 22:03, eric wu wrote:
>
> how to re-write these codes below to a modern object-oriented
> programming codes? And to be able to work with a database alias.
>
>
> 1. to check if a table is exist
> 2. if not, create one.
>
> thanks in advance!
> Eric
>
>         
>     local f
>     f = new file()
>     if not f.exists( "c:\Issu.dbf" )
>        Create Table  "C:\Issu.dbf"  ( Name char(20),  depType char(10) )
>     endif
>     f = null

This is the code I am using
if not file(mcompany.direct+'\label0.dbf')
        cmd = 'CREATE TABLE "'+mcompany.direct+'\label0.dbf" ';
        + '(bcode char(7) default " " ,';
        + 'company char(10) default " "         , item char(10) default " " ,';
        + 'descrip char(25) default " "         ,';
        + 'mrp numeric(9,2) default 0    ,';
        + 'disc numeric(5,2) default 0        , offerp numeric(9,2)default 0,';
        + 'hsn_code char(8) default " "  ,';
        + 'tax numeric(6,2) default 0    , adtax numeric(6,2) default 0, ';
        + 'row_no numeric(8,0) default 0        )'
        ?cmd
        &cmd
else
        ?"Label0 file exists"
endif

and it is working fine. I do not use database/bde alias hence the above
code.
Be careful of word wrap.

Regards
Akshat