]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/sql_create.c
Add Raw file save/restore
[bacula/bacula] / bacula / src / cats / sql_create.c
1 /*
2  * Bacula Catalog Database Create record interface routines
3  * 
4  *    Kern Sibbald, March 2000
5  *
6  *    Version $Id$
7  */
8
9 /*
10    Copyright (C) 2000-2003 Kern Sibbald and John Walker
11
12    This program is free software; you can redistribute it and/or
13    modify it under the terms of the GNU General Public License as
14    published by the Free Software Foundation; either version 2 of
15    the License, or (at your option) any later version.
16
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20    General Public License for more details.
21
22    You should have received a copy of the GNU General Public
23    License along with this program; if not, write to the Free
24    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25    MA 02111-1307, USA.
26
27  */
28
29 /* *****FIXME**** fix fixed length of select_cmd[] and insert_cmd[] */
30
31 /* The following is necessary so that we do not include
32  * the dummy external definition of DB.
33  */
34 #define __SQL_C                       /* indicate that this is sql.c */
35
36 #include "bacula.h"
37 #include "cats.h"
38
39 #if    HAVE_MYSQL || HAVE_SQLITE
40
41 /* -----------------------------------------------------------------------
42  *
43  *   Generic Routines (or almost generic)
44  *
45  * -----------------------------------------------------------------------
46  */
47
48 /* Forward referenced subroutines */
49 static int db_create_file_record(B_DB *mdb, ATTR_DBR *ar);
50 static int db_create_filename_record(B_DB *mdb, ATTR_DBR *ar);
51 static int db_create_path_record(B_DB *mdb, ATTR_DBR *ar);
52
53
54 /* Imported subroutines */
55 extern void print_dashes(B_DB *mdb);
56 extern void print_result(B_DB *mdb);
57 extern int QueryDB(char *file, int line, B_DB *db, char *select_cmd);
58 extern int InsertDB(char *file, int line, B_DB *db, char *select_cmd);
59 extern void split_path_and_filename(B_DB *mdb, char *fname);
60
61
62 /* Create a new record for the Job
63  * Returns: 0 on failure
64  *          1 on success
65  */
66 int
67 db_create_job_record(B_DB *mdb, JOB_DBR *jr)
68 {
69    char dt[MAX_TIME_LENGTH];
70    time_t stime;
71    struct tm tm;
72    int stat;
73    char JobId[30];
74    utime_t JobTDate;
75    char ed1[30];
76
77    stime = jr->SchedTime;
78
79    localtime_r(&stime, &tm); 
80    strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
81    JobTDate = (utime_t)stime;
82
83    db_lock(mdb);
84    if (!db_next_index(mdb, "Job", JobId)) {
85       jr->JobId = 0;
86       db_unlock(mdb);
87       return 0;
88    }
89    /* Must create it */
90    Mmsg(&mdb->cmd,
91 "INSERT INTO Job (JobId,Job,Name,Type,Level,JobStatus,SchedTime,JobTDate) VALUES \
92 (%s,'%s','%s','%c','%c','%c','%s',%s)", 
93            JobId, jr->Job, jr->Name, (char)(jr->Type), (char)(jr->Level), 
94            (char)(jr->JobStatus), dt, edit_uint64(JobTDate, ed1));
95
96    if (!INSERT_DB(mdb, mdb->cmd)) {
97       Mmsg2(&mdb->errmsg, _("Create DB Job record %s failed. ERR=%s\n"), 
98             mdb->cmd, sql_strerror(mdb));
99       jr->JobId = 0;
100       stat = 0;
101    } else {
102       jr->JobId = sql_insert_id(mdb);
103       stat = 1;
104    }
105    db_unlock(mdb);
106    return stat;
107 }
108
109 /* Create a JobMedia record for medium used this job   
110  * Returns: 0 on failure
111  *          1 on success
112  */
113 int
114 db_create_jobmedia_record(B_DB *mdb, JOBMEDIA_DBR *jm)
115 {
116    int stat;
117
118    db_lock(mdb);
119    Mmsg(&mdb->cmd, "SELECT JobId, MediaId FROM JobMedia WHERE \
120 JobId=%d AND MediaId=%d", jm->JobId, jm->MediaId);
121
122    Dmsg0(30, mdb->cmd);
123    if (QUERY_DB(mdb, mdb->cmd)) {
124       mdb->num_rows = sql_num_rows(mdb);
125       if (mdb->num_rows > 0) {
126          Mmsg0(&mdb->errmsg, _("Create JobMedia failed. Record already exists.\n"));
127          sql_free_result(mdb);
128          db_unlock(mdb);
129          Dmsg0(0, "Already have JobMedia record\n");
130          return 0;
131       }
132       sql_free_result(mdb);
133    }
134
135    /* Must create it */
136    Mmsg(&mdb->cmd, 
137 "INSERT INTO JobMedia (JobId,MediaId,FirstIndex,LastIndex,\
138 StartFile,EndFile,StartBlock,EndBlock) \
139 VALUES (%u,%u,%u,%u,%u,%u,%u,%u)", 
140        jm->JobId, jm->MediaId, jm->FirstIndex, jm->LastIndex,
141        jm->StartFile, jm->EndFile, jm->StartBlock, jm->EndBlock);
142
143    Dmsg0(30, mdb->cmd);
144    if (!INSERT_DB(mdb, mdb->cmd)) {
145       Mmsg2(&mdb->errmsg, _("Create db JobMedia record %s failed. ERR=%s\n"), mdb->cmd, 
146          sql_strerror(mdb));
147       stat = 0;
148    } else {
149       stat = 1;
150    }
151    db_unlock(mdb);
152    Dmsg0(30, "Return from JobMedia\n");
153    return stat;
154 }
155
156
157
158 /* Create Unique Pool record
159  * Returns: 0 on failure
160  *          1 on success
161  */
162 int
163 db_create_pool_record(B_DB *mdb, POOL_DBR *pr)
164 {
165    int stat;
166    char ed1[30], ed2[30], ed3[50];
167
168    Dmsg0(200, "In create pool\n");
169    db_lock(mdb);
170    Mmsg(&mdb->cmd, "SELECT PoolId,Name FROM Pool WHERE Name='%s'", pr->Name);
171    Dmsg1(200, "selectpool: %s\n", mdb->cmd);
172
173    if (QUERY_DB(mdb, mdb->cmd)) {
174
175       mdb->num_rows = sql_num_rows(mdb);
176    
177       if (mdb->num_rows > 0) {
178          Mmsg1(&mdb->errmsg, _("pool record %s already exists\n"), pr->Name);
179          sql_free_result(mdb);
180          db_unlock(mdb);
181          return 0;
182       }
183       sql_free_result(mdb);
184    }
185
186    /* Must create it */
187    Mmsg(&mdb->cmd, 
188 "INSERT INTO Pool (Name,NumVols,MaxVols,UseOnce,UseCatalog,\
189 AcceptAnyVolume,AutoPrune,Recycle,VolRetention,VolUseDuration,\
190 MaxVolJobs,MaxVolFiles,MaxVolBytes,PoolType,LabelFormat) \
191 VALUES ('%s',%u,%u,%d,%d,%d,%d,%d,%s,%s,%u,%u,%s,'%s','%s')", 
192                   pr->Name,
193                   pr->NumVols, pr->MaxVols,
194                   pr->UseOnce, pr->UseCatalog,
195                   pr->AcceptAnyVolume,
196                   pr->AutoPrune, pr->Recycle,
197                   edit_uint64(pr->VolRetention, ed1),
198                   edit_uint64(pr->VolUseDuration, ed2),
199                   pr->MaxVolJobs, pr->MaxVolFiles,
200                   edit_uint64(pr->MaxVolBytes, ed3),
201                   pr->PoolType, pr->LabelFormat);
202    Dmsg1(200, "Create Pool: %s\n", mdb->cmd);
203    if (!INSERT_DB(mdb, mdb->cmd)) {
204       Mmsg2(&mdb->errmsg, _("Create db Pool record %s failed: ERR=%s\n"), 
205             mdb->cmd, sql_strerror(mdb));
206       pr->PoolId = 0;
207       stat = 0;
208    } else {
209       pr->PoolId = sql_insert_id(mdb);
210       stat = 1;
211    }
212    db_unlock(mdb);
213    
214    return stat;
215 }
216
217
218 /* 
219  * Create Unique Media record   
220  * Returns: 0 on failure
221  *          1 on success
222  */ 
223 int
224 db_create_media_record(B_DB *mdb, MEDIA_DBR *mr)
225 {
226    int stat;
227    char ed1[30], ed2[30], ed3[30], ed4[30];
228
229    db_lock(mdb);
230    Mmsg(&mdb->cmd, "SELECT MediaId FROM Media WHERE VolumeName='%s'", 
231            mr->VolumeName);
232    Dmsg1(110, "selectpool: %s\n", mdb->cmd);
233
234    if (QUERY_DB(mdb, mdb->cmd)) {
235       mdb->num_rows = sql_num_rows(mdb);
236       if (mdb->num_rows > 0) {
237          Mmsg1(&mdb->errmsg, _("Media record %s already exists\n"), mr->VolumeName);
238          sql_free_result(mdb);
239          db_unlock(mdb);
240          return 0;
241       }
242       sql_free_result(mdb);
243    }
244
245    /* Must create it */
246    Mmsg(&mdb->cmd, 
247 "INSERT INTO Media (VolumeName,MediaType,PoolId,MaxVolBytes,VolCapacityBytes," 
248 "Recycle,VolRetention,VolUseDuration,VolStatus,Slot) "
249 "VALUES ('%s','%s',%u,%s,%s,%d,%s,%s,'%s',%d)", 
250                   mr->VolumeName,
251                   mr->MediaType, mr->PoolId, 
252                   edit_uint64(mr->MaxVolBytes,ed1),
253                   edit_uint64(mr->VolCapacityBytes, ed2),
254                   mr->Recycle,
255                   edit_uint64(mr->VolRetention, ed3),
256                   edit_uint64(mr->VolUseDuration, ed4),
257                   mr->VolStatus,
258                   mr->Slot);
259
260    Dmsg1(500, "Create Volume: %s\n", mdb->cmd);
261    if (!INSERT_DB(mdb, mdb->cmd)) {
262       Mmsg2(&mdb->errmsg, _("Create DB Media record %s failed. ERR=%s\n"),
263             mdb->cmd, sql_strerror(mdb));
264       stat = 0;
265    } else {
266       mr->MediaId = sql_insert_id(mdb);
267       stat = 1;
268    }
269    db_unlock(mdb);
270    return stat;
271 }
272
273
274
275 /* 
276  * Create a Unique record for the client -- no duplicates 
277  * Returns: 0 on failure
278  *          1 on success with id in cr->ClientId
279  */
280 int db_create_client_record(B_DB *mdb, CLIENT_DBR *cr)
281 {
282    SQL_ROW row;
283    int stat;
284    char ed1[30], ed2[30];
285
286    db_lock(mdb);
287    Mmsg(&mdb->cmd, "SELECT ClientId,Uname FROM Client WHERE Name='%s'", cr->Name);
288
289    cr->ClientId = 0;
290    if (QUERY_DB(mdb, mdb->cmd)) {
291
292       mdb->num_rows = sql_num_rows(mdb);
293       
294       /* If more than one, report error, but return first row */
295       if (mdb->num_rows > 1) {
296          Mmsg1(&mdb->errmsg, _("More than one Client!: %d\n"), (int)(mdb->num_rows));
297          Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg);
298       }
299       if (mdb->num_rows >= 1) {
300          if ((row = sql_fetch_row(mdb)) == NULL) {
301             Mmsg1(&mdb->errmsg, _("error fetching Client row: %s\n"), sql_strerror(mdb));
302             Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg);
303             sql_free_result(mdb);
304             db_unlock(mdb);
305             return 0;
306          }
307          cr->ClientId = atoi(row[0]);
308          if (row[1]) {
309             strncpy(cr->Uname, row[1], sizeof(cr->Uname)-2);
310             cr->Uname[sizeof(cr->Uname)-1] = 0;
311          } else {
312             cr->Uname[0] = 0;         /* no name */
313          }
314          sql_free_result(mdb);
315          db_unlock(mdb);
316          return 1;
317       }
318       sql_free_result(mdb);
319    }
320
321    /* Must create it */
322    Mmsg(&mdb->cmd, "INSERT INTO Client (Name, Uname, AutoPrune, \
323 FileRetention, JobRetention) VALUES \
324 ('%s', '%s', %d, %s, %s)", cr->Name, cr->Uname, cr->AutoPrune,
325       edit_uint64(cr->FileRetention, ed1),
326       edit_uint64(cr->JobRetention, ed2));
327
328    if (!INSERT_DB(mdb, mdb->cmd)) {
329       Mmsg2(&mdb->errmsg, _("Create DB Client record %s failed. ERR=%s\n"),
330             mdb->cmd, sql_strerror(mdb));
331       Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg);
332       cr->ClientId = 0;
333       stat = 0;
334    } else {
335       cr->ClientId = sql_insert_id(mdb);
336       stat = 1;
337    }
338    db_unlock(mdb);
339    return stat;
340 }
341
342
343 /* 
344  * Create a FileSet record. This record is unique in the
345  *  name and the MD5 signature of the include/exclude sets.
346  *  Returns: 0 on failure
347  *           1 on success with FileSetId in record
348  */
349 int db_create_fileset_record(B_DB *mdb, FILESET_DBR *fsr)
350 {
351    SQL_ROW row;
352    int stat;
353
354    db_lock(mdb);
355    Mmsg(&mdb->cmd, "SELECT FileSetId FROM FileSet WHERE \
356 FileSet='%s' and MD5='%s'", fsr->FileSet, fsr->MD5);
357
358    fsr->FileSetId = 0;
359    if (QUERY_DB(mdb, mdb->cmd)) {
360
361       mdb->num_rows = sql_num_rows(mdb);
362       
363       if (mdb->num_rows > 1) {
364          Mmsg1(&mdb->errmsg, _("More than one FileSet!: %d\n"), (int)(mdb->num_rows));
365          Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg);
366       }
367       if (mdb->num_rows >= 1) {
368          if ((row = sql_fetch_row(mdb)) == NULL) {
369             Mmsg1(&mdb->errmsg, _("error fetching FileSet row: ERR=%s\n"), sql_strerror(mdb));
370             Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg);
371             sql_free_result(mdb);
372             db_unlock(mdb);
373             return 0;
374          }
375          fsr->FileSetId = atoi(row[0]);
376          sql_free_result(mdb);
377          db_unlock(mdb);
378          return 1;
379       }
380       sql_free_result(mdb);
381    }
382
383    /* Must create it */
384    Mmsg(&mdb->cmd, "INSERT INTO FileSet (FileSet, MD5) VALUES \
385 ('%s', '%s')", fsr->FileSet, fsr->MD5);
386
387    if (!INSERT_DB(mdb, mdb->cmd)) {
388       Mmsg2(&mdb->errmsg, _("Create DB FileSet record %s failed. ERR=%s\n"),
389             mdb->cmd, sql_strerror(mdb));
390       Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg);
391       fsr->FileSetId = 0;
392       stat = 0;
393    } else {
394       fsr->FileSetId = sql_insert_id(mdb);
395       stat = 1;
396    }
397
398    db_unlock(mdb);
399    return stat;
400 }
401
402
403 /*
404  *  struct stat
405  *  {
406  *      dev_t         st_dev;       * device *
407  *      ino_t         st_ino;       * inode *
408  *      mode_t        st_mode;      * protection *
409  *      nlink_t       st_nlink;     * number of hard links *
410  *      uid_t         st_uid;       * user ID of owner *
411  *      gid_t         st_gid;       * group ID of owner *
412  *      dev_t         st_rdev;      * device type (if inode device) *
413  *      off_t         st_size;      * total size, in bytes *
414  *      unsigned long st_blksize;   * blocksize for filesystem I/O *
415  *      unsigned long st_blocks;    * number of blocks allocated *
416  *      time_t        st_atime;     * time of last access *
417  *      time_t        st_mtime;     * time of last modification *
418  *      time_t        st_ctime;     * time of last inode change *            
419  *  };
420  */
421
422
423
424 /* 
425  * Create File record in B_DB   
426  *
427  *  In order to reduce database size, we store the File attributes,
428  *  the FileName, and the Path separately.  In principle, there   
429  *  is a single FileName record and a single Path record, no matter
430  *  how many times it occurs.  This is this subroutine, we separate
431  *  the file and the path and create three database records.
432  */
433 int db_create_file_attributes_record(B_DB *mdb, ATTR_DBR *ar)
434 {
435
436    Dmsg1(100, "Fname=%s\n", ar->fname);
437    Dmsg0(50, "put_file_into_catalog\n");
438    /*
439     * Make sure we have an acceptable attributes record.
440     */
441    if (!(ar->Stream == STREAM_UNIX_ATTRIBUTES || ar->Stream == STREAM_WIN32_ATTRIBUTES)) {
442       Mmsg0(&mdb->errmsg, _("Attempt to put non-attributes into catalog\n"));
443       Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg);
444       return 0;
445    }
446
447    db_lock(mdb);
448
449    split_path_and_filename(mdb, ar->fname);
450
451    if (!db_create_filename_record(mdb, ar)) {
452       db_unlock(mdb);
453       return 0;
454    }
455    Dmsg1(100, "db_create_filename_record: %s\n", mdb->esc_name);
456
457
458    if (!db_create_path_record(mdb, ar)) {
459       db_unlock(mdb);
460       return 0;
461    }
462    Dmsg1(100, "db_create_path_record\n", mdb->esc_name);
463
464    /* Now create master File record */
465    if (!db_create_file_record(mdb, ar)) {
466       db_unlock(mdb);
467       return 0;
468    }
469    Dmsg0(50, "db_create_file_record\n");
470
471    Dmsg3(100, "Path=%s File=%s FilenameId=%d\n", mdb->path, mdb->fname, ar->FilenameId);
472    db_unlock(mdb);
473    return 1;
474 }
475
476 /*
477  * This is the master File entry containing the attributes.
478  *  The filename and path records have already been created.
479  */
480 static int db_create_file_record(B_DB *mdb, ATTR_DBR *ar)
481 {
482    int stat;
483
484    ASSERT(ar->JobId);
485    ASSERT(ar->PathId);
486    ASSERT(ar->FilenameId);
487
488    /* Must create it */
489    Mmsg(&mdb->cmd,
490 "INSERT INTO File (FileIndex, JobId, PathId, FilenameId, \
491 LStat, MD5) VALUES (%u, %u, %u, %u, '%s', '0')", 
492       ar->FileIndex, ar->JobId, ar->PathId, ar->FilenameId, 
493       ar->attr);
494
495    if (!INSERT_DB(mdb, mdb->cmd)) {
496       Mmsg2(&mdb->errmsg, _("Create db File record %s failed. ERR=%s"),       
497          mdb->cmd, sql_strerror(mdb));
498       Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg);
499       ar->FileId = 0;
500       stat = 0;
501    } else {
502       ar->FileId = sql_insert_id(mdb);
503       stat = 1;
504    }
505    return stat;
506 }
507
508 /* Create a Unique record for the Path -- no duplicates */
509 static int db_create_path_record(B_DB *mdb, ATTR_DBR *ar)
510 {
511    SQL_ROW row;
512    int stat;
513
514    mdb->esc_name = check_pool_memory_size(mdb->esc_name, mdb->pnl+1);
515    db_escape_string(mdb->esc_name, mdb->path, mdb->pnl);
516
517    if (mdb->cached_path_id != 0 && mdb->cached_path_len == mdb->pnl &&
518        strcmp(mdb->cached_path, mdb->path) == 0) {
519       ar->PathId = mdb->cached_path_id;
520       ASSERT(ar->PathId);
521       return 1;
522    }          
523
524    Mmsg(&mdb->cmd, "SELECT PathId FROM Path WHERE Path='%s'", mdb->path);
525
526    if (QUERY_DB(mdb, mdb->cmd)) {
527
528       mdb->num_rows = sql_num_rows(mdb);
529
530       if (mdb->num_rows > 1) {
531          char ed1[30];
532          Mmsg2(&mdb->errmsg, _("More than one Path!: %s for Path=%s\n"), 
533             edit_uint64(mdb->num_rows, ed1), mdb->path);
534          Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg);
535       }
536       if (mdb->num_rows >= 1) {
537          if ((row = sql_fetch_row(mdb)) == NULL) {
538             Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
539             Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg);
540             sql_free_result(mdb);
541             ar->PathId = 0;
542             ASSERT(ar->PathId);
543             return 0;
544          }
545          ar->PathId = atoi(row[0]);
546          sql_free_result(mdb);
547          /* Cache path */
548          if (ar->PathId != mdb->cached_path_id) {
549             mdb->cached_path_id = ar->PathId;
550             mdb->cached_path_len = mdb->pnl;
551             pm_strcpy(&mdb->cached_path, mdb->path);
552          }
553          ASSERT(ar->PathId);
554          return 1;
555       }
556
557       sql_free_result(mdb);
558    }
559
560    Mmsg(&mdb->cmd, "INSERT INTO Path (Path)  VALUES ('%s')", mdb->path);
561
562    if (!INSERT_DB(mdb, mdb->cmd)) {
563       Mmsg2(&mdb->errmsg, _("Create db Path record %s failed. ERR=%s\n"), 
564          mdb->cmd, sql_strerror(mdb));
565       Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg);
566       ar->PathId = 0;
567       stat = 0;
568    } else {
569       ar->PathId = sql_insert_id(mdb);
570       stat = 1;
571    }
572
573    /* Cache path */
574    if (ar->PathId != mdb->cached_path_id) {
575       mdb->cached_path_id = ar->PathId;
576       mdb->cached_path_len = mdb->pnl;
577       pm_strcpy(&mdb->cached_path, mdb->path);
578    }
579    ASSERT(ar->PathId);
580    return stat;
581 }
582
583 /* Create a Unique record for the filename -- no duplicates */
584 static int db_create_filename_record(B_DB *mdb, ATTR_DBR *ar) 
585 {
586    SQL_ROW row;
587
588    
589    mdb->esc_name = check_pool_memory_size(mdb->esc_name, mdb->fnl+1);
590    db_escape_string(mdb->esc_name, mdb->fname, mdb->fnl);
591
592    Mmsg(&mdb->cmd, "SELECT FilenameId FROM Filename WHERE Name='%s'", mdb->esc_name);
593
594    if (QUERY_DB(mdb, mdb->cmd)) {
595       mdb->num_rows = sql_num_rows(mdb);
596       if (mdb->num_rows > 1) {
597          Mmsg2(&mdb->errmsg, _("More than one Filename!: %d File=%s\n"), 
598             (int)(mdb->num_rows), mdb->esc_name);
599          Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg);
600       }
601       if (mdb->num_rows >= 1) {
602          if ((row = sql_fetch_row(mdb)) == NULL) {
603             Mmsg2(&mdb->errmsg, _("error fetching row for file=%s: ERR=%s\n"), 
604                 mdb->fname, sql_strerror(mdb));
605             Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg);
606             ar->FilenameId = 0;
607          } else {
608             ar->FilenameId = atoi(row[0]);
609          }
610          sql_free_result(mdb);
611          return ar->FilenameId > 0;
612       }
613       sql_free_result(mdb);
614    }
615
616    Mmsg(&mdb->cmd, "INSERT INTO Filename (Name) \
617 VALUES ('%s')", mdb->fname);
618
619    if (!INSERT_DB(mdb, mdb->cmd)) {
620       Mmsg2(&mdb->errmsg, _("Create db Filename record %s failed. ERR=%s\n"), 
621             mdb->cmd, sql_strerror(mdb));
622       Jmsg(mdb->jcr, M_ERROR, 0, "%s", mdb->errmsg);
623       ar->FilenameId = 0;
624    } else {
625       ar->FilenameId = sql_insert_id(mdb);
626    }
627
628    return ar->FilenameId > 0;
629 }
630
631 #endif /* HAVE_MYSQL || HAVE_SQLITE */