1 /*
2    Bacula(R) - The Network Backup Solution
3 
4    Copyright (C) 2000-2020 Kern Sibbald
5 
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8 
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13 
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16 
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 
20 /* MySQL driver specific definitions */
21 
22 #ifdef __BDB_MYSQL_H_
23 
24 /*
25  * Number of insert statements to batch-up in batch insert
26  * mode. We use multi-row inserts only in the batch mode
27  * on the private database connection.
28  */
29 #define MYSQL_CHANGES_PER_BATCH_INSERT 32
30 
31 class BDB_MYSQL: public BDB {
32 private:
33    MYSQL *m_db_handle;
34    MYSQL m_instance;
35    MYSQL_RES *m_result;
36 
37 public:
38    BDB_MYSQL();
39    ~BDB_MYSQL();
40 
41    /* Functions that we override */
42    bool bdb_open_database(JCR *jcr);
43    void bdb_close_database(JCR *jcr);
44    void bdb_thread_cleanup(void);
45    void bdb_escape_string(JCR *jcr, char *snew, char *old, int len);
46    char *bdb_escape_object(JCR *jcr, char *old, int len);
47    void bdb_unescape_object(JCR *jcr, char *from, int32_t expected_len,
48                            POOLMEM **dest, int32_t *len);
49    void bdb_start_transaction(JCR *jcr);
50    void bdb_end_transaction(JCR *jcr);
51    bool bdb_sql_query(const char *query, DB_RESULT_HANDLER *result_handler, void *ctx);
52    void sql_free_result(void);
53    SQL_ROW sql_fetch_row(void);
54    bool sql_query(const char *query, int flags=0);
55    const char *sql_strerror(void);
56    int sql_num_rows(void);
57    void sql_data_seek(int row);
58    int sql_affected_rows(void);
59    uint64_t sql_insert_autokey_record(const char *query, const char *table_name);
60    void sql_field_seek(int field);
61    SQL_FIELD *sql_fetch_field(void);
62    int sql_num_fields(void);
63    bool sql_field_is_not_null(int field_type);
64    bool sql_field_is_numeric(int field_type);
65    bool sql_batch_start(JCR *jcr);
66    bool sql_batch_end(JCR *jcr, const char *error);
67    bool sql_batch_insert(JCR *jcr, ATTR_DBR *ar);
68 };
69 
70 #endif /* __BDB_MYSQL_H_ */
71