]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/sql_create.c
Tweak insert_autokey to use unsigned int64 instead of signed int64.
[bacula/bacula] / bacula / src / cats / sql_create.c
index 3a1d02faf808f49ea1099f61231d93a9e0d79b5b..3dcc13c81e5707f5020157a784c0be3289fb7488 100644 (file)
@@ -6,7 +6,7 @@
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
@@ -15,7 +15,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
@@ -58,8 +58,8 @@ static int db_create_filename_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
 #endif /* HAVE_BATCH_FILE_INSERT */
 
 
-/* Create a new record for the Job
- * Returns: false on failure
+/** Create a new record for the Job
+ *  Returns: false on failure
  *          true  on success
  */
 bool
@@ -96,7 +96,7 @@ db_create_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
            (char)(jr->JobStatus), dt, edit_uint64(JobTDate, ed1),
            edit_int64(jr->ClientId, ed2), buf.c_str());
 
-   jr->JobId = sql_insert_id(mdb, mdb->cmd, NT_("Job"));
+   jr->JobId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("Job"));
    if (jr->JobId == 0) {
       Mmsg2(&mdb->errmsg, _("Create DB Job record %s failed. ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
@@ -109,8 +109,8 @@ db_create_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
 }
 
 
-/* Create a JobMedia record for medium used this job
- * Returns: false on failure
+/** Create a JobMedia record for medium used this job
+ *  Returns: false on failure
  *          true  on success
  */
 bool
@@ -131,10 +131,6 @@ db_create_jobmedia_record(JCR *jcr, B_DB *mdb, JOBMEDIA_DBR *jm)
    }
    count++;
 
-   /* Note, jm->Strip is not used and is not likely to be used
-    * in the near future, so I have removed it from the insert
-    * to save space in the DB. KES June 2006.
-    */
    Mmsg(mdb->cmd,
         "INSERT INTO JobMedia (JobId,MediaId,FirstIndex,LastIndex,"
         "StartFile,EndFile,StartBlock,EndBlock,VolIndex) "
@@ -165,8 +161,8 @@ db_create_jobmedia_record(JCR *jcr, B_DB *mdb, JOBMEDIA_DBR *jm)
    return ok;
 }
 
-/* Create Unique Pool record
- * Returns: false on failure
+/** Create Unique Pool record
+ *  Returns: false on failure
  *          true  on success
  */
 bool
@@ -213,7 +209,7 @@ db_create_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
                   pr->ActionOnPurge
       );
    Dmsg1(200, "Create Pool: %s\n", mdb->cmd);
