diff options
-rw-r--r-- | dive.h | 1 | ||||
-rw-r--r-- | file.c | 9 | ||||
-rw-r--r-- | parse-xml.c | 59 |
3 files changed, 69 insertions, 0 deletions
@@ -663,6 +663,7 @@ extern int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, i extern int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); extern int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); +extern int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); extern int parse_dlf_buffer(unsigned char *buffer, size_t size); extern int parse_file(const char *filename); @@ -171,6 +171,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem) char dm5_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%SampleBlob%'"; char shearwater_test[] = "select count(*) from sqlite_master where type='table' and name='system' and sql like '%dbVersion%'"; char cobalt_test[] = "select count(*) from sqlite_master where type='table' and name='TrackPoints' and sql like '%DepthPressure%'"; + char divinglog_test[] = "select count(*) from sqlite_master where type='table' and name='DBInfo' and sql like '%PrgName%'"; int retval; retval = sqlite3_open(filename, &handle); @@ -212,6 +213,14 @@ static int try_to_open_db(const char *filename, struct memblock *mem) return retval; } + /* Testing if DB schema resembles Divinglog database format */ + retval = sqlite3_exec(handle, divinglog_test, &db_test_func, 0, NULL); + if (!retval) { + retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, &dive_table); + sqlite3_close(handle); + return retval; + } + sqlite3_close(handle); return retval; diff --git a/parse-xml.c b/parse-xml.c index 54a9b9471..62eceaa83 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -2843,6 +2843,65 @@ int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buffer, in return 0; } +extern int divinglog_dive(void *param, int columns, char **data, char **column) +{ + int retval = 0; + sqlite3 *handle = (sqlite3 *)param; + char *err = NULL; + + dive_start(); + cur_dive->number = atoi(data[0]); + + cur_dive->when = (time_t)(atol(data[1])); + + if (data[2]) + cur_dive->dive_site_uuid = create_dive_site(data[2]); + + if (data[3]) + utf8_string(data[3], &cur_dive->buddy); + + if (data[4]) + utf8_string(data[4], &cur_dive->notes); + + if (data[5]) + cur_dive->dc.maxdepth.mm = atoi(data[5]) * 1000; + + if (data[6]) + cur_dive->dc.duration.seconds = atoi(data[6]) * 60; + + settings_start(); + dc_settings_start(); + cur_settings.dc.model = strdup("Divinglog import"); + + dc_settings_end(); + settings_end(); + + cur_dive->dc.model = strdup("Divinglog import"); + dive_end(); + + return SQLITE_OK; +} + + +int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, + struct dive_table *table) +{ + int retval; + char *err = NULL; + target_table = table; + + char get_dives[] = "select Number,strftime('%s',Divedate || ' ' || ifnull(Entrytime,'00:00')),Country || ' - ' || City || ' - ' || Place,Buddy,Comments,Depth,Divetime from Logbook where UUID not in (select UUID from DeletedRecords)"; + + retval = sqlite3_exec(handle, get_dives, &divinglog_dive, handle, &err); + + if (retval != SQLITE_OK) { + fprintf(stderr, "Database query failed '%s'.\n", url); + return 1; + } + + return 0; +} + int parse_dlf_buffer(unsigned char *buffer, size_t size) { unsigned char *ptr = buffer; |