Command to change the database structure

This forum is for eXpress++ general support.
Message
Author
User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Command to change the database structure

#1 Post by Eugene Lutsenko »

How easy is it to change the database structure with such:

Code: Select all

   aStructure := { { "KOD_OpSc"  , "N", 15, 0 }, ;
                   { "NAME_OpSc" , "C",250, 0 }, ;
                   { "INT_INF"   , "N", 19, 7 }, ;
                   { "SUM_II"    , "N", 19, 7 }, ;
                   { "SII_PERC"  , "N", 19, 7 }, ;
                   { "RANG"      , "N", 15, 0 }, ;
                   { "ABS"       , "N", 15, 0 }, ;
                   { "PERC_FIZ"  , "N", 19, 7 }, ;
                   { "Sum_ZnGr"  , "N", 19, 7 }, ;
                   { "N_GrOpSc"  , "N", 15, 0 }, ;
                   { "KodGr_min" , "N", 15, 0 }, ; // Минимальный  код градаций описательной шкалы
                   { "KodGr_max" , "N", 15, 0 }, ; // Максимальный код градаций описательной шкалы
                   { "Date"      , "C", 10, 0 }, ;
                   { "Time"      , "C",  8, 0 }  }
On such a:

Code: Select all

   aStructure := { { "KOD_OpSc"  , "N", 15, 0 }, ;
                   { "NAME_OpSc" , "C",250, 0 }, ;
                   { "INT_INF"   , "N", 19, 7 }, ;
                   { "SUM_II"    , "N", 19, 7 }, ;
                   { "SII_PERC"  , "N", 19, 7 }, ;
                   { "RANG"      , "N", 15, 0 }, ;
                   { "ABS"       , "N", 15, 0 }, ;
                   { "PERC_FIZ"  , "N", 19, 7 }, ;
                   { "Sum_ZnGr"  , "N", 19, 7 }, ;
                   { "N_GrOpSc"  , "N", 15, 0 }, ;
                   { "KodGr_min" , "N", 15, 0 }, ; // Минимальный  код градаций описательной шкалы
                   { "KodGr_max" , "N", 15, 0 }, ; // Максимальный код градаций описательной шкалы
                   { "N_combinat", "N", 15, 0 }, ; // Число комбинаций различных сочетаний значений факторов
                   { "Date"      , "C", 10, 0 }, ;
                   { "Time"      , "C",  8, 0 }  }
That is, how to add a field to an already existing database (in this case, this is the T_combinat field) with data saved in the database?

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Command to change the database structure

#2 Post by rdonnay »

You can use Xdot.exe to modify the structure of the database.

At the dot prompt do the following :

. USE <file name> EXCLUSIVE VIA <dbe>
. MODIFY STRUCTURE
The eXpress train is coming - and it has more cars.

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Command to change the database structure

#3 Post by Eugene Lutsenko »

rdonnay wrote: Mon Dec 06, 2021 1:32 pm You can use Xdot.exe to modify the structure of the database.

At the dot prompt do the following :

. USE <file name> EXCLUSIVE VIA <dbe>
. MODIFY STRUCTURE
Hi, Roger! Health to you!

This is understandable. In the question I mean how to do it programmatically. I wrote a small program that does this, but I thought maybe there is a command for this:
1. Then create an Opis_Sc database with a new structure
2. Copy data from the old structure to the new one
3. Close all Opis_Sc databases, both old and new
4. Rename the new one to the old one
5. Calculate the values of the new field in the new database as in Help 22()

jezda
Posts: 14
Joined: Thu Mar 28, 2019 4:41 am

Re: Command to change the database structure

#4 Post by jezda »

LOCAL astructure := {}
aStructure := { { "KOD_OpSc" , "N", 15, 0 }, ;
{ "NAME_OpSc" , "C",250, 0 }, ;
{ "INT_INF" , "N", 19, 7 }, ;
{ "SUM_II" , "N", 19, 7 }, ;
{ "SII_PERC" , "N", 19, 7 }, ;
{ "RANG" , "N", 15, 0 }, ;
{ "ABS" , "N", 15, 0 }, ;
{ "PERC_FIZ" , "N", 19, 7 }, ;
{ "Sum_ZnGr" , "N", 19, 7 }, ;
{ "N_GrOpSc" , "N", 15, 0 }, ;
{ "KodGr_min" , "N", 15, 0 }, ; // Минимальный код градаций описательной шкалы
{ "KodGr_max" , "N", 15, 0 }, ; // Максимальный код градаций описательной шкалы
{ "N_combinat", "N", 15, 0 }, ; // Число комбинаций различных сочетаний значений факторов
{ "Date" , "C", 10, 0 }, ;
{ "Time" , "C", 8, 0 } }

If file("database.dbf")
use database.dbf exclusive
If .not. dc_isstru( aStructure )
DC_STRUUPDATE( aStructure )
Endif
Else
DbCreate("database.dbf", aStructure )
Endif
USE

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Command to change the database structure

#5 Post by Eugene Lutsenko »

Thanks, Jezda, I'll take a look!

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Command to change the database structure

#6 Post by rdonnay »

I didn't know that you wanted to do it programatically.

Yes, DC_IsStru() and DC_StruUpdated() were designed for this purpose.
The eXpress train is coming - and it has more cars.

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Command to change the database structure

#7 Post by Eugene Lutsenko »

Thank you, Roger! This is exactly what you need. I remember when I was watching xdemo.exe , there was this. But I didn't find it now (there wasn't enough time to search) and just asked on the forum. Thank you again for your excellent work!

It looks like I don't have DC_LIST RU(). When compiling, it writes an error that the function is missing. I dispensed with this function, checked the structure myself. But I still wonder why I don't have this feature.

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Command to change the database structure

#8 Post by rdonnay »

DC_IsStru() and DC_StruUpdate() are in DCLIP1.DLL.

You need to include DCLIP1.LIB in your project file.
The eXpress train is coming - and it has more cars.

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Command to change the database structure

#9 Post by Eugene Lutsenko »

And where to turn it on?

Code: Select all

[PROJECT]
    TARGET_DIR    = .\run
    VERSION       = 2.3
    Project.xpj

[Project.xpj]
    __AIDOS-X.exe

[__AIDOS-X.exe]
    COMPILE              = xpp
    GUI                  = yes
    LINKER               = alink
    LINK_FLAGS           = _Aidos-X.res /PM:PM
    RC_COMPILE           = arc
    RC_FLAGS             = _Aidos-X.arc
    INTERMEDIATE_RELEASE = .release
    
// $START-AUTODEPEND
    __AIDOS-X.obj
    F4_7.obj
    F2_3_2_2.obj
    F2_3_2_11.obj
    F2_3_2_12.obj
    AddsAppls.obj
    F4_6.obj
    F4_1_2.obj
    RAIF_Challenge_2017.obj
    F6_9.obj
    
// $STOP-AUTODEPEND
    __AIDOS-X.prg
    F4_7.PRG
    F2_3_2_2.prg
    F2_3_2_11.prg
    F2_3_2_12.prg
    AddsAppls.prg
    F4_6.PRG
    F4_1_2.PRG
    RAIF_Challenge_2017.prg
    F6_9.prg

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Command to change the database structure

#10 Post by rdonnay »

Put DCLIP1.LIB in the area with your PRG files.
The eXpress train is coming - and it has more cars.

Post Reply