-   pr->PoolId = sql_insert_id(mdb, mdb->cmd, NT_("Pool"));
+   pr->PoolId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("Pool"));
    if (pr->PoolId == 0) {
       Mmsg2(&mdb->errmsg, _("Create db Pool record %s failed: ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
@@ -226,7 +222,7 @@ db_create_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
    return stat;
 }
 
-/*
+/**
  * Create Unique Device record
  * Returns: false on failure
  *          true  on success
@@ -260,7 +256,7 @@ db_create_device_record(JCR *jcr, B_DB *mdb, DEVICE_DBR *dr)
                   edit_uint64(dr->MediaTypeId, ed1),
                   edit_int64(dr->StorageId, ed2));
    Dmsg1(200, "Create Device: %s\n", mdb->cmd);
-   dr->DeviceId = sql_insert_id(mdb, mdb->cmd, NT_("Device"));
+   dr->DeviceId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("Device"));
    if (dr->DeviceId == 0) {
       Mmsg2(&mdb->errmsg, _("Create db Device record %s failed: ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
@@ -274,7 +270,7 @@ db_create_device_record(JCR *jcr, B_DB *mdb, DEVICE_DBR *dr)
 
 
 
-/*
+/**
  * Create a Unique record for Storage -- no duplicates
  * Returns: false on failure
  *          true  on success with id in sr->StorageId
@@ -318,7 +314,7 @@ bool db_create_storage_record(JCR *jcr, B_DB *mdb, STORAGE_DBR *sr)
    Mmsg(mdb->cmd, "INSERT INTO Storage (Name,AutoChanger)"
         " VALUES ('%s',%d)", sr->Name, sr->AutoChanger);
 
-   sr->StorageId = sql_insert_id(mdb, mdb->cmd, NT_("Storage"));
+   sr->StorageId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("Storage"));
    if (sr->StorageId == 0) {
       Mmsg2(&mdb->errmsg, _("Create DB Storage record %s failed. ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
@@ -333,7 +329,7 @@ bool db_create_storage_record(JCR *jcr, B_DB *mdb, STORAGE_DBR *sr)
 }
 
 
-/*
+/**
  * Create Unique MediaType record
  * Returns: false on failure
  *          true  on success
@@ -366,7 +362,7 @@ db_create_mediatype_record(JCR *jcr, B_DB *mdb, MEDIATYPE_DBR *mr)
                   mr->MediaType,
                   mr->ReadOnly);
    Dmsg1(200, "Create mediatype: %s\n", mdb->cmd);
-   mr->MediaTypeId = sql_insert_id(mdb, mdb->cmd, NT_("MediaType"));
+   mr->MediaTypeId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("MediaType"));
    if (mr->MediaTypeId == 0) {
       Mmsg2(&mdb->errmsg, _("Create db mediatype record %s failed: ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
@@ -379,7 +375,7 @@ db_create_mediatype_record(JCR *jcr, B_DB *mdb, MEDIATYPE_DBR *mr)
 }
 
 
-/*
+/**
  * Create Media record. VolumeName and non-zero Slot must be unique
  *
  * Returns: 0 on failure
@@ -445,7 +441,7 @@ db_create_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
 
 
    Dmsg1(500, "Create Volume: %s\n", mdb->cmd);
-   mr->MediaId = sql_insert_id(mdb, mdb->cmd, NT_("Media"));
+   mr->MediaId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("Media"));
    if (mr->MediaId == 0) {
       Mmsg2(&mdb->errmsg, _("Create DB Media record %s failed. ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
@@ -474,7 +470,7 @@ db_create_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
    return stat;
 }
 
-/*
+/**
  * Create a Unique record for the client -- no duplicates
  * Returns: 0 on failure
  *          1 on success with id in cr->ClientId
@@ -524,7 +520,7 @@ int db_create_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr)
       edit_uint64(cr->FileRetention, ed1),
       edit_uint64(cr->JobRetention, ed2));
 
-   cr->ClientId = sql_insert_id(mdb, mdb->cmd, NT_("Client"));
+   cr->ClientId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("Client"));
    if (cr->ClientId == 0) {
       Mmsg2(&mdb->errmsg, _("Create DB Client record %s failed. ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
@@ -538,7 +534,7 @@ int db_create_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr)
 }
 
 
-/* Create a Unique record for the Path -- no duplicates */
+/** Create a Unique record for the Path -- no duplicates */
 int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
 {
    SQL_ROW row;
@@ -589,7 +585,7 @@ int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
 
    Mmsg(mdb->cmd, "INSERT INTO Path (Path) VALUES ('%s')", mdb->esc_name);
 
-   ar->PathId = sql_insert_id(mdb, mdb->cmd, NT_("Path"));
+   ar->PathId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("Path"));
    if (ar->PathId == 0) {
       Mmsg2(&mdb->errmsg, _("Create db Path record %s failed. ERR=%s\n"),
          mdb->cmd, sql_strerror(mdb));
@@ -609,7 +605,7 @@ int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
    return stat;
 }
 
-/*
+/**
  * Create a Unique record for the counter -- no duplicates
  * Returns: 0 on failure
  *          1 on success with counter filled in
@@ -629,7 +625,7 @@ int db_create_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr)
    }
 
    /* Must create it */
-   Mmsg(mdb->cmd, "INSERT INTO Counters (Counter,MinValue,MaxValue,CurrentValue,"
+   Mmsg(mdb->cmd, "INSERT INTO Counters (Counter,\"MinValue\",\"MaxValue\",CurrentValue,"
       "WrapCounter) VALUES ('%s','%d','%d','%d','%s')",
       cr->Counter, cr->MinValue, cr->MaxValue, cr->CurrentValue,
       cr->WrapCounter);
@@ -647,7 +643,7 @@ int db_create_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr)
 }
 
 
-/*
+/**
  * Create a FileSet record. This record is unique in the
  *  name and the MD5 signature of the include/exclude sets.
  *  Returns: 0 on failure
@@ -702,7 +698,7 @@ bool db_create_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr)
       Mmsg(mdb->cmd, "INSERT INTO FileSet (FileSet,MD5,CreateTime) "
 "VALUES ('%s','%s','%s')", fsr->FileSet, fsr->MD5, fsr->cCreateTime);
 
-   fsr->FileSetId = sql_insert_id(mdb, mdb->cmd, NT_("FileSet"));
+   fsr->FileSetId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("FileSet"));
    if (fsr->FileSetId == 0) {
       Mmsg2(&mdb->errmsg, _("Create DB FileSet record %s failed. ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
@@ -718,7 +714,7 @@ bool db_create_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr)
 }
 
 
-/*
+/**
  *  struct stat
  *  {
  *      dev_t         st_dev;       * device *
@@ -739,7 +735,7 @@ bool db_create_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr)
 
 #ifdef HAVE_BATCH_FILE_INSERT
 
-/*  All sql_batch_* functions are used to do bulk batch insert in File/Filename/Path
+/** All sql_batch_* functions are used to do bulk batch insert in File/Filename/Path
  *  tables. This code can be activated by adding "#define HAVE_BATCH_FILE_INSERT 1"
  *  in baconfig.h
  *  
@@ -822,11 +818,12 @@ bool my_batch_end(JCR *jcr, B_DB *mdb, const char *error)
 }
 
 /* 
- * Returns 1 if OK
- *         0 if failed
+ * Returns true if OK
+ *         false if failed
  */
 bool db_write_batch_file_records(JCR *jcr)
 {
+   bool retval = false;
    int JobStatus = jcr->JobStatus;
 
    if (!jcr->batch_started) {         /* no files to backup ? */
@@ -834,7 +831,7 @@ bool db_write_batch_file_records(JCR *jcr)
       return true;
    }
    if (job_canceled(jcr)) {
-      return false;
+      goto bail_out;
    }
 
    Dmsg1(50,"db_create_file_record changes=%u\n",jcr->db_batch->changes);
@@ -842,49 +839,52 @@ bool db_write_batch_file_records(JCR *jcr)
    jcr->JobStatus = JS_AttrInserting;
    if (!sql_batch_end(jcr, jcr->db_batch, NULL)) {
       Jmsg1(jcr, M_FATAL, 0, "Batch end %s\n", jcr->db_batch->errmsg);
-      return false;
+      goto bail_out;
    }
    if (job_canceled(jcr)) {
-      return false;
+      goto bail_out;
    }
 
-
-   /* we have to lock tables */
+   /*
+    * We have to lock tables
+    */
    if (!db_sql_query(jcr->db_batch, sql_batch_lock_path_query, NULL, NULL)) {
       Jmsg1(jcr, M_FATAL, 0, "Lock Path table %s\n", jcr->db_batch->errmsg);
-      return false;
+      goto bail_out;
    }
 
    if (!db_sql_query(jcr->db_batch, sql_batch_fill_path_query, NULL, NULL)) {
       Jmsg1(jcr, M_FATAL, 0, "Fill Path table %s\n",jcr->db_batch->errmsg);
       db_sql_query(jcr->db_batch, sql_batch_unlock_tables_query, NULL, NULL);
-      return false;
+      goto bail_out;
    }
    
    if (!db_sql_query(jcr->db_batch, sql_batch_unlock_tables_query,NULL,NULL)) {
       Jmsg1(jcr, M_FATAL, 0, "Unlock Path table %s\n", jcr->db_batch->errmsg);
-      return false;      
+      goto bail_out;
    }
 
-   /* we have to lock tables */
+   /*
+    * We have to lock tables
+    */
    if (!db_sql_query(jcr->db_batch,sql_batch_lock_filename_query,NULL, NULL)) {
       Jmsg1(jcr, M_FATAL, 0, "Lock Filename table %s\n", jcr->db_batch->errmsg);
-      return false;
+      goto bail_out;
    }
    
    if (!db_sql_query(jcr->db_batch,sql_batch_fill_filename_query, NULL,NULL)) {
       Jmsg1(jcr,M_FATAL,0,"Fill Filename table %s\n",jcr->db_batch->errmsg);
       db_sql_query(jcr->db_batch, sql_batch_unlock_tables_query, NULL, NULL);
-      return false;            
+      goto bail_out;
    }
 
    if (!db_sql_query(jcr->db_batch, sql_batch_unlock_tables_query,NULL,NULL)) {
       Jmsg1(jcr, M_FATAL, 0, "Unlock Filename table %s\n", jcr->db_batch->errmsg);
-      return false;
+      goto bail_out;
    }
    
    if (!db_sql_query(jcr->db_batch, 
-       "INSERT INTO File (FileIndex, JobId, PathId, FilenameId, LStat, MD5)"
+       "INSERT INTO File (FileIndex, JobId, PathId, FilenameId, LStat, MD5) "
          "SELECT batch.FileIndex, batch.JobId, Path.PathId, "
                 "Filename.FilenameId,batch.LStat, batch.MD5 "
            "FROM batch "
@@ -893,16 +893,19 @@ bool db_write_batch_file_records(JCR *jcr)
                      NULL,NULL))
    {
       Jmsg1(jcr, M_FATAL, 0, "Fill File table %s\n", jcr->db_batch->errmsg);
-      return false;
+      goto bail_out;
    }
 
+   jcr->JobStatus = JobStatus;         /* reset entry status */
+   retval = true;
+
+bail_out:
    db_sql_query(jcr->db_batch, "DROP TABLE batch", NULL,NULL);
 
-   jcr->JobStatus = JobStatus;         /* reset entry status */
-   return true;
+   return retval;
 }
 
-/*
+/**
  * Create File record in B_DB
  *
  *  In order to reduce database size, we store the File attributes,
@@ -953,7 +956,7 @@ bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
 
 #else  /* ! HAVE_BATCH_FILE_INSERT */
 
-/*
+/**
  * Create File record in B_DB
  *
  *  In order to reduce database size, we store the File attributes,
@@ -997,7 +1000,7 @@ bail_out:
 }
 
 
-/*
+/**
  * This is the master File entry containing the attributes.
  *  The filename and path records have already been created.
  */
@@ -1024,7 +1027,7 @@ static int db_create_file_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
         ar->FileIndex, ar->JobId, ar->PathId, ar->FilenameId,
         ar->attr, digest);
 
