-int get_sql_record_max(void *jcr, B_DB *mdb);
-int db_next_index(void *jcr, B_DB *mdb, char *table, char *index);
-int db_sql_query(B_DB *mdb, char *cmd, DB_RESULT_HANDLER *result_handler, void *ctx);
-int check_tables_version(void *jcr, B_DB *mdb);
-void _db_unlock(char *file, int line, B_DB *mdb);
-void _db_lock(char *file, int line, B_DB *mdb);
-void db_start_transaction(void *jcr, B_DB *mdb);
-void db_end_transaction(void *jcr, B_DB *mdb);
-
-/* create.c */
-int db_create_file_attributes_record(void *jcr, B_DB *mdb, ATTR_DBR *ar);
-int db_create_job_record(void *jcr, B_DB *db, JOB_DBR *jr);
-int db_create_media_record(void *jcr, B_DB *db, MEDIA_DBR *media_dbr);
-int db_create_client_record(void *jcr, B_DB *db, CLIENT_DBR *cr);
-int db_create_fileset_record(void *jcr, B_DB *db, FILESET_DBR *fsr);
-int db_create_pool_record(void *jcr, B_DB *db, POOL_DBR *pool_dbr);
-int db_create_jobmedia_record(void *jcr, B_DB *mdb, JOBMEDIA_DBR *jr);
-
-/* delete.c */
-int db_delete_pool_record(void *jcr, B_DB *db, POOL_DBR *pool_dbr);
-int db_delete_media_record(void *jcr, B_DB *mdb, MEDIA_DBR *mr);
-
-/* find.c */
-int db_find_job_start_time(void *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime);
-int db_find_last_jobid(void *jcr, B_DB *mdb, JOB_DBR *jr);
-int db_find_next_volume(void *jcr, B_DB *mdb, int index, MEDIA_DBR *mr);
-
-/* get.c */
-int db_get_pool_record(void *jcr, B_DB *db, POOL_DBR *pdbr);
-int db_get_client_record(void *jcr, B_DB *mdb, CLIENT_DBR *cr);
-int db_get_job_record(void *jcr, B_DB *mdb, JOB_DBR *jr);
-int db_get_job_volume_names(void *jcr, B_DB *mdb, uint32_t JobId, POOLMEM **VolumeNames);
-int db_get_file_attributes_record(void *jcr, B_DB *mdb, char *fname, FILE_DBR *fdbr);
-int db_get_fileset_record(void *jcr, B_DB *mdb, FILESET_DBR *fsr);
-int db_get_media_record(void *jcr, B_DB *mdb, MEDIA_DBR *mr);
-int db_get_num_media_records(void *jcr, B_DB *mdb);
-int db_get_num_pool_records(void *jcr, B_DB *mdb);
-int db_get_pool_ids(void *jcr, B_DB *mdb, int *num_ids, uint32_t **ids);
-int db_get_client_ids(void *jcr, B_DB *mdb, int *num_ids, uint32_t **ids);
-int db_get_media_ids(void *jcr, B_DB *mdb, int *num_ids, uint32_t **ids);
-int db_get_job_volume_parameters(void *jcr, B_DB *mdb, uint32_t JobId, VOL_PARAMS **VolParams);
-int db_get_client_record(void *jcr, B_DB *mdb, CLIENT_DBR *cdbr);
-
-
-/* list.c */
-void db_list_pool_records(void *jcr, B_DB *db, DB_LIST_HANDLER sendit, void *ctx);
-void db_list_job_records(void *jcr, B_DB *db, JOB_DBR *jr, DB_LIST_HANDLER sendit, void *ctx);
-void db_list_job_totals(void *jcr, B_DB *db, JOB_DBR *jr, DB_LIST_HANDLER sendit, void *ctx);
-void db_list_files_for_job(void *jcr, B_DB *db, uint32_t jobid, DB_LIST_HANDLER sendit, void *ctx);
-void db_list_media_records(void *jcr, B_DB *mdb, MEDIA_DBR *mdbr, DB_LIST_HANDLER *sendit, void *ctx);
-void db_list_jobmedia_records(void *jcr, B_DB *mdb, uint32_t JobId, DB_LIST_HANDLER *sendit, void *ctx);
-int db_list_sql_query(void *jcr, B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx, int verbose);
-void db_list_client_records(void *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx);
-
-/* update.c */
-int db_update_job_start_record(void *jcr, B_DB *db, JOB_DBR *jr);
-int db_update_job_end_record(void *jcr, B_DB *db, JOB_DBR *jr);
-int db_update_pool_record(void *jcr, B_DB *db, POOL_DBR *pr);
-int db_update_media_record(void *jcr, B_DB *db, MEDIA_DBR *mr);
-int db_add_MD5_to_file_record(void *jcr, B_DB *mdb, FileId_t FileId, char *MD5);
-int db_mark_file_record(void *jcr, B_DB *mdb, FileId_t FileId, JobId_t JobId);
+int db_next_index(JCR *jcr, B_DB *mdb, char *table, char *index);
+bool db_sql_query(B_DB *mdb, const char *cmd, DB_RESULT_HANDLER *result_handler, void *ctx);
+void db_start_transaction(JCR *jcr, B_DB *mdb);
+void db_end_transaction(JCR *jcr, B_DB *mdb);
+int db_int64_handler(void *ctx, int num_fields, char **row);
+void db_thread_cleanup();
+void _dbg_print_db(JCR *jcr, FILE *fp);
+
+/* sql_create.c */
+bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
+bool db_create_job_record(JCR *jcr, B_DB *db, JOB_DBR *jr);
+int db_create_media_record(JCR *jcr, B_DB *db, MEDIA_DBR *media_dbr);
+int db_create_client_record(JCR *jcr, B_DB *db, CLIENT_DBR *cr);
+bool db_create_fileset_record(JCR *jcr, B_DB *db, FILESET_DBR *fsr);
+bool db_create_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pool_dbr);
+bool db_create_jobmedia_record(JCR *jcr, B_DB *mdb, JOBMEDIA_DBR *jr);
+int db_create_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr);
+bool db_create_device_record(JCR *jcr, B_DB *mdb, DEVICE_DBR *dr);
+bool db_create_storage_record(JCR *jcr, B_DB *mdb, STORAGE_DBR *sr);
+bool db_create_mediatype_record(JCR *jcr, B_DB *mdb, MEDIATYPE_DBR *mr);
+bool db_write_batch_file_records(JCR *jcr);
+bool my_batch_start(JCR *jcr, B_DB *mdb);
+bool my_batch_end(JCR *jcr, B_DB *mdb, const char *error);
+bool my_batch_insert(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
+
+/* sql_delete.c */
+int db_delete_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pool_dbr);
+int db_delete_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr);
+
+/* sql_find.c */
+bool db_find_last_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime, int JobLevel);
+bool db_find_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime);
+bool db_find_last_jobid(JCR *jcr, B_DB *mdb, const char *Name, JOB_DBR *jr);
+int db_find_next_volume(JCR *jcr, B_DB *mdb, int index, bool InChanger, MEDIA_DBR *mr);
+bool db_find_failed_job_since(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM *stime, int &JobLevel);
+
+/* sql_get.c */
+bool db_get_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pdbr);
+int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr);
+bool db_get_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr);
+int db_get_job_volume_names(JCR *jcr, B_DB *mdb, JobId_t JobId, POOLMEM **VolumeNames);
+int db_get_file_attributes_record(JCR *jcr, B_DB *mdb, char *fname, JOB_DBR *jr, FILE_DBR *fdbr);
+int db_get_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr);
+bool db_get_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr);
+int db_get_num_media_records(JCR *jcr, B_DB *mdb);
+int db_get_num_pool_records(JCR *jcr, B_DB *mdb);
+int db_get_pool_ids(JCR *jcr, B_DB *mdb, int *num_ids, DBId_t **ids);
+int db_get_client_ids(JCR *jcr, B_DB *mdb, int *num_ids, DBId_t **ids);
+bool db_get_media_ids(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr, int *num_ids, uint32_t **ids);
+int db_get_job_volume_parameters(JCR *jcr, B_DB *mdb, JobId_t JobId, VOL_PARAMS **VolParams);
+int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cdbr);
+int db_get_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr);
+bool db_get_query_dbids(JCR *jcr, B_DB *mdb, POOL_MEM &query, dbid_list &ids);
+bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, DB_RESULT_HANDLER *result_handler, void *ctx);
+bool db_accurate_get_jobids(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM *jobids);
+int db_get_int_handler(void *ctx, int num_fields, char **row);
+
+
+/* sql_list.c */
+enum e_list_type {
+ HORZ_LIST,
+ VERT_LIST
+};
+void db_list_pool_records(JCR *jcr, B_DB *db, POOL_DBR *pr, DB_LIST_HANDLER sendit, void *ctx, e_list_type type);
+void db_list_job_records(JCR *jcr, B_DB *db, JOB_DBR *jr, DB_LIST_HANDLER sendit, void *ctx, e_list_type type);
+void db_list_job_totals(JCR *jcr, B_DB *db, JOB_DBR *jr, DB_LIST_HANDLER sendit, void *ctx);
+void db_list_files_for_job(JCR *jcr, B_DB *db, uint32_t jobid, DB_LIST_HANDLER sendit, void *ctx);
+void db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
+void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, JobId_t JobId, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
+void db_list_joblog_records(JCR *jcr, B_DB *mdb, JobId_t JobId, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
+int db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query, DB_LIST_HANDLER *sendit, void *ctx, int verbose, e_list_type type);
+void db_list_client_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
+void db_list_copies_records(JCR *jcr, B_DB *mdb, uint32_t limit, char *jobids, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
+
+/* sql_update.c */
+bool db_update_job_start_record(JCR *jcr, B_DB *db, JOB_DBR *jr);
+int db_update_job_end_record(JCR *jcr, B_DB *db, JOB_DBR *jr);
+int db_update_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr);
+int db_update_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pr);
+bool db_update_storage_record(JCR *jcr, B_DB *mdb, STORAGE_DBR *sr);
+int db_update_media_record(JCR *jcr, B_DB *db, MEDIA_DBR *mr);
+int db_update_media_defaults(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr);
+int db_update_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr);
+int db_add_digest_to_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, char *digest, int type);
+int db_mark_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, JobId_t JobId);
+void db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr);
+int db_update_stats(JCR *jcr, B_DB *mdb, utime_t age);