diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-03-08 09:30:54 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-03-08 09:30:54 +0100 |
commit | 552b997007a24943429488a3cc46c3e649316947 (patch) | |
tree | 39bf2835817314c9d09988e8704aa55285cd79c7 /apps/SoilMoistureIo.cpp | |
parent | 7088a4a5639b27a4c82eb6f6560ec1f1fd538fd4 (diff) | |
download | ble-toys-552b997007a24943429488a3cc46c3e649316947.tar.gz ble-toys-552b997007a24943429488a3cc46c3e649316947.tar.bz2 ble-toys-552b997007a24943429488a3cc46c3e649316947.tar.xz ble-toys-552b997007a24943429488a3cc46c3e649316947.zip |
o Improved SQL output.
Diffstat (limited to 'apps/SoilMoistureIo.cpp')
-rw-r--r-- | apps/SoilMoistureIo.cpp | 25 |
1 files changed, 14 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) { |