6 * Anyone who accesses the database will need to include
9 * This file contains definitions common to sql.c and
10 * the external world, and definitions destined only
11 * for the external world. This is control with
12 * the define __SQL_C, which is defined only in sql.c
18 Copyright (C) 2000-2005 Kern Sibbald
20 This program is free software; you can redistribute it and/or
21 modify it under the terms of the GNU General Public License as
22 published by the Free Software Foundation; either version 2 of
23 the License, or (at your option) any later version.
25 This program is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 General Public License for more details.
30 You should have received a copy of the GNU General Public
31 License along with this program; if not, write to the Free
32 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
38 Here is how database versions work.
40 While I am working on a new release with database changes, the
41 update scripts are in the src/cats directory under the names
42 update_xxx_tables.in. Most of the time, I make database updates
43 in one go and immediately update the version, but not always. If
44 there are going to be several updates as is the case with version
45 1.37, then I will often forgo changing the version until the last
46 update otherwise I will end up with too many versions and a lot
49 When I am pretty sure there will be no more updates, I will
50 change the version from 8 to 9 (in the present case), and when I
51 am 100% sure there will be no more changes, the update script
52 will be copied to the updatedb directory with the correct name
53 (in the present case 8 to 9).
55 Now, in principle, each of the different DB implementations
56 can have a different version, but in practice they are all
57 the same (simplifies things). The exception is the internal
58 database, which is no longer used, and hence, no longer changes.
66 typedef void (DB_LIST_HANDLER)(void *, const char *);
67 typedef int (DB_RESULT_HANDLER)(void *, int, char **);
69 #define db_lock(mdb) _db_lock(__FILE__, __LINE__, mdb)
70 #define db_unlock(mdb) _db_unlock(__FILE__, __LINE__, mdb)
80 /* Define opaque structure for sqlite */
85 #define IS_NUM(x) ((x) == 1)
86 #define IS_NOT_NULL(x) ((x) == 1)
88 typedef struct s_sql_field {
89 char *name; /* name of column */
90 int length; /* length */
91 int max_length; /* max length */
92 uint32_t type; /* type */
93 uint32_t flags; /* flags */
97 * This is the "real" definition that should only be
98 * used inside sql.c and associated database interface
102 typedef struct s_db {
103 BQUEUE bq; /* queue control */
104 brwlock_t lock; /* transaction lock */
108 int nrow; /* nrow returned from sqlite */
109 int ncolumn; /* ncolum returned from sqlite */
110 int num_rows; /* used by code */
111 int row; /* seek row */
112 int field; /* seek field */
113 SQL_FIELD **fields; /* defined fields */
117 char *db_address; /* host name address */
118 char *db_socket; /* socket for local access */
120 int db_port; /* port for host name address */
121 bool connected; /* connection made to db */
122 bool have_insert_id; /* do not have insert id */
123 bool fields_defined; /* set when fields defined */
124 char *sqlite_errmsg; /* error message returned by sqlite */
125 POOLMEM *errmsg; /* nicely edited error message */
126 POOLMEM *cmd; /* SQL command string */
127 POOLMEM *cached_path; /* cached path name */
128 int cached_path_len; /* length of cached path */
129 uint32_t cached_path_id; /* cached path id */
130 bool allow_transactions; /* transactions allowed */
131 bool transaction; /* transaction started */
132 int changes; /* changes during transaction */
133 POOLMEM *fname; /* Filename only */
134 POOLMEM *path; /* Path only */
135 POOLMEM *esc_name; /* Escaped file/path name */
136 int fnl; /* file name length */
137 int pnl; /* path name length */
142 * "Generic" names for easier conversion
146 #define sql_store_result(x) (x)->result
147 #define sql_free_result(x) my_sqlite_free_table(x)
148 #define sql_fetch_row(x) my_sqlite_fetch_row(x)
149 #define sql_query(x, y) my_sqlite_query((x), (y))
151 #define sql_insert_id(x,y) sqlite3_last_insert_rowid((x)->db)
152 #define sql_close(x) sqlite3_close((x)->db)
154 #define sql_insert_id(x,y) sqlite_last_insert_rowid((x)->db)
155 #define sql_close(x) sqlite_close((x)->db)
157 #define sql_strerror(x) (x)->sqlite_errmsg?(x)->sqlite_errmsg:"unknown"
158 #define sql_num_rows(x) (x)->nrow
159 #define sql_data_seek(x, i) (x)->row = (i)
160 #define sql_affected_rows(x) 1
161 #define sql_field_seek(x, y) my_sqlite_field_seek((x), (y))
162 #define sql_fetch_field(x) my_sqlite_fetch_field(x)
163 #define sql_num_fields(x) ((x)->ncolumn)
164 #define SQL_ROW char**
168 /* In cats/sqlite.c */
169 void my_sqlite_free_table(B_DB *mdb);
170 SQL_ROW my_sqlite_fetch_row(B_DB *mdb);
171 int my_sqlite_query(B_DB *mdb, char *cmd);
172 void my_sqlite_field_seek(B_DB *mdb, int field);
173 SQL_FIELD *my_sqlite_fetch_field(B_DB *mdb);
184 #define BDB_VERSION 9
188 /* Define opaque structure for sqlite */
193 #define IS_NUM(x) ((x) == 1)
194 #define IS_NOT_NULL(x) ((x) == 1)
196 typedef struct s_sql_field {
197 char *name; /* name of column */
198 int length; /* length */
199 int max_length; /* max length */
200 uint32_t type; /* type */
201 uint32_t flags; /* flags */
205 * This is the "real" definition that should only be
206 * used inside sql.c and associated database interface
210 typedef struct s_db {
211 BQUEUE bq; /* queue control */
212 brwlock_t lock; /* transaction lock */
216 int nrow; /* nrow returned from sqlite */
217 int ncolumn; /* ncolum returned from sqlite */
218 int num_rows; /* used by code */
219 int row; /* seek row */
220 int field; /* seek field */
221 SQL_FIELD **fields; /* defined fields */
225 char *db_address; /* host name address */
226 char *db_socket; /* socket for local access */
228 int db_port; /* port for host name address */
229 bool connected; /* connection made to db */
230 bool have_insert_id; /* do not have insert id */
231 bool fields_defined; /* set when fields defined */
232 char *sqlite_errmsg; /* error message returned by sqlite */
233 POOLMEM *errmsg; /* nicely edited error message */
234 POOLMEM *cmd; /* SQL command string */
235 POOLMEM *cached_path; /* cached path name */
236 int cached_path_len; /* length of cached path */
237 uint32_t cached_path_id; /* cached path id */
238 bool allow_transactions; /* transactions allowed */
239 bool transaction; /* transaction started */
240 int changes; /* changes during transaction */
241 POOLMEM *fname; /* Filename only */
242 POOLMEM *path; /* Path only */
243 POOLMEM *esc_name; /* Escaped file/path name */
244 int fnl; /* file name length */
245 int pnl; /* path name length */
249 * Conversion of sqlite 2 names to sqlite3
251 #define sqlite_last_insert_rowid sqlite3_last_insert_rowid
252 #define sqlite_open sqlite3_open
253 #define sqlite_close sqlite3_close
254 #define sqlite_result sqlite3_result
255 #define sqlite_exec sqlite3_exec
256 #define sqlite_get_table sqlite3_get_table
257 #define sqlite_free_table sqlite3_free_table
261 * "Generic" names for easier conversion
265 #define sql_store_result(x) (x)->result
266 #define sql_free_result(x) my_sqlite_free_table(x)
267 #define sql_fetch_row(x) my_sqlite_fetch_row(x)
268 #define sql_query(x, y) my_sqlite_query((x), (y))
270 #define sql_insert_id(x,y) sqlite3_last_insert_rowid((x)->db)
271 #define sql_close(x) sqlite3_close((x)->db)
273 #define sql_insert_id(x,y) sqlite_last_insert_rowid((x)->db)
274 #define sql_close(x) sqlite_close((x)->db)
276 #define sql_strerror(x) (x)->sqlite_errmsg?(x)->sqlite_errmsg:"unknown"
277 #define sql_num_rows(x) (x)->nrow
278 #define sql_data_seek(x, i) (x)->row = (i)
279 #define sql_affected_rows(x) 1
280 #define sql_field_seek(x, y) my_sqlite_field_seek((x), (y))
281 #define sql_fetch_field(x) my_sqlite_fetch_field(x)
282 #define sql_num_fields(x) ((x)->ncolumn)
283 #define SQL_ROW char**
287 /* In cats/sqlite.c */
288 void my_sqlite_free_table(B_DB *mdb);
289 SQL_ROW my_sqlite_fetch_row(B_DB *mdb);
290 int my_sqlite_query(B_DB *mdb, char *cmd);
291 void my_sqlite_field_seek(B_DB *mdb, int field);
292 SQL_FIELD *my_sqlite_fetch_field(B_DB *mdb);
299 #define BDB_VERSION 9
304 * This is the "real" definition that should only be
305 * used inside sql.c and associated database interface
310 typedef struct s_db {
311 BQUEUE bq; /* queue control */
312 brwlock_t lock; /* transaction lock */
317 my_ulonglong num_rows;
322 char *db_address; /* host address */
323 char *db_socket; /* socket for local access */
324 int db_port; /* port of host address */
325 int have_insert_id; /* do have insert_id() */
327 POOLMEM *errmsg; /* nicely edited error message */
328 POOLMEM *cmd; /* SQL command string */
329 POOLMEM *cached_path;
330 int cached_path_len; /* length of cached path */
331 uint32_t cached_path_id;
332 int changes; /* changes made to db */
333 POOLMEM *fname; /* Filename only */
334 POOLMEM *path; /* Path only */
335 POOLMEM *esc_name; /* Escaped file/path name */
336 int fnl; /* file name length */
337 int pnl; /* path name length */
340 #define DB_STATUS int
342 /* "Generic" names for easier conversion */
343 #define sql_store_result(x) mysql_store_result((x)->db)
344 #define sql_free_result(x) mysql_free_result((x)->result)
345 #define sql_fetch_row(x) mysql_fetch_row((x)->result)
346 #define sql_query(x, y) mysql_query((x)->db, (y))
347 #define sql_close(x) mysql_close((x)->db)
348 #define sql_strerror(x) mysql_error((x)->db)
349 #define sql_num_rows(x) mysql_num_rows((x)->result)
350 #define sql_data_seek(x, i) mysql_data_seek((x)->result, (i))
351 #define sql_affected_rows(x) mysql_affected_rows((x)->db)
352 #define sql_insert_id(x,y) mysql_insert_id((x)->db)
353 #define sql_field_seek(x, y) mysql_field_seek((x)->result, (y))
354 #define sql_fetch_field(x) mysql_fetch_field((x)->result)
355 #define sql_num_fields(x) (int)mysql_num_fields((x)->result)
356 #define SQL_ROW MYSQL_ROW
357 #define SQL_FIELD MYSQL_FIELD
361 #ifdef HAVE_POSTGRESQL
363 #define BDB_VERSION 9
365 #include <libpq-fe.h>
367 /* TEMP: the following is taken from select OID, typname from pg_type; */
368 #define IS_NUM(x) ((x) == 20 || (x) == 21 || (x) == 23 || (x) == 700 || (x) == 701)
369 #define IS_NOT_NULL(x) ((x) == 1)
371 typedef char **POSTGRESQL_ROW;
372 typedef struct pg_field {
376 unsigned int flags; // 1 == not null
381 * This is the "real" definition that should only be
382 * used inside sql.c and associated database interface
385 * P O S T G R E S Q L
387 typedef struct s_db {
388 BQUEUE bq; /* queue control */
389 brwlock_t lock; /* transaction lock */
394 POSTGRESQL_FIELD *fields;
397 int row_number; /* what row number did we get via my_postgresql_data_seek? */
398 int field_number; /* what field number did we get via my_postgresql_field_seek? */
403 char *db_address; /* host address */
404 char *db_socket; /* socket for local access */
405 int db_port; /* port of host address */
406 int have_insert_id; /* do have insert_id() */
408 POOLMEM *errmsg; /* nicely edited error message */
409 POOLMEM *cmd; /* SQL command string */
410 POOLMEM *cached_path;
411 int cached_path_len; /* length of cached path */
412 uint32_t cached_path_id;
413 bool allow_transactions; /* transactions allowed */
414 bool transaction; /* transaction started */
415 int changes; /* changes made to db */
416 POOLMEM *fname; /* Filename only */
417 POOLMEM *path; /* Path only */
418 POOLMEM *esc_name; /* Escaped file/path name */
419 int fnl; /* file name length */
420 int pnl; /* path name length */
423 void my_postgresql_free_result(B_DB *mdb);
424 POSTGRESQL_ROW my_postgresql_fetch_row (B_DB *mdb);
425 int my_postgresql_query (B_DB *mdb, const char *query);
426 void my_postgresql_data_seek (B_DB *mdb, int row);
427 int my_postgresql_currval (B_DB *mdb, char *table_name);
428 void my_postgresql_field_seek (B_DB *mdb, int row);
429 POSTGRESQL_FIELD * my_postgresql_fetch_field(B_DB *mdb);
432 /* "Generic" names for easier conversion */
433 #define sql_store_result(x) ((x)->result)
434 #define sql_free_result(x) my_postgresql_free_result(x)
435 #define sql_fetch_row(x) my_postgresql_fetch_row(x)
436 #define sql_query(x, y) my_postgresql_query((x), (y))
437 #define sql_close(x) PQfinish((x)->db)
438 #define sql_strerror(x) PQresultErrorMessage((x)->result)
439 #define sql_num_rows(x) ((unsigned) PQntuples((x)->result))
440 #define sql_data_seek(x, i) my_postgresql_data_seek((x), (i))
441 #define sql_affected_rows(x) ((unsigned) atoi(PQcmdTuples((x)->result)))
442 #define sql_insert_id(x,y) my_postgresql_currval((x), (y))
443 #define sql_field_seek(x, y) my_postgresql_field_seek((x), (y))
444 #define sql_fetch_field(x) my_postgresql_fetch_field(x)
445 #define sql_num_fields(x) ((x)->num_fields)
446 #define SQL_ROW POSTGRESQL_ROW
447 #define SQL_FIELD POSTGRESQL_FIELD
449 #else /* USE BACULA DB routines */
451 #define HAVE_BACULA_DB 1
453 /* Change this each time there is some incompatible
454 * file format change!!!!
456 #define BDB_VERSION 13 /* file version number */
459 int bdb_version; /* Version number */
460 uint32_t JobId; /* next Job Id */
461 uint32_t PoolId; /* next Pool Id */
462 uint32_t MediaId; /* next Media Id */
463 uint32_t JobMediaId; /* next JobMedia Id */
464 uint32_t ClientId; /* next Client Id */
465 uint32_t FileSetId; /* nest FileSet Id */
466 time_t time; /* time file written */
470 /* This is the REAL definition for using the
473 typedef struct s_db {
474 BQUEUE bq; /* queue control */
475 /* pthread_mutex_t mutex; */ /* single thread lock */
476 brwlock_t lock; /* transaction lock */
477 int ref_count; /* number of times opened */
478 struct s_control control; /* control file structure */
479 int cfd; /* control file device */
480 FILE *jobfd; /* Jobs records file descriptor */
481 FILE *poolfd; /* Pool records fd */
482 FILE *mediafd; /* Media records fd */
483 FILE *jobmediafd; /* JobMedia records fd */
484 FILE *clientfd; /* Client records fd */
485 FILE *filesetfd; /* FileSet records fd */
486 char *db_name; /* name of database */
487 POOLMEM *errmsg; /* nicely edited error message */
488 POOLMEM *cmd; /* Command string */
489 POOLMEM *cached_path;
490 int cached_path_len; /* length of cached path */
491 uint32_t cached_path_id;
494 #endif /* HAVE_SQLITE3 */
495 #endif /* HAVE_MYSQL */
496 #endif /* HAVE_SQLITE */
497 #endif /* HAVE_POSTGRESQL */
499 /* Use for better error location printing */
500 #define UPDATE_DB(jcr, db, cmd) UpdateDB(__FILE__, __LINE__, jcr, db, cmd)
501 #define INSERT_DB(jcr, db, cmd) InsertDB(__FILE__, __LINE__, jcr, db, cmd)
502 #define QUERY_DB(jcr, db, cmd) QueryDB(__FILE__, __LINE__, jcr, db, cmd)
503 #define DELETE_DB(jcr, db, cmd) DeleteDB(__FILE__, __LINE__, jcr, db, cmd)
506 #else /* not __SQL_C */
508 /* This is a "dummy" definition for use outside of sql.c
510 typedef struct s_db {
511 int dummy; /* for SunOS compiler */
516 extern uint32_t bacula_db_version;
518 /* ***FIXME*** FileId_t should *really* be uint64_t
519 * but at the current time, this breaks MySQL.
521 typedef uint32_t FileId_t;
522 typedef uint32_t DBId_t; /* general DB id type */
523 typedef uint32_t JobId_t;
528 /* Job information passed to create job record and update
529 * job record at end of job. Note, although this record
530 * contains all the fields found in the Job database record,
531 * it also contains fields found in the JobMedia record.
536 char Job[MAX_NAME_LENGTH]; /* Job unique name */
537 char Name[MAX_NAME_LENGTH]; /* Job base name */
538 int JobType; /* actually char(1) */
539 int JobLevel; /* actually char(1) */
540 int JobStatus; /* actually char(1) */
541 DBId_t ClientId; /* Id of client */
542 DBId_t PoolId; /* Id of pool */
543 DBId_t FileSetId; /* Id of FileSet */
544 time_t SchedTime; /* Time job scheduled */
545 time_t StartTime; /* Job start time */
546 time_t EndTime; /* Job termination time */
547 utime_t JobTDate; /* Backup time/date in seconds */
548 uint32_t VolSessionId;
549 uint32_t VolSessionTime;
552 uint32_t JobMissingFiles;
555 /* Note, FirstIndex, LastIndex, Start/End File and Block
556 * are only used in the JobMedia record.
558 uint32_t FirstIndex; /* First index this Volume */
559 uint32_t LastIndex; /* Last index this Volume */
565 char cSchedTime[MAX_TIME_LENGTH];
566 char cStartTime[MAX_TIME_LENGTH];
567 char cEndTime[MAX_TIME_LENGTH];
568 /* Extra stuff not in DB */
572 /* Job Media information used to create the media records
573 * for each Volume used for the job.
575 /* JobMedia record */
576 struct JOBMEDIA_DBR {
577 DBId_t JobMediaId; /* record id */
578 JobId_t JobId; /* JobId */
579 DBId_t MediaId; /* MediaId */
580 uint32_t FirstIndex; /* First index this Volume */
581 uint32_t LastIndex; /* Last index this Volume */
582 uint32_t StartFile; /* File for start of data */
583 uint32_t EndFile; /* End file on Volume */
584 uint32_t StartBlock; /* start block on tape */
585 uint32_t EndBlock; /* last block */
586 uint32_t Copy; /* identical copy */
587 uint32_t Stripe; /* RAIT strip number */
591 /* Volume Parameter structure */
593 char VolumeName[MAX_NAME_LENGTH]; /* Volume name */
594 char MediaType[MAX_NAME_LENGTH]; /* Media Type */
595 uint32_t VolIndex; /* Volume seqence no. */
596 uint32_t FirstIndex; /* First index this Volume */
597 uint32_t LastIndex; /* Last index this Volume */
598 uint32_t StartFile; /* File for start of data */
599 uint32_t EndFile; /* End file on Volume */
600 uint32_t StartBlock; /* start block on tape */
601 uint32_t EndBlock; /* last block */
602 // uint32_t Copy; /* identical copy */
603 // uint32_t Stripe; /* RAIT strip number */
607 /* Attributes record -- NOT same as in database because
608 * in general, this "record" creates multiple database
609 * records (e.g. pathname, filename, fileattributes).
612 char *fname; /* full path & filename */
613 char *link; /* link if any */
614 char *attr; /* attributes statp */
627 /* File record -- same format as database */
637 int SigType; /* NO_SIG/MD5_SIG/SHA1_SIG */
640 /* Pool record -- same format as database */
643 char Name[MAX_NAME_LENGTH]; /* Pool name */
644 uint32_t NumVols; /* total number of volumes */
645 uint32_t MaxVols; /* max allowed volumes */
646 int32_t LabelType; /* Bacula/ANSI/IBM */
647 int32_t UseOnce; /* set to use once only */
648 int32_t UseCatalog; /* set to use catalog */
649 int32_t AcceptAnyVolume; /* set to accept any volume sequence */
650 int32_t AutoPrune; /* set to prune automatically */
651 int32_t Recycle; /* default Vol recycle flag */
652 utime_t VolRetention; /* retention period in seconds */
653 utime_t VolUseDuration; /* time in secs volume can be used */
654 uint32_t MaxVolJobs; /* Max Jobs on Volume */
655 uint32_t MaxVolFiles; /* Max files on Volume */
656 uint64_t MaxVolBytes; /* Max bytes on Volume */
657 char PoolType[MAX_NAME_LENGTH];
658 char LabelFormat[MAX_NAME_LENGTH];
659 /* Extra stuff not in DB */
666 char Name[MAX_NAME_LENGTH]; /* Device name */
667 DBId_t MediaTypeId; /* MediaType */
668 DBId_t StorageId; /* Storage id if autochanger */
669 uint32_t DevMounts; /* Number of times mounted */
670 uint32_t DevErrors; /* Number of read/write errors */
671 uint64_t DevReadBytes; /* Number of bytes read */
672 uint64_t DevWriteBytes; /* Number of bytew written */
673 uint64_t DevReadTime; /* time spent reading volume */
674 uint64_t DevWriteTime; /* time spent writing volume */
675 uint64_t DevReadTimeSincCleaning; /* read time since cleaning */
676 uint64_t DevWriteTimeSincCleaning; /* write time since cleaning */
677 time_t CleaningDate; /* time last cleaned */
678 utime_t CleaningPeriod; /* time between cleanings */
684 char Name[MAX_NAME_LENGTH]; /* Device name */
685 int AutoChanger; /* Set if autochanger */
687 /* Not in database */
688 bool created; /* set if created by db_create ... */
691 class MEDIATYPE_DBR {
694 char MediaType[MAX_NAME_LENGTH]; /* MediaType string */
695 int ReadOnly; /* Set if read-only */
699 /* Media record -- same as the database */
701 DBId_t MediaId; /* Unique volume id */
702 char VolumeName[MAX_NAME_LENGTH]; /* Volume name */
703 char MediaType[MAX_NAME_LENGTH]; /* Media type */
704 DBId_t PoolId; /* Pool id */
705 time_t FirstWritten; /* Time Volume first written */
706 time_t LastWritten; /* Time Volume last written */
707 time_t LabelDate; /* Date/Time Volume labeled */
708 int32_t LabelType; /* Label (Bacula/ANSI/IBM) */
709 uint32_t VolJobs; /* number of jobs on this medium */
710 uint32_t VolFiles; /* Number of files */
711 uint32_t VolBlocks; /* Number of blocks */
712 uint32_t VolMounts; /* Number of times mounted */
713 uint32_t VolErrors; /* Number of read/write errors */
714 uint32_t VolWrites; /* Number of writes */
715 uint32_t VolReads; /* Number of reads */
716 uint64_t VolBytes; /* Number of bytes written */
717 uint32_t VolParts; /* Number of parts written */
718 uint64_t MaxVolBytes; /* Max bytes to write to Volume */
719 uint64_t VolCapacityBytes; /* capacity estimate */
720 uint64_t VolReadTime; /* time spent reading volume */
721 uint64_t VolWriteTime; /* time spent writing volume */
722 utime_t VolRetention; /* Volume retention in seconds */
723 utime_t VolUseDuration; /* time in secs volume can be used */
724 uint32_t MaxVolJobs; /* Max Jobs on Volume */
725 uint32_t MaxVolFiles; /* Max files on Volume */
726 int32_t Recycle; /* recycle yes/no */
727 int32_t Slot; /* slot in changer */
728 int32_t InChanger; /* Volume currently in changer */
729 DBId_t StorageId; /* Storage record Id */
730 uint32_t EndFile; /* Last file on volume */
731 uint32_t EndBlock; /* Last block on volume */
732 char VolStatus[20]; /* Volume status */
733 /* Extra stuff not in DB */
734 faddr_t rec_addr; /* found record address */
735 /* Since the database returns times as strings, this is how we pass
738 char cFirstWritten[MAX_TIME_LENGTH]; /* FirstWritten returned from DB */
739 char cLastWritten[MAX_TIME_LENGTH]; /* LastWritten returned from DB */
740 char cLabelDate[MAX_TIME_LENGTH]; /* LabelData returned from DB */
741 bool set_first_written;
745 /* Client record -- same as the database */
747 DBId_t ClientId; /* Unique Client id */
749 utime_t FileRetention;
750 utime_t JobRetention;
751 char Name[MAX_NAME_LENGTH]; /* Client name */
752 char Uname[256]; /* Uname for client */
755 /* Counter record as in database */
757 char Counter[MAX_NAME_LENGTH];
760 int32_t CurrentValue;
761 char WrapCounter[MAX_NAME_LENGTH];
765 /* FileSet record -- same as the database */
767 DBId_t FileSetId; /* Unique FileSet id */
768 char FileSet[MAX_NAME_LENGTH]; /* FileSet name */
769 char MD5[50]; /* MD5 signature of include/exclude */
770 time_t CreateTime; /* date created */
772 * This is where we return CreateTime
774 char cCreateTime[MAX_TIME_LENGTH]; /* CreateTime as returned from DB */
775 /* Not in DB but returned by db_create_fileset() */
776 bool created; /* set when record newly created */
785 * Some functions exported by sql.c for use withing the
788 void list_result(B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_type type);
789 void list_dashes(B_DB *mdb, DB_LIST_HANDLER *send, void *ctx);
790 int get_sql_record_max(JCR *jcr, B_DB *mdb);
791 int check_tables_version(JCR *jcr, B_DB *mdb);
792 void _db_unlock(const char *file, int line, B_DB *mdb);
793 void _db_lock(const char *file, int line, B_DB *mdb);
795 #endif /* __SQL_H_ */