]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #9594 Use a default date when the data has not timestamp
authorEric Bollengier <eric@baculasystems.com>
Thu, 13 Oct 2022 16:15:43 +0000 (18:15 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:59 +0000 (13:56 +0200)
bacula/src/cats/cats.c
bacula/src/cats/sql_cmds.c
bacula/src/cats/sql_cmds.h

index 6ac7806354d68076540f3dc0bacce68baab5ae5c..0d3bdeeedd22c515da44acef29afe9d893850212 100644 (file)
@@ -476,7 +476,7 @@ static struct json_sql email_json_v1[] = {
    SAME_KW("EmailInternetMessageId", OT_STRING),
    SAME_KW("EmailIsRead", OT_BOOL),
    SAME_KW("EmailIsDraft", OT_BOOL),
-   SAME_KW("EmailTime", OT_STRING),
+   SAME_KW("EmailTime", OT_DATE),
    SAME_KW("EmailSubject", OT_STRING),
    SAME_KW("EmailTags", OT_STRING),
    SAME_KW("EmailTo", OT_STRING),
@@ -539,6 +539,26 @@ bool META_JSON_SCANNER::parse(JCR *jcr, BDB *db,
               first?' ':',',
               val->valuedouble == 0 ? 0 : 1);
          break;
+      case OT_DATE:
+      {
+         const char *def = sql_now[db_get_type_index(db)];
+         if (!cJSON_IsString(val) || (val->valuestring == NULL)) {
+            Mmsg(dest, "JSON Error: Unable to find %s", m_j2s[i].json_name);
+            goto bail_out;
+         }
+         // TODO: Need to check the date format
+         if (val->valuestring[0] != 0) { // not empty string
+            def = val->valuestring;
+         }
+         len = strlen(def);
+         esc.check_size(len*2+1);
+         db_escape_string(jcr, db, esc.c_str(), def, len);
+
+         Mmsg(tmp, "%c'%s'",
+              first?' ':',',
+              esc.c_str());
+      }
+      break;
       case OT_STRING:
          if (!cJSON_IsString(val) || (val->valuestring == NULL)) {
             Mmsg(dest, "JSON Error: Unable to find %s", m_j2s[i].json_name);
index 82d5a54cb9e66ab0f8574c1dee247a5780ab00cb..80339a335beb40f728e2c36fc3f9ef26692c8081 100644 (file)
@@ -986,6 +986,15 @@ const char *update_counter_values[] =
    update_counter_values_default 
 }; 
 
+const char *sql_now[] = {
+   /* MySQL */
+   " NOW() ",
+   /* PostgreSQL */
+   " NOW() ",
+   /* SQLite */
+   " strftime('%s', datetime('now', 'localtime')) "
+};
+
 const char *prune_cache[] = {
    /* MySQL */
    " (Media.LastWritten + Media.CacheRetention) < NOW() ",
index 3b589cc47b968493bdb149c63d3400e5dabc4b30..656f976dc109b6c76a735a774b7d17db5fb4feff 100644 (file)
@@ -27,6 +27,7 @@
  *     Kern Sibbald, July MMII
  */
 
+extern const char CATS_IMP_EXP *sql_now[];
 extern const char CATS_IMP_EXP *batch_fill_filename_query[];
 extern const char CATS_IMP_EXP *batch_fill_path_query[];
 extern const char CATS_IMP_EXP *batch_lock_filename_query[];