Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I diff 2 SQLite files?

Tags:

sqlite

diff

ide

Using SQLite-manager (in its XUL form) on a Mac.

How can I diff a SQLite file from one submitted by someone else on the team, and incorporate his changes?

Thanks.

like image 297
Traveling Tech Guy Avatar asked Jan 02 '11 20:01

Traveling Tech Guy


People also ask

What is Sqldiff?

The sqldiff.exe binary is a command-line utility program that displays content differences between SQLite databases. Example usage: sqldiff [options] database1.sqlite database2.sqlite. The usual output is an SQL script that will transform database1. sqlite (the "source" database) into database2.

Can SQLite have multiple schemas?

In SQLite, a schema name is the name of an attached database. So it is not possible to have multiple schemata within the same database.

Is SQLite and sqlite3 the same?

SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. The sqlite3 has no synonyms but sqlite has sqlitedatabase as a solitary synonym. Normally version tags are used for questions about features specific for that version.

Does SQLite support multiple databases?

Yes, SQLite explicitly supports multi-database transactions (see https://www.sqlite.org/atomiccommit.html#_multi_file_commit for technical details).


2 Answers

I believe you could use the following, in combination:

$ diff sqlite-file-1.sql sqlite-file-2.sql > sqlite-patch.diff $ patch -p0 sqlite-file-1.sql sqlite-patch.diff 

I hope that works for you. Otherwise, I highly suggest consulting the man-pages:

$ man diff $ man patch 

EDIT: Alright, here's the whole walk-through.

First, dump the databases:

$ sqlite test1.sql .dump > test1.sql.txt $ sqlite test2.sql .dump > test2.sql.txt 

Next, generate a diff file:

$ diff -u test1.sql.txt test2.sql.txt > patch-0.1.diff 

And, finally, to apply the patch:

$ patch -p0 test1.sql.txt patch-0.1.diff 
like image 61
nesv Avatar answered Sep 20 '22 08:09

nesv


We can use the sqldiff Utility Program:

https://www.sqlite.org/sqldiff.html

It will compare the source to the destination databases and generate SQL commands to make source equivalent to destination.

  • Any differences in the content of paired rows are output as UPDATEs.
  • Rows in the source database that could not be paired are output as DELETEs.
  • Rows in the destination database that could not be paired are output as INSERTs.

We have to download the sources and compile it, from the tool folder.

like image 37
Bernardo Ramos Avatar answered Sep 18 '22 08:09

Bernardo Ramos