简体   繁体   中英

Java - Compare two sqlite database files

Situation is we are generating a sqlite database as an output.

I want to see if said database equals an expected database file.

So far I have been using sqlite3 to generate dumps and then comparing the files, as suggested in this question: How to compare two sqlite databases on linux .

This works well for our purposes, however I've noticed that I'm using a sqlite3 executable for linux. I am using the following code to create dumps:

// call sqlite3 .dump
Process p = Runtime.getRuntime().exec(executeCommand);

This causes the tests to fail in a Windows environment:

java.io.IOException: Cannot run program "C:\[...]": CreateProcess error=193, 
    %1 is not a valid Win32 application
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)

I think I could simply write a bunch of queries, or include all sqlite3 executables and just check for the OS and hide this behind an interface, but I thought I'd ask first to see if anyone had a simpler solution, or even a different methodology that avoids the problem entirely.

The way I understand this is that you want to make sure that the database schema (that is, tables, columns and so on) and the data itself in your SQLite databases on different systems are the same. You should use one of many database comparison tools.

SchemaCrawler for SQLite is one such - a free, cross-platform tool designed for performing database schema and data diffs, using a human readable plain-text format.

Sualeh Fatehi, SchemaCrawler

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM