summaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2014-02-15 08:36:50 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-02-14 22:46:35 -0800
commit62e313df35df7319005b49b6011717ec0bc70088 (patch)
treebd000ecd112a9469236f819c362191ed966c2fc7 /file.c
parent4b949936c26d5689c331d7c7e25b8c130e97c0e5 (diff)
downloadsubsurface-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.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/file.c b/file.c
index b218a13e2..08b61b234 100644
--- a/file.c
+++ b/file.c
@@ -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;