2 * Bacula Catalog Database Get record interface routines
3 * Note, these routines generally get a record by id or
4 * by name. If more logic is involved, the routine
7 * Kern Sibbald, March 2000
13 Copyright (C) 2000-2003 Kern Sibbald and John Walker
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation; either version 2 of
18 the License, or (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public
26 License along with this program; if not, write to the Free
27 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
33 /* The following is necessary so that we do not include
34 * the dummy external definition of DB.
36 #define __SQL_C /* indicate that this is sql.c */
41 #if HAVE_MYSQL || HAVE_SQLITE
43 /* -----------------------------------------------------------------------
45 * Generic Routines (or almost generic)
47 * -----------------------------------------------------------------------
50 /* Forward referenced functions */
51 static int db_get_file_record(JCR *jcr, B_DB *mdb, FILE_DBR *fdbr);
52 static int db_get_filename_record(JCR *jcr, B_DB *mdb);
53 static int db_get_path_record(JCR *jcr, B_DB *mdb);
56 /* Imported subroutines */
57 extern void print_result(B_DB *mdb);
58 extern int QueryDB(char *file, int line, JCR *jcr, B_DB *db, char *select_cmd);
59 extern void split_path_and_filename(JCR *jcr, B_DB *mdb, char *fname);
64 * Given a full filename (with path), look up the File record
65 * (with attributes) in the database.
67 * Returns: 0 on failure
68 * 1 on success with the File record in FILE_DBR
70 int db_get_file_attributes_record(JCR *jcr, B_DB *mdb, char *fname, FILE_DBR *fdbr)
73 Dmsg1(20, "Enter get_file_from_catalog fname=%s \n", fname);
76 split_path_and_filename(jcr, mdb, fname);
78 fdbr->FilenameId = db_get_filename_record(jcr, mdb);
80 fdbr->PathId = db_get_path_record(jcr, mdb);
82 stat = db_get_file_record(jcr, mdb, fdbr);
92 * Returns: 0 on failure
95 * DO NOT use Jmsg in this routine.
97 * Note in this routine, we do not use Jmsg because it may be
98 * called to get attributes of a non-existent file, which is
99 * "normal" if a new file is found during Verify.
102 int db_get_file_record(JCR *jcr, B_DB *mdb, FILE_DBR *fdbr)
108 "SELECT FileId, LStat, MD5 from File where File.JobId=%u and File.PathId=%u and \
109 File.FilenameId=%u", fdbr->JobId, fdbr->PathId, fdbr->FilenameId);
111 Dmsg3(050, "Get_file_record JobId=%u FilenameId=%u PathId=%u\n",
112 fdbr->JobId, fdbr->FilenameId, fdbr->PathId);
114 Dmsg1(100, "Query=%s\n", mdb->cmd);
116 if (QUERY_DB(jcr, mdb, mdb->cmd)) {
118 mdb->num_rows = sql_num_rows(mdb);
119 Dmsg1(050, "get_file_record num_rows=%d\n", (int)mdb->num_rows);
121 if (mdb->num_rows > 1) {
122 Mmsg1(&mdb->errmsg, _("get_file_record want 1 got rows=%d\n"),
125 if (mdb->num_rows >= 1) {
126 if ((row = sql_fetch_row(mdb)) == NULL) {
127 Mmsg1(&mdb->errmsg, _("Error fetching row: %s\n"), sql_strerror(mdb));
129 fdbr->FileId = (FileId_t)str_to_int64(row[0]);
130 bstrncpy(fdbr->LStat, row[1], sizeof(fdbr->LStat));
131 bstrncpy(fdbr->SIG, row[2], sizeof(fdbr->SIG));
135 Mmsg2(&mdb->errmsg, _("File record for PathId=%u FilenameId=%u not found.\n"),
136 fdbr->PathId, fdbr->FilenameId);
138 sql_free_result(mdb);
144 /* Get Filename record
145 * Returns: 0 on failure
146 * FilenameId on success
148 * DO NOT use Jmsg in this routine (see notes for get_file_record)
150 static int db_get_filename_record(JCR *jcr, B_DB *mdb)
155 mdb->esc_name = check_pool_memory_size(mdb->esc_name, 2*mdb->fnl+2);
156 db_escape_string(mdb->esc_name, mdb->fname, mdb->fnl);
158 Mmsg(&mdb->cmd, "SELECT FilenameId FROM Filename WHERE Name='%s'", mdb->esc_name);
159 if (QUERY_DB(jcr, mdb, mdb->cmd)) {
162 mdb->num_rows = sql_num_rows(mdb);
164 if (mdb->num_rows > 1) {
165 Mmsg2(&mdb->errmsg, _("More than one Filename!: %s for file: %s\n"),
166 edit_uint64(mdb->num_rows, ed1), mdb->fname);
167 Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg);
169 if (mdb->num_rows >= 1) {
170 if ((row = sql_fetch_row(mdb)) == NULL) {
171 Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
173 FilenameId = atoi(row[0]);
174 if (FilenameId <= 0) {
175 Mmsg2(&mdb->errmsg, _("Get DB Filename record %s found bad record: %d\n"),
176 mdb->cmd, FilenameId);
181 Mmsg1(&mdb->errmsg, _("Filename record: %s not found.\n"), mdb->fname);
183 sql_free_result(mdb);
189 * Returns: 0 on failure
192 * DO NOT use Jmsg in this routine (see notes for get_file_record)
194 static int db_get_path_record(JCR *jcr, B_DB *mdb)
199 mdb->esc_name = check_pool_memory_size(mdb->esc_name, 2*mdb->pnl+2);
200 db_escape_string(mdb->esc_name, mdb->path, mdb->pnl);
202 if (mdb->cached_path_id != 0 && mdb->cached_path_len == mdb->pnl &&
203 strcmp(mdb->cached_path, mdb->path) == 0) {
204 return mdb->cached_path_id;
207 Mmsg(&mdb->cmd, "SELECT PathId FROM Path WHERE Path='%s'", mdb->esc_name);
209 if (QUERY_DB(jcr, mdb, mdb->cmd)) {
211 mdb->num_rows = sql_num_rows(mdb);
213 if (mdb->num_rows > 1) {
214 Mmsg2(&mdb->errmsg, _("More than one Path!: %s for path: %s\n"),
215 edit_uint64(mdb->num_rows, ed1), mdb->path);
216 Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg);
218 /* Even if there are multiple paths, take the first one */
219 if (mdb->num_rows >= 1) {
220 if ((row = sql_fetch_row(mdb)) == NULL) {
221 Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
223 PathId = atoi(row[0]);
225 Mmsg2(&mdb->errmsg, _("Get DB path record %s found bad record: %u\n"),
230 if (PathId != mdb->cached_path_id) {
231 mdb->cached_path_id = PathId;
232 mdb->cached_path_len = mdb->pnl;
233 pm_strcpy(&mdb->cached_path, mdb->path);
238 Mmsg1(&mdb->errmsg, _("Path record: %s not found.\n"), mdb->path);
240 sql_free_result(mdb);
247 * Get Job record for given JobId or Job name
248 * Returns: 0 on failure
251 int db_get_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
256 if (jr->JobId == 0) {
257 Mmsg(&mdb->cmd, "SELECT VolSessionId,VolSessionTime,\
258 PoolId,StartTime,EndTime,JobFiles,JobBytes,JobTDate,Job,JobStatus,\
260 FROM Job WHERE Job='%s'", jr->Job);
262 Mmsg(&mdb->cmd, "SELECT VolSessionId,VolSessionTime,\
263 PoolId,StartTime,EndTime,JobFiles,JobBytes,JobTDate,Job,JobStatus,\
265 FROM Job WHERE JobId=%u", jr->JobId);
268 if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
270 return 0; /* failed */
272 if ((row = sql_fetch_row(mdb)) == NULL) {
273 Mmsg1(&mdb->errmsg, _("No Job found for JobId %u\n"), jr->JobId);
274 sql_free_result(mdb);
276 return 0; /* failed */
279 jr->VolSessionId = str_to_uint64(row[0]);
280 jr->VolSessionTime = str_to_uint64(row[1]);
281 jr->PoolId = str_to_uint64(row[2]);
282 bstrncpy(jr->cStartTime, row[3]!=NULL?row[3]:"", sizeof(jr->cStartTime));
283 bstrncpy(jr->cEndTime, row[4]!=NULL?row[4]:"", sizeof(jr->cEndTime));
284 jr->JobFiles = atol(row[5]);
285 jr->JobBytes = str_to_int64(row[6]);
286 jr->JobTDate = str_to_int64(row[7]);
287 bstrncpy(jr->Job, row[8]!=NULL?row[8]:"", sizeof(jr->Job));
288 jr->JobStatus = (int)*row[9];
289 jr->Type = (int)*row[10];
290 jr->Level = (int)*row[11];
291 sql_free_result(mdb);
298 * Find VolumeNames for a give JobId
299 * Returns: 0 on error or no Volumes found
300 * number of volumes on success
301 * Volumes are concatenated in VolumeNames
302 * separated by a vertical bar (|).
304 * Returns: number of volumes on success
306 int db_get_job_volume_names(JCR *jcr, B_DB *mdb, uint32_t JobId, POOLMEM **VolumeNames)
314 "SELECT VolumeName FROM JobMedia,Media WHERE JobMedia.JobId=%u \
315 AND JobMedia.MediaId=Media.MediaId", JobId);
317 Dmsg1(130, "VolNam=%s\n", mdb->cmd);
319 if (QUERY_DB(jcr, mdb, mdb->cmd)) {
320 mdb->num_rows = sql_num_rows(mdb);
321 Dmsg1(130, "Num rows=%d\n", mdb->num_rows);
322 if (mdb->num_rows <= 0) {
323 Mmsg1(&mdb->errmsg, _("No volumes found for JobId=%d\n"), JobId);
326 stat = mdb->num_rows;
327 for (i=0; i < stat; i++) {
328 if ((row = sql_fetch_row(mdb)) == NULL) {
329 Mmsg2(&mdb->errmsg, _("Error fetching row %d: ERR=%s\n"), i, sql_strerror(mdb));
330 Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
334 if (*VolumeNames[0] != 0) {
335 pm_strcat(VolumeNames, "|");
337 pm_strcat(VolumeNames, row[0]);
341 sql_free_result(mdb);
348 * Find Volume parameters for a give JobId
349 * Returns: 0 on error or no Volumes found
350 * number of volumes on success
351 * List of Volumes and start/end file/blocks (malloced structure!)
353 * Returns: number of volumes on success
355 int db_get_job_volume_parameters(JCR *jcr, B_DB *mdb, uint32_t JobId, VOL_PARAMS **VolParams)
360 VOL_PARAMS *Vols = NULL;
364 "SELECT VolumeName,FirstIndex,LastIndex,StartFile,EndFile,StartBlock,EndBlock"
365 " FROM JobMedia,Media WHERE JobMedia.JobId=%u"
366 " AND JobMedia.MediaId=Media.MediaId ORDER BY VolIndex,JobMediaId", JobId);
368 Dmsg1(130, "VolNam=%s\n", mdb->cmd);
369 if (QUERY_DB(jcr, mdb, mdb->cmd)) {
370 mdb->num_rows = sql_num_rows(mdb);
371 Dmsg1(130, "Num rows=%d\n", mdb->num_rows);
372 if (mdb->num_rows <= 0) {
373 Mmsg1(&mdb->errmsg, _("No volumes found for JobId=%d\n"), JobId);
376 stat = mdb->num_rows;
378 *VolParams = Vols = (VOL_PARAMS *)malloc(stat * sizeof(VOL_PARAMS));
380 for (i=0; i < stat; i++) {
381 if ((row = sql_fetch_row(mdb)) == NULL) {
382 Mmsg2(&mdb->errmsg, _("Error fetching row %d: ERR=%s\n"), i, sql_strerror(mdb));
383 Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
387 bstrncpy(Vols[i].VolumeName, row[0], MAX_NAME_LENGTH);
388 Vols[i].FirstIndex = atoi(row[1]);
389 Vols[i].LastIndex = atoi(row[2]);
390 Vols[i].StartFile = atoi(row[3]);
391 Vols[i].EndFile = atoi(row[4]);
392 Vols[i].StartBlock = atoi(row[5]);
393 Vols[i].EndBlock = atoi(row[6]);
397 sql_free_result(mdb);
406 * Get the number of pool records
408 * Returns: -1 on failure
411 int db_get_num_pool_records(JCR *jcr, B_DB *mdb)
416 Mmsg(&mdb->cmd, "SELECT count(*) from Pool");
417 stat = get_sql_record_max(jcr, mdb);
423 * This function returns a list of all the Pool record ids.
424 * The caller must free ids if non-NULL.
426 * Returns 0: on failure
429 int db_get_pool_ids(JCR *jcr, B_DB *mdb, int *num_ids, uint32_t *ids[])
438 Mmsg(&mdb->cmd, "SELECT PoolId FROM Pool");
439 if (QUERY_DB(jcr, mdb, mdb->cmd)) {
440 *num_ids = sql_num_rows(mdb);
442 id = (uint32_t *)malloc(*num_ids * sizeof(uint32_t));
443 while ((row = sql_fetch_row(mdb)) != NULL) {
444 id[i++] = str_to_uint64(row[0]);
448 sql_free_result(mdb);
451 Mmsg(&mdb->errmsg, _("Pool id select failed: ERR=%s\n"), sql_strerror(mdb));
452 Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
460 * This function returns a list of all the Client record ids.
461 * The caller must free ids if non-NULL.
463 * Returns 0: on failure
466 int db_get_client_ids(JCR *jcr, B_DB *mdb, int *num_ids, uint32_t *ids[])
475 Mmsg(&mdb->cmd, "SELECT ClientId FROM Client");
476 if (QUERY_DB(jcr, mdb, mdb->cmd)) {
477 *num_ids = sql_num_rows(mdb);
479 id = (uint32_t *)malloc(*num_ids * sizeof(uint32_t));
480 while ((row = sql_fetch_row(mdb)) != NULL) {
481 id[i++] = (uint32_t)atoi(row[0]);
485 sql_free_result(mdb);
488 Mmsg(&mdb->errmsg, _("Client id select failed: ERR=%s\n"), sql_strerror(mdb));
489 Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
499 * If the PoolId is non-zero, we get its record,
500 * otherwise, we search on the PoolName
502 * Returns: 0 on failure
505 int db_get_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pdbr)
511 if (pdbr->PoolId != 0) { /* find by id */
513 "SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,AcceptAnyVolume,\
514 AutoPrune,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,\
515 MaxVolBytes,PoolType,LabelFormat FROM Pool WHERE Pool.PoolId=%u", pdbr->PoolId);
516 } else { /* find by name */
518 "SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,AcceptAnyVolume,\
519 AutoPrune,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,\
520 MaxVolBytes,PoolType,LabelFormat FROM Pool WHERE Pool.Name='%s'", pdbr->Name);
523 if (QUERY_DB(jcr, mdb, mdb->cmd)) {
524 mdb->num_rows = sql_num_rows(mdb);
525 if (mdb->num_rows > 1) {
527 Mmsg1(&mdb->errmsg, _("More than one Pool!: %s\n"),
528 edit_uint64(mdb->num_rows, ed1));
529 Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
530 } else if (mdb->num_rows == 1) {
531 if ((row = sql_fetch_row(mdb)) == NULL) {
532 Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
533 Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
535 pdbr->PoolId = str_to_int64(row[0]);
536 bstrncpy(pdbr->Name, row[1]!=NULL?row[1]:"", sizeof(pdbr->Name));
537 pdbr->NumVols = str_to_int64(row[2]);
538 pdbr->MaxVols = str_to_int64(row[3]);
539 pdbr->UseOnce = str_to_int64(row[4]);
540 pdbr->UseCatalog = str_to_int64(row[5]);
541 pdbr->AcceptAnyVolume = str_to_int64(row[6]);
542 pdbr->AutoPrune = str_to_int64(row[7]);
543 pdbr->Recycle = str_to_int64(row[8]);
544 pdbr->VolRetention = str_to_int64(row[9]);
545 pdbr->VolUseDuration = str_to_int64(row[10]);
546 pdbr->MaxVolJobs = str_to_int64(row[11]);
547 pdbr->MaxVolFiles = str_to_int64(row[12]);
548 pdbr->MaxVolBytes = str_to_uint64(row[13]);
549 bstrncpy(pdbr->PoolType, row[13]!=NULL?row[14]:"", sizeof(pdbr->PoolType));
550 bstrncpy(pdbr->LabelFormat, row[14]!=NULL?row[15]:"", sizeof(pdbr->LabelFormat));
554 sql_free_result(mdb);
561 * If the ClientId is non-zero, we get its record,
562 * otherwise, we search on the Client Name
564 * Returns: 0 on failure
567 int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cdbr)
573 if (cdbr->ClientId != 0) { /* find by id */
575 "SELECT ClientId,Name,Uname,AutoPrune,FileRetention,JobRetention "
576 "FROM Client WHERE Client.ClientId=%u", cdbr->ClientId);
577 } else { /* find by name */
579 "SELECT ClientId,Name,Uname,AutoPrune,FileRetention,JobRetention "
580 "FROM Client WHERE Client.Name='%s'", cdbr->Name);
583 if (QUERY_DB(jcr, mdb, mdb->cmd)) {
584 mdb->num_rows = sql_num_rows(mdb);
585 if (mdb->num_rows > 1) {
587 Mmsg1(&mdb->errmsg, _("More than one Client!: %s\n"),
588 edit_uint64(mdb->num_rows, ed1));
589 Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
590 } else if (mdb->num_rows == 1) {
591 if ((row = sql_fetch_row(mdb)) == NULL) {
592 Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
593 Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
595 cdbr->ClientId = str_to_int64(row[0]);
596 bstrncpy(cdbr->Name, row[1]!=NULL?row[1]:"", sizeof(cdbr->Name));
597 bstrncpy(cdbr->Uname, row[2]!=NULL?row[1]:"", sizeof(cdbr->Uname));
598 cdbr->AutoPrune = str_to_int64(row[3]);
599 cdbr->FileRetention = str_to_int64(row[4]);
600 cdbr->JobRetention = str_to_int64(row[5]);
604 sql_free_result(mdb);
611 /* Get FileSet Record
612 * If the FileSetId is non-zero, we get its record,
613 * otherwise, we search on the name
615 * Returns: 0 on failure
618 int db_get_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr)
624 if (fsr->FileSetId != 0) { /* find by id */
626 "SELECT FileSetId,FileSet,MD5,CreateTime FROM FileSet "
627 "WHERE FileSetId=%u", fsr->FileSetId);
628 } else { /* find by name */
630 "SELECT FileSetId,FileSet,CreateTime MD5,FROM FileSet "
631 "WHERE FileSet='%s'", fsr->FileSet);
634 if (QUERY_DB(jcr, mdb, mdb->cmd)) {
635 mdb->num_rows = sql_num_rows(mdb);
636 if (mdb->num_rows > 1) {
638 Mmsg1(&mdb->errmsg, _("Error got %s FileSets but expected only one!\n"),
639 edit_uint64(mdb->num_rows, ed1));
640 sql_data_seek(mdb, mdb->num_rows-1);
642 if ((row = sql_fetch_row(mdb)) == NULL) {
643 Mmsg1(&mdb->errmsg, _("FileSet record \"%s\" not found.\n"), fsr->FileSet);
645 fsr->FileSetId = atoi(row[0]);
646 bstrncpy(fsr->FileSet, row[1]!=NULL?row[1]:"", sizeof(fsr->FileSet));
647 bstrncpy(fsr->MD5, row[2]!=NULL?row[2]:"", sizeof(fsr->MD5));
648 bstrncpy(fsr->cCreateTime, row[3]!=NULL?row[3]:"", sizeof(fsr->cCreateTime));
649 stat = fsr->FileSetId;
651 sql_free_result(mdb);
659 * Get the number of Media records
661 * Returns: -1 on failure
664 int db_get_num_media_records(JCR *jcr, B_DB *mdb)
669 Mmsg(&mdb->cmd, "SELECT count(*) from Media");
670 stat = get_sql_record_max(jcr, mdb);
677 * This function returns a list of all the Media record ids.
678 * The caller must free ids if non-NULL.
680 * Returns 0: on failure
683 int db_get_media_ids(JCR *jcr, B_DB *mdb, int *num_ids, uint32_t *ids[])
692 Mmsg(&mdb->cmd, "SELECT MediaId FROM Media");
693 if (QUERY_DB(jcr, mdb, mdb->cmd)) {
694 *num_ids = sql_num_rows(mdb);
696 id = (uint32_t *)malloc(*num_ids * sizeof(uint32_t));
697 while ((row = sql_fetch_row(mdb)) != NULL) {
698 id[i++] = (uint32_t)atoi(row[0]);
702 sql_free_result(mdb);
705 Mmsg(&mdb->errmsg, _("Media id select failed: ERR=%s\n"), sql_strerror(mdb));
706 Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
716 * Returns: 0 on failure
719 int db_get_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
725 if (mr->MediaId == 0 && mr->VolumeName[0] == 0) {
726 Mmsg(&mdb->cmd, "SELECT count(*) from Media");
727 mr->MediaId = get_sql_record_max(jcr, mdb);
731 if (mr->MediaId != 0) { /* find by id */
732 Mmsg(&mdb->cmd, "SELECT MediaId,VolumeName,VolJobs,VolFiles,VolBlocks,\
733 VolBytes,VolMounts,VolErrors,VolWrites,MaxVolBytes,VolCapacityBytes,\
734 MediaType,VolStatus,PoolId,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,\
735 Recycle,Slot,FirstWritten,LastWritten \
736 FROM Media WHERE MediaId=%d", mr->MediaId);
737 } else { /* find by name */
738 Mmsg(&mdb->cmd, "SELECT MediaId,VolumeName,VolJobs,VolFiles,VolBlocks,\
739 VolBytes,VolMounts,VolErrors,VolWrites,MaxVolBytes,VolCapacityBytes,\
740 MediaType,VolStatus,PoolId,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,\
741 Recycle,Slot,FirstWritten,LastWritten \
742 FROM Media WHERE VolumeName='%s'", mr->VolumeName);
745 if (QUERY_DB(jcr, mdb, mdb->cmd)) {
746 mdb->num_rows = sql_num_rows(mdb);
747 if (mdb->num_rows > 1) {
749 Mmsg1(&mdb->errmsg, _("More than one Volume!: %s\n"),
750 edit_uint64(mdb->num_rows, ed1));
751 Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
752 } else if (mdb->num_rows == 1) {
753 if ((row = sql_fetch_row(mdb)) == NULL) {
754 Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
755 Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
758 mr->MediaId = str_to_int64(row[0]);
759 bstrncpy(mr->VolumeName, row[1]!=NULL?row[1]:"", sizeof(mr->VolumeName));
760 mr->VolJobs = str_to_int64(row[2]);
761 mr->VolFiles = str_to_int64(row[3]);
762 mr->VolBlocks = str_to_int64(row[4]);
763 mr->VolBytes = str_to_uint64(row[5]);
764 mr->VolMounts = str_to_int64(row[6]);
765 mr->VolErrors = str_to_int64(row[7]);
766 mr->VolWrites = str_to_int64(row[8]);
767 mr->MaxVolBytes = str_to_uint64(row[9]);
768 mr->VolCapacityBytes = str_to_uint64(row[10]);
769 bstrncpy(mr->MediaType, row[11]!=NULL?row[11]:"", sizeof(mr->MediaType));
770 bstrncpy(mr->VolStatus, row[12]!=NULL?row[12]:"", sizeof(mr->VolStatus));
771 mr->PoolId = str_to_int64(row[13]);
772 mr->VolRetention = str_to_uint64(row[14]);
773 mr->VolUseDuration = str_to_uint64(row[15]);
774 mr->MaxVolJobs = str_to_int64(row[16]);
775 mr->MaxVolFiles = str_to_int64(row[17]);
776 mr->Recycle = str_to_int64(row[18]);
777 mr->Slot = str_to_int64(row[19]);
778 bstrncpy(mr->cFirstWritten, row[20]!=NULL?row[20]:"", sizeof(mr->cFirstWritten));
779 mr->FirstWritten = (time_t)str_to_utime(mr->cFirstWritten);
780 bstrncpy(mr->cLastWritten, row[21]!=NULL?row[21]:"", sizeof(mr->cLastWritten));
781 mr->LastWritten = (time_t)str_to_utime(mr->cLastWritten);
785 if (mr->MediaId != 0) {
786 Mmsg1(&mdb->errmsg, _("Media record MediaId=%u not found.\n"), mr->MediaId);
788 Mmsg1(&mdb->errmsg, _("Media record for Volume \"%s\" not found.\n"),
792 sql_free_result(mdb);
799 #endif /* HAVE_MYSQL || HAVE_SQLITE */