Best way to compare databases?

Find and share HowTos to various installations / configurations!
6 posts • Page 1 of 1
NikolayLevchenko
Posts:74
Joined: Wed May 10, 2017 3:34 pm

Best way to compare databases?

Post by NikolayLevchenko »

Hi all,

Let's say I want to do some reasonable big change to a project (or already did). Let's say I have a previous backup of the project before the change. What I would really like to do is compare them. I'm not so worried about panels and scripts, they are easy to compare (WinMerge, etc.). What I want to make sure is that (for example):
1. No DP's got deleted or added
2. No DPT's changed
3. DPE's didn't have their Modbus address changed, or alert class, or archiver config.
4. etc.

The only way I can see to do this is to do a full ASCII export from both projects and then compare them section by section ("# DpType", "# Datapoint/DpId", "# PeriphAddrMain", etc.).

Unfortunately, this is a VERY tedious process. Datapoints can move up and down, manager numbers changes, etc.The best I found so far is EXCEL with VLOOKUP functions, but my god this is slow and painful.

Anyone came up with any better ways to compare databases to identify differences?

RudiKreiner
Posts:198
Joined: Mon May 16, 2011 2:10 pm

Re: Best way to compare databases?

Post by RudiKreiner »

I would write a script to make a dump to a file of everything that is of interest, then compare then with your favorite text file diff tool
Note that the dpNames() function returns datapoints in alphabetical order so that should solve your problem of things moving up and down.

Here is some quick and dirty code to read all datapoints of interest and their associcated address references.
If you understand this then you can expand it to meet your requirements:

dynstring dps = dpNames(*.**); // I'm not sure if this also includes the internal datapoints whose names begin with _ and I'm not sure if you want those

alternatively you can write it like this with all the patterns that you need to get the datapoints that you want.

dynstring dps = dpNames(A*.**);
dynAppend(dps, dpNames(B*.**));
dynAppend(dps, dpNames(C*.**));


then read the values of all the configs that you need, this example assumes that all dps have address references,
if yours don't then you may need to read and check the config _address.._type of each dp first.

dynstring adr_ref_dps = dps;
for (int i = 1 i

NikolayLevchenko
Posts:74
Joined: Wed May 10, 2017 3:34 pm

Re: Best way to compare databases?

Post by NikolayLevchenko »

Thanks Rudi,

I started leaning that way, too.

ASCII export tool just seems to be too unpredictable for the purposes of comparison. With custom made scripts at least there is control over order and you can throw away all other irrelevant mismatch-causing stuff (timestamps, manager).

RudiKreiner
Posts:198
Joined: Mon May 16, 2011 2:10 pm

Re: Best way to compare databases?

Post by RudiKreiner »

I agree totally.

You need to write some code, but if you know what you are doing and use dynamic variables, it goes quite fast and you can customize it and format it to match your exact needs.

Good luck ;)

leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

Re: Best way to compare databases?

Post by leoknipp »

If you have a lot of dp elements in your project reading all the information by using dpGet() will take a lot of time. Especially as you have to make the check for every single dp-element, even if the result will be that the config does not exist.

Instead of using dpNames several times you could read all datapoints with one command and make afterwards a dynSort.


From my point of view it might be easier to export the information using the ASCII manager in a single file for every section, e.g. a list of datapoints (filter D), a list of all _address configs (filter P + _address), ...

This file is then opened with Excel, sorted by the dp element name and saved again.
If the ASCII format differs, e.g. the column for the manager ID and user is only added to the ASCII file in newer version, this column can be removed before saving the file.
Then it should be able to compare files of a different project version.

Best Regards
Leopold Knipp
Senior Support Specialist

NikolayLevchenko
Posts:74
Joined: Wed May 10, 2017 3:34 pm

Re: Best way to compare databases?

Post by NikolayLevchenko »

Thanks Leopold, that's what I've resorted to for now. Very tedious though :-(

6 posts • Page 1 of 1