DBEXPORT procedure
Update data in an ODBC database table using GenStat data, PC Windows only (D.B. Baird).
Options
Parameters
Description
DBEXPORT can be used to add either a new table to an ODBC data source (METHOD=create), add rows to an existing table (METHOD=insert), or update rows in an existing table (METHOD=merge).
The form of the DB connection string can be found by saving a ODBC Query in the GenStat client in a GDB file (using the Spread > New > ODBC Query menu in GenStat for Windows) and then examining this file with a text editor. The second line contains the database connection string.
The data to be sent can either be specified as a pointer to a set of structures in GenStat or a text giving a GenStat spreadsheet (GSH) file. The DATA parameter need not be set if a GLKFILE is specified, as this may point to an existing GSH file. If a GLKFILE is provided, all options and parameters will be taken from this, with the exception that a different DATA set and/or TABLENAME can be provided and this will be used with the existing parameters from the GLKFILE. A GLKFILE can be created using the Spread > Export menu items and using the Save Export Link option in these menus.
The column names within the ODBC table are assumed to be the same as the GenStat identifiers, unless you specify COLUMNNAMES and WITH (for matching with MATCH).
If COLMERGEMETHOD=omit, any columns in the data not found in the database table will be omitted; otherwise new columns will be added to the existing table. The SUBSET parameter can be set to pick a subset of columns from an existing GSH file. However if DATA is set to a pointer, it would be normal to only form this to contain only the elements that you wanted updated in the table, instead of using the SUBSET parameter.
If METHOD=merge, the MATCH parameter must be set. At most only five columns can be matched. The WITH parameter may be set if the columns in the table do not have the same names as the structures used in the DATA parameter. The ROWMERGEMETHOD option controls how unmatched rows are handled in a merge: the setting none does not add unmatched rows, the setting matched only adds a row if another with the same matching criteria already existing in the table, and all adds in all unmatched rows into the table.
If the WARNINGDIALOGS option is set to display, message boxes will pop up on the windows desktop detailing any errors; the setting omit suppresses the warning messages. The GenStat server will wait until the user clicks OK on these, so this will halt any processing, and is better not used in batch jobs. If option ERRORACTION=stop, any warnings (such as not being able to add missing values into a column or not being able to add rows with duplicate ID's) will cause the update to stop; otherwise all valid data will be added to the table, unless a fatal error occurs.
(Note: DBEXPORT replaces the procedure %ODBCUPDATE from earlier editions of GenStat.)
Options: METHOD, ROWMERGEMETHOD, COLMERGEMETHOD, OMIT, ERRORACTION, WARNINGDIALOGS, GLKFILE.
Parameters: DATA, DB, TABLENAME, COLUMNNAMES, SUBSET, MATCH, WITH.
Method
The structures in DATA are saved to a GSH file using FSPREADSHEET. A GLK file is built using the supplied parameters or an existing GLK file, and then this is passed to the ODBCLOAD.DLL library to be processed.
Action with
RESTRICT
Restrictions on the structures are obeyed if OMIT=restricted, otherwise they are ignored. If the restrictions on the structures are not consistent, a fault will occur.