-   ar->FileId = sql_insert_id(mdb, mdb->cmd, NT_("File"));
+   ar->FileId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("File"));
    if (ar->FileId == 0) {
       Mmsg2(&mdb->errmsg, _("Create db File record %s failed. ERR=%s"),
          mdb->cmd, sql_strerror(mdb));
@@ -1036,7 +1039,7 @@ static int db_create_file_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
    return stat;
 }
 
-/* Create a Unique record for the filename -- no duplicates */
+/** Create a Unique record for the filename -- no duplicates */
 static int db_create_filename_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
 {
    SQL_ROW row;
@@ -1071,7 +1074,7 @@ static int db_create_filename_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
 
    Mmsg(mdb->cmd, "INSERT INTO Filename (Name) VALUES ('%s')", mdb->esc_name);
 
-   ar->FilenameId = sql_insert_id(mdb, mdb->cmd, NT_("Filename"));
+   ar->FilenameId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("Filename"));
    if (ar->FilenameId == 0) {
       Mmsg2(&mdb->errmsg, _("Create db Filename record %s failed. ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
@@ -1087,39 +1090,7 @@ bool db_write_batch_file_records(JCR *jcr)
 
 #endif /* ! HAVE_BATCH_FILE_INSERT */
 
-
-/* List of SQL commands to create temp table and indicies  */
-const char *create_temp_basefile[5] = {
-   /* MySQL */
-   "CREATE TEMPORARY TABLE basefile%lld ("
-//   "CREATE TABLE basefile%lld ("
-   "Path BLOB NOT NULL,"
-   "Name BLOB NOT NULL)",
-
-   /* Postgresql */
-   "CREATE TEMPORARY TABLE basefile%lld (" 
-//   "CREATE TABLE basefile%lld (" 
-   "Path TEXT,"
-   "Name TEXT)",
-
-   /* SQLite */
-   "CREATE TEMPORARY TABLE basefile%lld (" 
-   "Path TEXT,"
-   "Name TEXT)",
-
-   /* SQLite3 */
-   "CREATE TEMPORARY TABLE basefile%lld (" 
-   "Path TEXT,"
-   "Name TEXT)",
-
-   /* Ingres */
-   "DECLARE GLOBAL TEMPORARY TABLE basefile%lld (" 
-   "Path TEXT NOT NULL,"
-   "Name TEXT NOT NULL)"
-   "ON COMMIT PRESERVE ROWS WITH NORECOVERY"
-};
-
-/* 
+/** 
  * Create file attributes record, or base file attributes record
  */
 bool db_create_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
@@ -1149,7 +1120,7 @@ bool db_create_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
    return ret;
 }
 
-/*
+/**
  * Create Base File record in B_DB
  *
  */
@@ -1177,7 +1148,7 @@ bool db_create_base_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
    return ret;
 }
 
-/* 
+/** 
  * Cleanup the base file temporary tables
  */
 static void db_cleanup_base_file(JCR *jcr, B_DB *mdb)
@@ -1190,7 +1161,7 @@ static void db_cleanup_base_file(JCR *jcr, B_DB *mdb)
    db_sql_query(mdb, buf.c_str(), NULL, NULL);
 }
 
