5 Database Utilities

The dbexport and dbimport Programs

The two program files, dbexport and dbimport, are used to copy the entries in data sets of a database to and from ASCII files. The database structural information is not saved. These two program files are useful when restructuring a database.

dbexport

The HP-UX program file dbexport copies data entries from all or selected data sets to ASCII files (see Appendix for format description). There are two export modes - multiple files and single file.

If exporting into multiple files the contents of each data set is written into a separate file. These export files are named database_name.dataset_number.exp. This is the default export mode. We recommend using a directory to hold all export files of a database.

If exporting into a single file, you can choose any filename or stdout.

The dbexport command must be executed from the operatind system prompt. Syntax of the command is as follows:

dbexport [options] database [data set [ data set ] . . .] ] ]

Options:

-u user
Specify user id. The user name is obtained by default from the LOGNAME or USER environment variable.
-p password
Specify password. When using the eloqdb5 server, this must be the maintenance password of the database.
-v
Detailed listing of procedures. -v stands for "verbose".
-o path
Enter directory where export (.exp) files should be created. If -o path is not used, the export files are created in the current directory. This option cannot be used with the single file option.
-c
chained export
-a
export automatic sets
-r
create restructure information
-f sep
Specifies a different field separator. The default field separator is comma (','). With this option dbexport utility program may be used to export data from a Eloquence database to an external application.
-s file
output into single file, '-' = stdout
databasename
Enter name of database to be exported.
dataset
Enter name or number of the data set to be exported. If no data set names are specified, all data sets associated with the named database are exported.
Execute the dbexport command as shown:

dbexport -p secret -v -o sadexp SAD
This command exports the data from all SAD data sets to export files (SAD.03.exp, SAD.04.exp, SAD.05.exp, and SAD.06.exp). SAD data sets 01 and 02 are defined in the root file as automatic data sets and are therefore not exported. The -o sadexp option specifies that the export files are to be created in the sadexp directory. The -p secret option specifies the user password.

NOTE: Data sets of type automatic master are filled automatically by dbimport. These data sets are not exported by dbexport, unless option -a is used with dbexport. However, automatic sets are not imported from exported files, but are built up during the loading of corresponding detail data.

Display:

B1368B DBEXPORT (C) COPYRIGHT MARXMEIER SOFTWARE AG 2002 (A.06.00)
Processing database : SAD
Export path         : sadexp

DATA SET              Records   Count
---------------- -- - --------  --------
DATE             01 A       11
ORDER            02 A       11
PRODUCT          03 M        5         5
LOCATION         04 M        1         1
OPTION           05 D       16        16
CUSTOMER         06 D       11        11
  |              |  |        |         |
  Data Set Name   |  |        |         Number of exported entries counted
                 |  |        |
                 |  |        Number of entries in the data set
                 |  |
                 |  Data Set Type
                 |    A = Automatic Master
                 |    M = Manual Master
                 |    D = Detail
                 |
                 Data Set Number
NOTE: If a data set contains no entries, no export file will be created for that data set.

dbimport

The HP-UX program file dbimport copies data from export files into the entire database or to selected data sets. Dbimport can be used to restructure an existing Eloquence database, as outlined in page 135 . In such instances, dbimport copies data from export files, created by dbexport, into a database. Dbimport can also be used to import data from export files created by an application program.

NOTE: Files to be imported must have the naming format databasename.datasetnumber.exp. Therefore, if you use an application program to dump data to a file that you plan to use dbimport on later, make sure that data is dumped to a file named databasename.datasetnumber.exp.

The dbimport command must be executed from the operating system prompt. Syntax of the command is as follows:

dbimport [options] database [data set [ data set ] . . .] ] ]

Options:

-u user
Specify user id. The user name is obtained by default from the LOGNAME or USER environment variable.
-p password
Specify password. When using the eloqdb5 server, this must be the maintenance password of the database.
-v
Detailed listing of procedures. -v stands for "verbose".
-i path
Enter directory where export (.exp) files are situated. If -i path is not used, program looks in current directory.
-p pswd
Enter database password with write access.
-d
trace item value assignment
-r file
restructure database. '-' = no file
-s file
import from single file, '-' = stdin
-f sep
Specifies a different field separator. The default field separator is comma (','). With this option dbimport utility program may be used to import data into a Eloquence database from an external application.
databasename
Enter name of database to receive the data.
dataset
Enter name or number of the data set to be imported into the database.
Execute the dbimport command as shown:

dbimport -v -i sadexp -p secret SAD
This command imports the data from the SAD export files (SAD.03.exp, SAD.04.exp, SAD.05.exp, and SAD.06.exp) into the .idx and .dat files created using dbcreate. SAD data sets 01 and 02 are defined in the root file as automatic data sets and are therefore filled automatically when dbimport is executed.

The -i sadexp option specifies that the export files are in the sadexp directory. The -p secret option specifies the user password.

Display:

B1368B DBIMPORT (C) COPYRIGHT MARXMEIER SOFTWARE AG 2002 (A.06.00)

Processing database: SAD
Import path        : sadexp

