aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/SoilMoistureIo.cpp25
-rw-r--r--apps/sample-convert.cpp8
2 files changed, 22 insertions, 11 deletions
diff --git a/apps/SoilMoistureIo.cpp b/apps/SoilMoistureIo.cpp
index 24618ff..983427c 100644
--- a/apps/SoilMoistureIo.cpp
+++ b/apps/SoilMoistureIo.cpp
@@ -108,7 +108,10 @@ SqlSampleOutputStream::SqlSampleOutputStream(ostream &stream, vector<string> fie
}
void SqlSampleOutputStream::write(Sample values) {
- stringstream fs, vs;
+ string fs, vs;
+
+ fs.reserve(1024);
+ vs.reserve(1024);
if (filterFields) {
auto i = fields.begin();
@@ -116,21 +119,21 @@ void SqlSampleOutputStream::write(Sample values) {
while (i != fields.end()) {
auto field = *i;
- fs << field;
+ fs += field;
auto value = values.find(field);
if (value != values.end()) {
- vs << "'" << value->second << "'";
+ vs += "'" + value->second + "'";
} else {
- vs << "NULL";
+ vs + "NULL";
}
i++;
if (i != fields.end()) {
- fs << ",";
- vs << ",";
+ fs += ",";
+ vs += ",";
}
}
} else {
@@ -138,17 +141,17 @@ void SqlSampleOutputStream::write(Sample values) {
while (i != values.end()) {
auto v = *i++;
- fs << v.first;
- vs << "'" << v.second << "'";
+ fs += v.first;
+ vs += "'" + v.second + "'";
if (i != values.end()) {
- fs << ",";
- vs << ",";
+ fs += ",";
+ vs += ",";
}
}
}
- stream << "INSERT INTO (" << fs << ") VALUES(" << vs << ")" << endl;
+ stream << "INSERT INTO (" << fs << ") VALUES(" << vs << ");" << endl;
}
void CsvParser::process(mutable_buffers_1 buffer) {
diff --git a/apps/sample-convert.cpp b/apps/sample-convert.cpp
index 370059c..23a04ff 100644
--- a/apps/sample-convert.cpp
+++ b/apps/sample-convert.cpp
@@ -37,6 +37,10 @@ public:
inputStream = &cin;
} else {
inputStream = new ifstream(inputFile);
+ if (inputStream->fail()) {
+ cerr << "Unable to open input file " << inputFile << endl;
+ return EXIT_FAILURE;
+ }
}
ostream *outputStream;
@@ -44,6 +48,10 @@ public:
outputStream = &cout;
} else {
outputStream = new ofstream(outputFile);
+ if (outputStream->fail()) {
+ cerr << "Unable to open output file " << outputFile << endl;
+ return EXIT_FAILURE;
+ }
}
if (outputFormat == "plain") {