aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dive.h3
-rw-r--r--file.c15
-rw-r--r--parse-xml.c13
3 files changed, 17 insertions, 14 deletions
diff --git a/dive.h b/dive.h
index 16105e1ec..9f3df313d 100644
--- a/dive.h
+++ b/dive.h
@@ -6,6 +6,7 @@
#include <time.h>
#include <math.h>
#include <zip.h>
+#include <sqlite3.h>
/* Windows has no MIN/MAX macros - so let's just roll our own */
#define MIN(x, y) ({ \
@@ -643,7 +644,7 @@ extern void parse_xml_buffer(const char *url, const char *buf, int size, struct
extern void parse_xml_exit(void);
extern void set_filename(const char *filename, bool force);
-extern int parse_dm4_buffer(const char *url, const char *buf, int size, struct dive_table *table, char **error);
+extern int parse_dm4_buffer(const sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, char **error);
extern void parse_file(const char *filename, char **error);
extern void parse_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int stopdepthf, int sepidx, const char *csvtemplate, char **error);
diff --git a/file.c b/file.c
index 8157e9a60..b218a13e2 100644
--- a/file.c
+++ b/file.c
@@ -153,7 +153,20 @@ static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, char
static int try_to_open_db(const char *filename, struct memblock *mem, char **error)
{
- return parse_dm4_buffer(filename, mem->buffer, mem->size, &dive_table, error);
+ sqlite3 *handle;
+ int retval;
+
+ retval = sqlite3_open(filename, &handle);
+
+ if (retval) {
+ fprintf(stderr, translate("gettextFromC","Database connection failed '%s'.\n"), filename);
+ return 1;
+ }
+
+ retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, &dive_table, error);
+ sqlite3_close(handle);
+
+ return retval;
}
timestamp_t parse_date(const char *date)
diff --git a/parse-xml.c b/parse-xml.c
index 2a98d3904..60a13c336 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -14,8 +14,6 @@
#include "gettext.h"
-#include<sqlite3.h>
-
#include "dive.h"
#include "device.h"
@@ -1863,25 +1861,17 @@ extern int dm4_dive(void *param, int columns, char **data, char **column)
return SQLITE_OK;
}
-int parse_dm4_buffer(const char *url, const char *buffer, int size,
+int parse_dm4_buffer(const sqlite3 *handle, const char *url, const char *buffer, int size,
struct dive_table *table, char **error)
{
int retval;
char *err = NULL;
- sqlite3 *handle;
target_table = table;
/* StartTime is converted from Suunto's nano seconds to standard
* time. We also need epoch, not seconds since year 1. */
char get_dives[] = "select D.DiveId,StartTime/10000000-62135596800,Note,Duration,SourceSerialNumber,Source,MaxDepth,SampleInterval,StartTemperature,BottomTemperature,D.StartPressure,D.EndPressure,Size,CylinderWorkPressure,SurfacePressure,DiveTime,SampleInterval,ProfileBlob,TemperatureBlob,PressureBlob,Oxygen,Helium,MIX.StartPressure,MIX.EndPressure FROM Dive AS D JOIN DiveMixture AS MIX ON D.DiveId=MIX.DiveId";
- retval = sqlite3_open(url, &handle);
-
- if (retval) {
- fprintf(stderr, translate("gettextFromC","Database connection failed '%s'.\n"), url);
- return 1;
- }
-
retval = sqlite3_exec(handle, get_dives, &dm4_dive, handle, &err);
if (retval != SQLITE_OK) {
@@ -1889,7 +1879,6 @@ int parse_dm4_buffer(const char *url, const char *buffer, int size,
return 1;
}
- sqlite3_close(handle);
return 0;
}