Add text_to_string().
This commit is contained in:
parent
138170975a
commit
f8fd9b8c6d
|
@ -118,6 +118,14 @@ public:
|
||||||
*/
|
*/
|
||||||
size_t remove(const string &uri);
|
size_t remove(const string &uri);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns tags as comma separated string.
|
||||||
|
*
|
||||||
|
* @since 0.9.0
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
static string tags_to_string(const vector<string> &tags);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
fs::path _dbpath;
|
fs::path _dbpath;
|
||||||
std::unique_ptr<Session> _session;
|
std::unique_ptr<Session> _session;
|
||||||
|
|
|
@ -30,19 +30,10 @@ void Export::CSV::print() const
|
||||||
<< R"("Title","Description","Full text")" << "\r\n";
|
<< R"("Title","Description","Full text")" << "\r\n";
|
||||||
for (const Database::entry &entry : _entries)
|
for (const Database::entry &entry : _entries)
|
||||||
{
|
{
|
||||||
string strtags;
|
|
||||||
for (const string &tag : entry.tags)
|
|
||||||
{
|
|
||||||
strtags += tag;
|
|
||||||
if (tag != *(entry.tags.rbegin()))
|
|
||||||
{
|
|
||||||
strtags += ",";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_out << '"' << quote(entry.uri) << "\",\""
|
_out << '"' << quote(entry.uri) << "\",\""
|
||||||
<< quote(entry.archive_uri) << "\",\""
|
<< quote(entry.archive_uri) << "\",\""
|
||||||
<< timepoint_to_string(entry.datetime) << "\",\""
|
<< timepoint_to_string(entry.datetime) << "\",\""
|
||||||
<< quote(strtags) << "\",\""
|
<< quote(Database::tags_to_string(entry.tags)) << "\",\""
|
||||||
<< quote(entry.title) << "\",\""
|
<< quote(entry.title) << "\",\""
|
||||||
<< quote(entry.description) << "\",\""
|
<< quote(entry.description) << "\",\""
|
||||||
<< quote(entry.fulltext_oneline()) << '"'<< "\r\n";
|
<< quote(entry.fulltext_oneline()) << '"'<< "\r\n";
|
||||||
|
|
|
@ -84,18 +84,9 @@ void Database::store(const Database::entry &data) const
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const string strdatetime = timepoint_to_string(data.datetime, true);
|
const string strdatetime = timepoint_to_string(data.datetime, true);
|
||||||
string strtags;
|
string strtags = tags_to_string(data.tags);
|
||||||
Statement insert(*_session);
|
Statement insert(*_session);
|
||||||
|
|
||||||
for (const string &tag : data.tags)
|
|
||||||
{
|
|
||||||
strtags += tag;
|
|
||||||
if (tag != *(data.tags.rbegin()))
|
|
||||||
{
|
|
||||||
strtags += ",";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// useRef() uses the const reference.
|
// useRef() uses the const reference.
|
||||||
insert << "INSERT INTO remwharead "
|
insert << "INSERT INTO remwharead "
|
||||||
"VALUES(?, ?, ?, ?, ?, ?, ?);",
|
"VALUES(?, ?, ?, ?, ?, ?, ?);",
|
||||||
|
@ -175,6 +166,22 @@ size_t Database::remove(const string &uri)
|
||||||
return del.execute();
|
return del.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string Database::tags_to_string(const vector<string> &tags)
|
||||||
|
{
|
||||||
|
string strtags;
|
||||||
|
|
||||||
|
for (const string &tag : tags)
|
||||||
|
{
|
||||||
|
strtags += tag;
|
||||||
|
if (tag != *(tags.rbegin()))
|
||||||
|
{
|
||||||
|
strtags += ',';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return strtags;
|
||||||
|
}
|
||||||
|
|
||||||
fs::path Database::get_data_home() const
|
fs::path Database::get_data_home() const
|
||||||
{
|
{
|
||||||
fs::path path;
|
fs::path path;
|
||||||
|
|
Loading…
Reference in New Issue