diff options
author | Miika Turkia <miika.turkia@gmail.com> | 2014-02-15 08:36:50 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-02-14 22:46:35 -0800 |
commit | 62e313df35df7319005b49b6011717ec0bc70088 (patch) | |
tree | bd000ecd112a9469236f819c362191ed966c2fc7 /file.c | |
parent | 4b949936c26d5689c331d7c7e25b8c130e97c0e5 (diff) | |
download | subsurface-62e313df35df7319005b49b6011717ec0bc70088.tar.gz |
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>
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -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; |