]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/sql_create.c
Convert restore object to use STREAM_RESTORE_OBJECT; cleaner code
[bacula/bacula] / bacula / src / cats / sql_create.c
index 44d1c2c5520871e04b6080d02a7d2104d298c20c..539c8db9d571255bfb408877d2a9e86ae3ffea9d 100644 (file)
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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;
@@ -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
@@ -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
@@ -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
  *  
@@ -902,7 +898,7 @@ bool db_write_batch_file_records(JCR *jcr)
    return true;
 }
 
-/*
+/**
  * Create File record in B_DB
  *
  *  In order to reduce database size, we store the File attributes,
@@ -953,7 +949,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 +993,7 @@ bail_out:
 }
 
 
-/*
+/**
  * This is the master File entry containing the attributes.
  *  The filename and path records have already been created.
  */
@@ -1036,7 +1032,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;
@@ -1087,39 +1083,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 +1113,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 +1141,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 +1154,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 +1182,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 +1206,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,8 +1214,7 @@ bail_out:
    return ret;
 }
 
-
-/*
+/**
  * Create Restore Object record in B_DB
  *
  */
@@ -1271,26 +1224,22 @@ bool db_create_restore_object_record(JCR *jcr, B_DB *mdb, ROBJECT_DBR *ro)
    POOLMEM *esc_obj = 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);
-
    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);
 
    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);
+        "INSERT INTO RestoreObject (ObjectName,RestoreObject,"
+        "ObjectLength,ObjectIndex,ObjectType,ObjectCompression,FileIndex,JobId) "
+        "VALUES ('%s','%s',%d,%d,%d,%d,%d,%u)",
+        mdb->esc_name, esc_obj, ro->object_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) {