DATA SET              Count
---------------- -- - --------
DATE             01 A
ORDER            02 A
PRODUCT          03 M        5
LOCATION         04 M        1
OPTION           05 D       16
CUSTOMER         06 D       11
  |              |  |        |
  Data Set Name  |  |        Number of imported entries counted
                 |  |
                 |  Data Set Type
                 |    A = Automatic Master
                 |    M = Manual Master
                 |    D = Detail
                 |
                 Data Set Number
NOTE: If you attempt to import a file that does not follow the naming conventions databasename.datasetnumber.exp, the following message appears: export file name: No such file or directory.

NOTE: If a detail data set contained no entries, no export file will be created for that data set and the following message appears: export file name: No such file or directory.

Database Restructuring with dbimport

If you specify the -r file option in the commandline, dbimport will operate in restructure mode. In this mode, dbimport will load data sets/items on a symbolic base. Data sets and items are identified by name rather than number or position in record. Unless you have changed set or item names, or you want to initialize new data sets or items, you don't need to worry about the database reload process.

dbimport restructure file syntax

IMPORT SET data set [ = data set]
{
   item spec = item spec;
   item spec = :NULL;
   item spec = :CONST constant;
   ...
}
data set
data set name or number
item spec
item name or number. If data item is defined with a subitem count (array) you may handle item elements individually. For example:
ITEM

this will specify all elements

ITEM [1]

this will specify first element

ITEM [1-3]

this will specify elements 1 to 3

:NULL
initialize item with default value. This is zero for any numeric item type or spaces for strings. This is the default for new items.
:CONST
initialize item with constant value. Only integer or string constants may be specified here. So you have to specify a LONG or SHORT constant as a string constant (eg. "3.1415").
All characters past '#' (unless in a quoted string) will be ignored until end-of-line.

NOTE: For the database to be loaded, data set/item names are taken from the ROOT file. For the export file(s) the data set/item names are saved by the dbexport utility if run with the -r option. If no data set/item names are saved in the export file(s) (dbexport not run with -r option) you have to specify each item that has a different position in the export set.

Formal syntax specification

    T_NUMBER = positive integer constant

    import_spec:
      /* empty */
      | set_spec import_spec

    set_spec:
       IMPORT SET to_set from_set
        set_spec_item_part

     set_spec_item_part:
      /* empty */
      | "{" item_spec_list "}"

     to_set:                          /* target set */
      set name | set number

     from_set:                       /* set in import file */
      /* empty */ | "=" set name | "=" set number

     item_spec_list:
       /* empty */
       | item_spec item_spec_list

     item_spec:                      /* item conversion spec */
      to_spec "=" from_spec ";"

     to_spec:                        /* target item (range) */
      to_item range_spec

      to_item:
       item name | item number

      from_spec:
        T_NUMBER                    /* field number in exported record */
        | item_name                 /* or exported field name (range) */
        | ":NULL"                   /* NULL (default) value */
        | ":CONST" T_NUMBER         /* integer constant */
        | ":CONST" string_in_quotes /* string constant */


      range_spec:                   /* array element range */
        /*  empty */
        | "[" T_NUMBER "]"
        | "[" T_NUMBER "-" T_NUMBER "]"

Example 1:

# Import set CUSTOMER from ACCOUNTS
IMPORT SET CUSTOMER = ACCOUNTS

# Fill PRODUCT from ORDER
IMPORT SET PRODUCT = ORDER
{
   PRODUCT-NO = ORDER-NO;
   PROD-DESC  = :CONST "* Unknown *";
   # all other default
}

Example 2:

New database layout ...                        Old database layout ...

    ITEMS:                                       ITEMS:

      ORDER-NO,      X8;                            ORDER-NO,      X8;
      PRODUCT-NO,    X6;                            PRODUCT-NO,    X6;
      QUANTITY,      I;                             QUANTITY,      I;
      SHIPMENT-DATE, X4;                            SHIPMENT-DATE, X4;
      QTY-AVAIL,     I;                             ARRAY,         3I;
      ARRAY,         4I;

      SETS:                                        SETS:

   N: ORDER-DETAIL D(/0);                       N: PRODUCTION D (/0);
   E: ORDER-NO,                                 E: ORDER-NO,
      PRODUCT-NO,                                  PRODUCT-NO,
      QUANTITY,                                    QUANTITY,
      SHIPMENT-DATE,                               SHIPMENT-DATE,
      QTY-AVAIL,                                   ARRAY;
      ARRAY;

Figure 8 Example of new layout

Database reload process...

You want to load your new data set ORDER-DETAIL from your old data set PRODUCTION. All data items should be taken from the the old data set with the following exceptions:

Your import specification file should contain...

     IMPORT SET ORDER-DETAIL = PRODUCTION
     {
        QTY-AVAIL = QUANTITY;
        QUANTITY  = :NULL;
        SHIPMENT-DATE = :CONST "0000";
        ARRAY[1-2] = ARRAY[1-2];
        ARRAY[4] = ARRAY[3];
        ARRAY[3] = :CONST 1;
     }

Eloquence Database Manual - 19 DEC 2002