AccdbMerge supports its own scripting language that can be used from the command line and has a lot of features provided by the Standard version GUI. Unlike the rest of KS DB Merge Tools, AccdbMerge command line tool is available only on Windows because of database engine dependencies. The tool requires a Standard license.
Here is the script example which copies all data from Northwind DB to the blank database with the same structure:
LogTo( fileName: 'c:\temp\myLog.txt', ifExists: Append, addTimestamp: true, bufferSize: 100); Set $db1 = DbOpen(fileName: 'c:\test\Northwind.accdb'); Set $db2 = DbOpen(fileName: 'c:\test\NorthwindBlank.accdb'); /* DependencyLevel sorting: process tables without foreign keys first, than tables dependant on processed tables and so on:*/ ForEach $table in GetCommonTables( nameRegex: '', commonPrimaryKey: true, sortBy: DependencyLevel, sortOrder: Asc, sortByDependencyLevelDb: $db1) DataMerge( changeType: New, fromDb: $db1, toDb: $db2, fromTable: $table);
Save such kind of text to text file with .ksdms extension and use the following command to run this script (if you use 32-bit Access and AccdbMerge, then AccdbMergeCmd64.exe should be replaced with AccdbMergeCmd.exe):
"c:\Program Files (x86)\AccdbMerge\AccdbMergeCmd64.exe" myscript.ksdms /forcescriptrun
To verify script syntax without execution, you can use /checkOnly switch:
"c:\Program Files (x86)\AccdbMerge\AccdbMergeCmd64.exe" myscript.ksdms /checkOnly
It will parse the script, validate its syntax and report to console output if it has any errors. You can also use the Script Editor application to prepare scipts: it has syntax highlight, allows to check and run scipts and shows the exit code and console output of AccdbMergeCmd.exe:
For many typical diff & merge tasks script can be generated automatically using the 'Generate automation script stub' toolbar button. Just click that button and application will generate a draft script for the current tab and open Script Editor application with that script. You will have to do few adjustments (like specify log file path) and script is ready for further testing and execution.
Application supports both /windows and --linux styles to define command line parameters. Parameters listed in the tables below are case-insensitive.
Parameter | Description |
---|---|
/? --? /help --help |
Show help, it is also shown if no or invalid parameters specified |
/checkonly --checkonly -c |
Validate script syntax without execution and print found errors |
/forcescriptrun --forcescriptrun -f |
Force execution of data or objects merge/delete functions , otherwise script execution is stopped with exit code 10 ('Deny script run' error) |
Here are the most common rules of this scripting language:
Set $selObjects = | Name | | dbo.vContactInfo | | dbo.vSalesPerson | ;
Here are some application features which are currently can be done only using GUI but not supported by scripting for now:
Generate a data diff summary report, similar to the Export in the Batch data diff tab.
Parameter | Type | Optional | Default value | Description |
---|---|---|---|---|
changeType | Custom | Yes | All |
Specify which tables needs to be exported: All - all tables, regardless of their Total/New/Changed count values New - only tables having new rows Changed - only tables having changed rows or those which have different Total value NewAndChanged - union of New and Changed rows |
calcType | Custom | Yes | Total |
Specify which counts are calculated: Total - only Total counts TotalAndNew - only Total and New counts All - calculate all counts |
showTables | Boolean | Yes | True (*) | Include regular tables |
showViews | Boolean | Yes | False (*) | Include views |
showCustomMappings | Boolean | Yes | False (*) | Include custom mappings from the diff profile which was loaded previously with LoadDiffProfile(). Mapping should be marked as 'Show in Batch data diff' |
showCustomQueries | Boolean | Yes | False (*) | Include custom queries from the diff profile which was loaded previously with LoadDiffProfile(). Queries should be marked as 'Show in Batch data diff' |
dataSlice | String | Yes | True | Open data slice from from the diff profile which was loaded previously with LoadDiffProfile(). |
fileName | String | No | Report file name, with .xlsx or .json file extension |
(*) These defaults are valid for non-data-slice mode. If data slice is specified, then default is True if data slice has corresponding objects, similar to behavior of the Batch data diff tab.
Delete data from the given table of the given database. You can specify second database to compare and delete only new/changed/both rows.
Parameter | Type | Optional | Default value | Description |
---|---|---|---|---|
changeType | Custom | No | All |
Specify which rows needs to be deleted: All - all table rows New - only rows that are new comparing to another database Changed - rows that exist in both DBs but have different values NewAndChanged - union of New and Changed rows |
fromDb | Database variable | No | Database to be processed | |
table (synonym: fromTable) | String or variable | No | Table needs to be processed, either string with table name or table variable returned from GetCommonTables() function call | |
comparedToDb | Database variable | Yes | Database to compare and identify New/Changed/NewAndChanged rows | |
onError | Custom | Yes | Proceed | Error processing logic: Proceed - skip failed row and proceed to process the rest StopCommand - stop current DataDelete execution and don't process rest of rows StopScript - stop the whole script execution |
withTransaction | Boolean | Yes | False | Process all rows as a single transaction. If onError is not Proceed, then changes will be applied as all or nothing. Using transactions can also improve performance |
fileName | String | Yes | Save generated SQL script to the specified .sql file (instead of execution) | |
ifExists | Custom | Yes | Append |
Behavior if fileName already exists. StopScript - stop script execution Overwrite - overwrite existing file Append - append new sql statements at the end of existing file |
Generate a data diff report for the given table, view, custom mapping or custom query; similar to the Export in the Data diff or Query result diff tabs.
Parameter | Type | Optional | Default value | Description |
---|---|---|---|---|
tableType | Custom | Yes | Table |
Table object type: Table - regular table View - view CustomMapping - custom mapping from the diff profile which was loaded previously with LoadDiffProfile() CustomQuery - custom query from the diff profile which was loaded previously with LoadDiffProfile() |
table | String or variable | No | Table that needs to be processed, either string with table name or table variable returned from GetCommonTables() function call | |
changeType | Custom | Yes | All |
Specify which rows needs to be exported: All - all table rows New - only rows that are new comparing to another database Changed - rows that exist in both DBs but have different values NewAndChanged - union of New and Changed rows Unchanged - rows that exist in both DBs and have no different values |
limit | Number | Yes | 0 | Max number of rows to put into file, specify 0 to include all rows |
fileName | String | No | Report file name, with .xlsx or .json file extension |
Merge data of the given table from one database to another
Parameter | Type | Optional | Default value | Description |
---|---|---|---|---|
changeType | Custom | Yes |
Specify which rows needs to be merged: New - only rows existing in source and missing in target Changed - rows that exist in both DBs but have different values NewAndChanged - union of New and Changed rows |
|
fromDb | Database variable | No | Source database | |
table (synonym: fromTable) | String or variable | No | Table needs to be processed, either string with table name or table variable returned from GetCommonTables() function call | |
toDb | Database variable | No | Target database | |
identityInsert | Boolean | Yes | True | If target table ID column is identity/autoincrement: True - import ID values from the source database, False - ignore source ID values, generate new ID values for imported rows. Note that in this case processed rows will keep to be considered as New by application because they will have different IDs |
updateOnlyChanged | Boolean | Yes | False | If the generated script will contain UPDATE statements, it can include all or only changed column values. In the last case, script will not be generated for unchanged rows. |
onError | Custom | Yes | Proceed | Error processing logic: Proceed - skip failed row and proceed to process the rest StopCommand - stop current MergeData execution and don't process rest of rows StopScript - stop the whole script execution |
withTransaction | Boolean | Yes | False | Process all rows as a single transaction. If onError is not Proceed, then changes will be applied as all or nothing. Using transactions can also improve performance |
fileName | String | Yes | Save generated SQL script to the specified .sql file (instead of execution) | |
ifExists | Custom | Yes | Append |
Behavior if fileName already exists. StopScript - stop script execution Overwrite - overwrite existing file Append - append new sql statements at the end of existing file |
Run SQL statement on the specified database.
Parameter | Type | Optional | Default value | Description |
---|---|---|---|---|
db | Database variable | No | Target database | |
sql | String | No | SQL statement to run |
Specify database connection and return its reference as a variable. Connection string specified as for .NET SqlClient, see https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/connection-string-syntax
Parameter | Type | Optional | Default value | Description |
---|---|---|---|---|
connectionString | String | No | Connection string text |
Returns a list of table names that exists in both databases. This list can be used only inside the ForEach statement, see example above.
Parameter | Type | Optional | Default value | Description |
---|---|---|---|---|
nameRegex | String | Yes | Regex filter by table name | |
sortBy | Custom | Yes | Name |
Specify by which table attribute we need to sort result: Name - by table name DelendencyLevel - by table dependency level. See Table DL for more information. |
sortByDependencyLevelDb | Database variable | See description | Each database has its own foreign keys and dependency level of the same tables can be different. If we do sorting by DependencyLevel - this parameter becomes mandatory. Otherwise it is optional | |
sortOrder | Custom | Yes | Asc |
Specify sort order: Asc - ascending Desc - descending |
commonPrimaryKey | Boolean | Yes | If True - return only tables which have the same primary key definition in both databases, if False - only different. If not specified - return all tables |
Load specified diff profile to process its items (custom mappings, queries and data slices). 'Load on start' diff profile option is not applied for AccdbMergeCmd. Necessary diff profile needs to be loaded in the script using this LoadDiffProfile() function.
Parameter | Type | Optional | Default value | Description |
---|---|---|---|---|
fileName | String | No | Diff profile file name |
Add text to the log
Parameter | Type | Optional | Default value | Description |
---|---|---|---|---|
text | String | No | Text of log entry |
Setup logging settings
Parameter | Type | Optional | Default value | Description |
---|---|---|---|---|
fileName | String | No | Log file name | |
ifExists | Custom | Yes | Append |
Behavior if fileName already exists. StopScript - stop script execution Overwrite - overwrite existing file Append - append new log entries at the end of existing file |
addTimestamp | Boolean | Yes | True | Specify timestamp of log entries |
logDataResult | Boolean | Yes | True | Add an entry on each processed row like 'Merging [DatabaseLogID] = 1.. Done.' |
logDataScript | Boolean | Yes | False | Add entry of each executed INSERT/UPDATE/DELETE statement |
logConnectionString | Boolean | Yes | False | During database open, add to the log database connection string (as is, including passwords if any) |
bufferSize | Number | Yes | 0 | Write log entries in batch mode, can improve performance, but some log entries can be lost in case of abnormal program termination |
Last updated: 2025-02-18