Skip to content

Commit

Permalink
Change: move GET iterator time conversion out of SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmundell committed Nov 27, 2023
1 parent 76b9085 commit d18e6c1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
36 changes: 32 additions & 4 deletions src/manage_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,46 @@ get_iterator_comment (iterator_t* iterator)
*
* @param[in] iterator Iterator.
*
* @return Creation time of the resource or NULL if iteration is complete.
* @return Creation time, or NULL if iteration is complete. Caller must free.
*/
DEF_ACCESS (get_iterator_creation_time, 4);
gchar *
get_iterator_creation_time (iterator_t* iterator)
{
time_t epoch;
char *iso;

if (iterator->done) return NULL;

epoch = iterator_int64 (iterator, 4);
iso = iso_time (&epoch);
if (iso)
// iso points to static memory.
return g_strdup (iso);
return g_strdup("ERR");
}

/**
* @brief Get the modification time of the resource from a GET iterator.
*
* @param[in] iterator Iterator.
*
* @return Modification time of the resource or NULL if iteration is complete.
* @return Modification time, or NULL if iteration is complete. Caller must free.
*/
DEF_ACCESS (get_iterator_modification_time, 5);
gchar *
get_iterator_modification_time (iterator_t* iterator)
{
time_t epoch;
char *iso;

if (iterator->done) return NULL;

epoch = iterator_int64 (iterator, 5);
iso = iso_time (&epoch);
if (iso)
// iso points to static memory.
return g_strdup (iso);
return g_strdup("ERR");
}

/**
* @brief Get the owner name of the resource from a GET iterator.
Expand Down
4 changes: 2 additions & 2 deletions src/manage_get.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ get_iterator_name (iterator_t*);
const char*
get_iterator_comment (iterator_t*);

const char*
gchar*
get_iterator_creation_time (iterator_t*);

const char*
gchar*
get_iterator_modification_time (iterator_t*);

const char*
Expand Down
10 changes: 5 additions & 5 deletions src/manage_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ typedef struct
*
* @param[in] prefix Column prefix.
*/
#define GET_ITERATOR_COLUMNS_STRING \
"id, uuid, name, comment, iso_time (creation_time)," \
" iso_time (modification_time), creation_time AS created," \
#define GET_ITERATOR_COLUMNS_STRING \
"id, uuid, name, comment, creation_time," \
" modification_time, creation_time AS created," \
" modification_time AS modified"

/**
Expand All @@ -263,8 +263,8 @@ typedef struct
{ prefix "uuid", NULL, KEYWORD_TYPE_STRING }, \
{ prefix "name", NULL, KEYWORD_TYPE_STRING }, \
{ prefix "comment", NULL, KEYWORD_TYPE_STRING }, \
{ " iso_time (" prefix "creation_time)", NULL, KEYWORD_TYPE_STRING }, \
{ " iso_time (" prefix "modification_time)", NULL, KEYWORD_TYPE_STRING }, \
{ prefix "creation_time", NULL, KEYWORD_TYPE_INTEGER }, \
{ prefix "modification_time", NULL, KEYWORD_TYPE_INTEGER }, \
{ prefix "creation_time", "created", KEYWORD_TYPE_INTEGER }, \
{ prefix "modification_time", "modified", KEYWORD_TYPE_INTEGER }

Expand Down

0 comments on commit d18e6c1

Please sign in to comment.