]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/sql_create.c
Fix bug #1504 -- Error when creating tables in MySQL 5.5
[bacula/bacula] / bacula / src / cats / sql_create.c
index 0508351cdbee7f338d0a1a919dd9a24a2e3a8e29..ad84e678f2fe2d718486bf35103ff4f06441705e 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.
@@ -90,12 +90,13 @@ 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));
 
-   jr->JobId = sql_insert_id(mdb, mdb->cmd, NT_("Job"));
-   if (jr->JobId == 0) {
+   if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
       Mmsg2(&mdb->errmsg, _("Create DB Job record %s failed. ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
+      jr->JobId = 0;
       ok = false;
    } else {
+      jr->JobId = sql_insert_id(mdb, NT_("Job"));
       ok = true;
    }
    db_unlock(mdb);
@@ -207,12 +208,13 @@ 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"));
-   if (pr->PoolId == 0) {
+   if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
       Mmsg2(&mdb->errmsg, _("Create db Pool record %s failed: ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
+      pr->PoolId = 0;
       stat = false;
    } else {
+      pr->PoolId = sql_insert_id(mdb, NT_("Pool"));
       stat = true;
    }
    db_unlock(mdb);
@@ -253,12 +255,13 @@ 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"));
-   if (dr->DeviceId == 0) {
+   if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
       Mmsg2(&mdb->errmsg, _("Create db Device record %s failed: ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
+      dr->DeviceId = 0;
       ok = false;
    } else {
+      dr->DeviceId = sql_insert_id(mdb, NT_("Device"));
       ok = true;
    }
    db_unlock(mdb);
@@ -311,13 +314,13 @@ 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"));
-   if (sr->StorageId == 0) {
+   if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
       Mmsg2(&mdb->errmsg, _("Create DB Storage record %s failed. ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
       Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
       ok = false;
    } else {
+      sr->StorageId = sql_insert_id(mdb, NT_("Storage"));
       sr->created = true;
       ok = true;
    }
@@ -359,12 +362,13 @@ 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"));
-   if (mr->MediaTypeId == 0) {
+   if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
       Mmsg2(&mdb->errmsg, _("Create db mediatype record %s failed: ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
+      mr->MediaTypeId = 0;
       stat = false;
    } else {
+      mr->MediaTypeId = sql_insert_id(mdb, NT_("MediaType"));
       stat = true;
    }
    db_unlock(mdb);
@@ -438,12 +442,12 @@ 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"));
-   if (mr->MediaId == 0) {
+   if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
       Mmsg2(&mdb->errmsg, _("Create DB Media record %s failed. ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
       stat = 0;
    } else {
+      mr->MediaId = sql_insert_id(mdb, NT_("Media"));
       stat = 1;
       if (mr->set_label_date) {
          char dt[MAX_TIME_LENGTH];
@@ -517,13 +521,14 @@ 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"));
-   if (cr->ClientId == 0) {
+   if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
       Mmsg2(&mdb->errmsg, _("Create DB Client record %s failed. ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
       Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+      cr->ClientId = 0;
       stat = 0;
    } else {
+      cr->ClientId = sql_insert_id(mdb, NT_("Client"));
       stat = 1;
    }
    db_unlock(mdb);
@@ -582,14 +587,14 @@ 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"));
-   if (ar->PathId == 0) {
+   if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
       Mmsg2(&mdb->errmsg, _("Create db Path record %s failed. ERR=%s\n"),
          mdb->cmd, sql_strerror(mdb));
       Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg);
       ar->PathId = 0;
       stat = 0;
    } else {
+      ar->PathId = sql_insert_id(mdb, NT_("Path"));
       stat = 1;
    }
 
@@ -622,7 +627,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);
@@ -695,13 +700,14 @@ 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"));
-   if (fsr->FileSetId == 0) {
+   if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
       Mmsg2(&mdb->errmsg, _("Create DB FileSet record %s failed. ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
       Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+      fsr->FileSetId = 0;
       stat = false;
    } else {
+      fsr->FileSetId = sql_insert_id(mdb, NT_("FileSet"));
       fsr->created = true;
       stat = true;
    }
@@ -1017,13 +1023,14 @@ 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"));
-   if (ar->FileId == 0) {
+   if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
       Mmsg2(&mdb->errmsg, _("Create db File record %s failed. ERR=%s"),
          mdb->cmd, sql_strerror(mdb));
       Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg);
+      ar->FileId = 0;
       stat = 0;
    } else {
+      ar->FileId = sql_insert_id(mdb, NT_("File"));
       stat = 1;
    }
    return stat;
@@ -1064,11 +1071,13 @@ 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"));
-   if (ar->FilenameId == 0) {
+   if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
       Mmsg2(&mdb->errmsg, _("Create db Filename record %s failed. ERR=%s\n"),
             mdb->cmd, sql_strerror(mdb));
       Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg);
+      ar->FilenameId = 0;
+   } else {
+      ar->FilenameId = sql_insert_id(mdb, NT_("Filename"));
    }
    return ar->FilenameId > 0;
 }