-/*
+/**
  * Put all base file seen in the backup to the BaseFile table
  * and cleanup temporary tables
  */
@@ -1218,7 +1189,7 @@ bool db_commit_base_file_attributes_record(JCR *jcr, B_DB *mdb)
    return ret;
 }
 
-/*
+/**
  * Find the last "accurate" backup state with Base jobs
  * 1) Get all files with jobid in list (F subquery) 
  * 2) Take only the last version of each file (Temp subquery) => accurate list is ok
@@ -1242,17 +1213,7 @@ bool db_create_base_file_list(JCR *jcr, B_DB *mdb, char *jobids)
       goto bail_out;
    }
    Mmsg(buf, select_recent_version[db_type], jobids, jobids);
-   Mmsg(mdb->cmd,
-"CREATE TEMPORARY TABLE new_basefile%lld AS  "
-//"CREATE TABLE new_basefile%lld AS "
-  "SELECT Path.Path AS Path, Filename.Name AS Name, Temp.FileIndex AS FileIndex,"
-         "Temp.JobId AS JobId, Temp.LStat AS LStat, Temp.FileId AS FileId, "
-         "Temp.MD5 AS MD5 "
-  "FROM ( %s ) AS Temp "
-  "JOIN Filename ON (Filename.FilenameId = Temp.FilenameId) "
-  "JOIN Path ON (Path.PathId = Temp.PathId) "
- "WHERE Temp.FileIndex > 0",
-        (uint64_t)jcr->JobId, buf.c_str());
+   Mmsg(mdb->cmd, create_temp_new_basefile[db_type], (uint64_t)jcr->JobId, buf.c_str());
 
    ret = db_sql_query(mdb, mdb->cmd, NULL, NULL);
 bail_out:
@@ -1260,39 +1221,41 @@ bail_out:
    return ret;
 }
 
-
-/*
+/**
  * Create Restore Object record in B_DB
  *
  */
 bool db_create_restore_object_record(JCR *jcr, B_DB *mdb, ROBJECT_DBR *ro)
 {
    bool stat;
-   POOLMEM *esc_obj = get_pool_memory(PM_MESSAGE); 
+   int plug_name_len;
+   POOLMEM *esc_plug_name = get_pool_memory(PM_MESSAGE);
+
    db_lock(mdb);
 
-   Dmsg1(dbglevel, "Fname=%s\n", ro->fname);
+   Dmsg1(dbglevel, "Oname=%s\n", ro->object_name);
    Dmsg0(dbglevel, "put_object_into_catalog\n");
 
-   split_path_and_file(jcr, mdb, ro->full_fname);
-
+   mdb->fnl = strlen(ro->object_name);
    mdb->esc_name = check_pool_memory_size(mdb->esc_name, mdb->fnl*2+1);
-   db_escape_string(jcr, mdb, mdb->esc_name, mdb->fname, mdb->fnl);
+   db_escape_string(jcr, mdb, mdb->esc_name, ro->object_name, mdb->fnl);
    
-   mdb->esc_path = check_pool_memory_size(mdb->esc_path, mdb->pnl*2+1);
-   db_escape_string(jcr, mdb, mdb->esc_path, mdb->path, mdb->pnl);
+   db_escape_object(jcr, mdb, ro->object, ro->object_len);
 
-   esc_obj = check_pool_memory_size(esc_obj, ro->object_len*2+1);
-   db_escape_string(jcr, mdb, esc_obj, ro->object, ro->object_len);
+   plug_name_len = strlen(ro->plugin_name);
+   esc_plug_name = check_pool_memory_size(esc_plug_name, plug_name_len*2+1);
+   db_escape_string(jcr, mdb, esc_plug_name, ro->plugin_name, plug_name_len);
 
    Mmsg(mdb->cmd,
-        "INSERT INTO RestoreObject (Fname,Path,PluginName,RestoreObject,"
-        "ObjectIndex,ObjectType,FileIndex,JobId) VALUES"
-        "('%s','%s','%s','%s',%d,%d,%d,%u)", 
-        mdb->esc_name, mdb->esc_path, mdb->esc_path, esc_obj, ro->object_len,
-        ro->ObjectIndex, FT_RESTORE_FIRST, ro->FileIndex, ro->JobId);
-
-   ro->RestoreObjectId = sql_insert_id(mdb, mdb->cmd, NT_("RestoreObject"));
+        "INSERT INTO RestoreObject (ObjectName,PluginName,RestoreObject,"
+        "ObjectLength,ObjectFullLength,ObjectIndex,ObjectType,"
+        "ObjectCompression,FileIndex,JobId) "
+        "VALUES ('%s','%s','%s',%d,%d,%d,%d,%d,%d,%u)",
+        mdb->esc_name, esc_plug_name, mdb->esc_obj,
+        ro->object_len, ro->object_full_len, ro->object_index, 
+        FT_RESTORE_FIRST, ro->object_compression, ro->FileIndex, ro->JobId);
+
+   ro->RestoreObjectId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("RestoreObject"));
    if (ro->RestoreObjectId == 0) {
       Mmsg2(&mdb->errmsg, _("Create db Object record %s failed. ERR=%s"),
          mdb->cmd, sql_strerror(mdb));
@@ -1302,7 +1265,7 @@ bool db_create_restore_object_record(JCR *jcr, B_DB *mdb, ROBJECT_DBR *ro)
       stat = true;
    }
    db_unlock(mdb);
-   free_pool_memory(esc_obj);
+   free_pool_memory(esc_plug_name);
    return stat;
 }