From f183201f6f43ca624a852d14a895624db0bf2dca Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 23 Apr 2011 21:13:57 -0400 Subject: [PATCH] Export - Added the ability to include the ID in _query command results. --- src/Task.cpp | 6 +++++- src/Task.h | 2 +- src/command.cpp | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index 99c85fdcc..d8201b415 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -426,11 +426,15 @@ std::string Task::composeYAML () const } //////////////////////////////////////////////////////////////////////////////// -std::string Task::composeJSON () const +std::string Task::composeJSON (bool include_id /*= false*/) const { std::stringstream out; out << "{"; + // ID inclusion is optional, not recommended. + if (include_id) + out << "\"id\":" << id << ","; + // Used for determining type. Att att; diff --git a/src/Task.h b/src/Task.h index 687b12cd6..a2eb89e00 100644 --- a/src/Task.h +++ b/src/Task.h @@ -45,7 +45,7 @@ public: void parse (const std::string&); std::string composeCSV () const; std::string composeYAML () const; - std::string composeJSON () const; + std::string composeJSON (bool include_id = false) const; // Status values. enum status {pending, completed, deleted, recurring, waiting}; diff --git a/src/command.cpp b/src/command.cpp index db8c5cecf..a505515e5 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -613,7 +613,7 @@ int handleQuery (std::string& outs) if (t != tasks.begin ()) outs += ",\n"; - outs += t->composeJSON (); + outs += t->composeJSON (true); } outs += "\n";