Import Shearwater Desktop divelog database

Sqlite database from Shearwater Desktop log software is imported. Just
the basic information like location, buddy, notes and dive profile
(depth and temperature).

This is tested with a DB in Imperial units, thus metric input might
contain errors.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Miika Turkia 2014-02-15 08:36:50 +02:00 committed by Dirk Hohndel
parent 4b949936c2
commit 62e313df35
3 changed files with 129 additions and 3 deletions

25
file.c
View file

@ -151,9 +151,17 @@ static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, char
return 0;
}
int db_test_func(void *param, int columns, char **data, char **column)
{
return *data[0] == '0';
}
static int try_to_open_db(const char *filename, struct memblock *mem, char **error)
{
sqlite3 *handle;
char dm4_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%ProfileBlob%'";
char shearwater_test[] = "select count(*) from sqlite_master where type='table' and name='system' and sql like '%dbVersion%'";
int retval;
retval = sqlite3_open(filename, &handle);
@ -163,7 +171,22 @@ static int try_to_open_db(const char *filename, struct memblock *mem, char **err
return 1;
}
retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, &dive_table, error);
/* Testing if DB schema resembles Suunto DM4 database format */
retval = sqlite3_exec(handle, dm4_test, &db_test_func, 0, NULL);
if (!retval) {
retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, &dive_table, error);
sqlite3_close(handle);
return retval;
}
/* Testing if DB schema resembles Shearwater database format */
retval = sqlite3_exec(handle, shearwater_test, &db_test_func, 0, NULL);
if (!retval) {
retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, &dive_table, error);
sqlite3_close(handle);
return retval;
}
sqlite3_close(handle);
return retval;