Mirroring an Sculptor database to ODBC

Sculptor can keep an ODBC database automatically synchronised with a Sculptor database. Read commands work from the Sculptor database, which is deemed to be the master. Update commands (insert, write and delete) are applied automatically to both databases.

The Sculptor database can be an explicitly defined +|-database of type DBT_SCULPTOR, with its own set of ![o]file declarations, or the default Sculptor database, which contains all independent ![o]file declarations. Not all the files in a program necessarily need to be mirrored; there may, for example, be temporary Sculptor work files which have no counterparts in the ODBC database.

The ODBC database must be declared using a –database declaration with type DBT_ODBC. This is a template database. It should not be opened and should not contain any ![o]file declarations. It must have a valid source clause defined at compile time or set dynamically at run time before being used. Other database properties such as flags and riu_timeout can also be specified, but riu_timeout should normally be 0, otherwise there is a risk that an update to the SQL database will be missed simply because the server is busy.

Since Sculptor version 6.0.0 a mirrored database can also be declared with SCULPTOR_SERVER in the source attribute, reducing network traffic substantially if the mirrored database is on the same server as the Sculptor database. This is not mandatory. The mirrored database can be local or can be accessed locally even if the source database is on a server. A mirrored database can now be either an ODBC database or a Sculptor database.

Any valid source string is acceptable. Examples:

source = "DSN=mydatasource"

source = "DRIVER=SQL Server;SERVER=myserver;DATABASE=master;UID=username;PWD=password"

source = "SCULPTOR_SERVER=myserver;DSN=mydsn"

To use this mirroring feature, a program must first call the set_mirror_source() function to define the Sculptor and ODBC databases. The mirror command is then used to specify the Sculptor files whose updates are to be mirrored to the ODBC database. Every time a record is updated in the Sculptor database, Sculptor applies the same update to the ODBC database. Sculptor also automatically inserts records and creates tables that are missing in the ODBC database.


EXAMPLE

1. This example illustrates mirroring of the default Sculptor database, i.e. files declared outside a database declaration.

/* Declare SQL database to synchronise */
-database mirrordb {
     type = DBT_ODBC
     source = "DRIVER=SQL Server;SERVER=myserver;DATABASE=master"
}

/* Declare Sculptor files */
!file FILE1 "file1"
!file FILE2 "file2"
!file FILE3 "file3"

     /* Specify databases and logfile */
     set_mirror_source(NULL, mirrordb, "myserver:c:/sclog/mirror.log", MirrorErr)

     /* Specify files to be mirrored */
     mirror FILE1, FILE2
     ...

!function MirrorErr(db){
     info "Mirror failed to database " + nameof(db)
}
  1. Mirroring a declared Sculptor database.

    -database mirrordb {
         type = DBT_ODBC
         source = "DRIVER=SQL Server;SERVER=myserver;DATABASE=master"
    }
    
    /* Declare the Sculptor database */
    +database scdb {
         type = DBT_SCULPTOR
         !file FILE1 "file1"
         !file FILE2 "file2"
    }
    
    /* This file won't be mirrored */
    !file FILE3 "file3"
    
         set_mirror_source(scdb, mirrordb, "myserver:c:/sclog/mirror.log", NULL)
         mirror FILE1, FILE2
    

RELATED TOPICS

ODBC

mirror

set_mirror_source()

Declaring an ODBC database