src/cats/mysql.c
BDB *db_init_database(JCR *jcr, const char *db_driver, const char *db_name, const char *db_user, 
                       const char *db_password, const char *db_address, int db_port, const char *db_socket, 
                       const char *db_ssl_mode, const char *db_ssl_key, 
                       const char *db_ssl_cert, const char *db_ssl_ca,
                       const char *db_ssl_capath, const char *db_ssl_cipher,
                       bool mult_db_connections, bool disable_batch_insert) 
{ 
   BDB_MYSQL *mdb = NULL; 
 
   if (!db_user) { 
      Jmsg(jcr, M_FATAL, 0, _("A user name for MySQL must be supplied.\n")); 
      return NULL; 
   } 
   P(mutex);                          /* lock DB queue */ 
 
   /* 
    * Look to see if DB already open 
    */ 
   if (db_list && !mult_db_connections) { 
      foreach_dlist(mdb, db_list) { 
         if (mdb->bdb_match_database(db_driver, db_name, db_address, db_port)) { 
            Dmsg1(100, "DB REopen %s\n", db_name); 
            mdb->increment_refcount(); 
            goto get_out; 
         } 
      } 
   } 
   Dmsg0(100, "db_init_database first time\n"); 
   mdb = New(BDB_MYSQL()); 
   if (!mdb) goto get_out; 
 
   /* 
    * Initialize the parent class members. 
    */ 
   mdb->m_db_name = bstrdup(db_name); 
   mdb->m_db_user = bstrdup(db_user); 
   if (db_password) { 
      mdb->m_db_password = bstrdup(db_password); 
   } 
   if (db_address) { 
      mdb->m_db_address = bstrdup(db_address); 
   } 
   if (db_socket) {
      mdb->m_db_socket = bstrdup(db_socket); 
   } 
   if (db_ssl_mode) {
      mdb->m_db_ssl_mode = bstrdup(db_ssl_mode);
   } else {
      mdb->m_db_ssl_mode = bstrdup("preferred");
   }
   if (db_ssl_key) {
      mdb->m_db_ssl_key = bstrdup(db_ssl_key);
   }
   if (db_ssl_cert) {
      mdb->m_db_ssl_cert = bstrdup(db_ssl_cert);
   }
   if (db_ssl_ca) {
      mdb->m_db_ssl_ca = bstrdup(db_ssl_ca);
   }
   if (db_ssl_capath) {
      mdb->m_db_ssl_capath = bstrdup(db_ssl_capath);
   }
   if (db_ssl_cipher) {
      mdb->m_db_ssl_cipher = bstrdup(db_ssl_cipher);
   }
   mdb->m_db_port = db_port; 
 
   if (disable_batch_insert) { 
      mdb->m_disabled_batch_insert = true; 
      mdb->m_have_batch_insert = false; 
   } else { 
      mdb->m_disabled_batch_insert = false; 
#ifdef USE_BATCH_FILE_INSERT 
#ifdef HAVE_MYSQL_THREAD_SAFE 
      mdb->m_have_batch_insert = mysql_thread_safe(); 
#else 
      mdb->m_have_batch_insert = false; 
#endif /* HAVE_MYSQL_THREAD_SAFE */ 
#else 
      mdb->m_have_batch_insert = false; 
#endif /* USE_BATCH_FILE_INSERT */ 
   } 
 
   mdb->m_allow_transactions = mult_db_connections; 
 
   /* At this time, when mult_db_connections == true, this is for 
    * specific console command such as bvfs or batch mode, and we don't 
    * want to share a batch mode or bvfs. In the future, we can change 
    * the creation function to add this parameter. 
    */ 
   mdb->m_dedicated = mult_db_connections; 
 
get_out: 
   V(mutex); 
   return mdb; 
}
/* 
 * Initialize database data structure. In principal this should 
 * never have errors, or it is really fatal. 
 */
Initialize database data structure. In principal this should
never have errors, or it is really fatal.
Initialize database data structure . In principal this should never have errors or it is really fatal .
BDB *db_init_database(JCR *jcr, const char *db_driver, const char *db_name, const char *db_user, 
                       const char *db_password, const char *db_address, int db_port, const char *db_socket, 
                       const char *db_ssl_mode, const char *db_ssl_key, 
                       const char *db_ssl_cert, const char *db_ssl_ca,
                       const char *db_ssl_capath, const char *db_ssl_cipher,
                       bool mult_db_connections, bool disable_batch_insert) 
{ 
   BDB_MYSQL *mdb = NULL; 
   if (!db_user) { 
      Jmsg(jcr, M_FATAL, 0, _("A user name for MySQL must be supplied.\n")); 
      return NULL; 
   } 
   P(mutex);                           
   if (db_list && !mult_db_connections) { 
      foreach_dlist(mdb, db_list) { 
         if (mdb->bdb_match_database(db_driver, db_name, db_address, db_port)) { 
            Dmsg1(100, "DB REopen %s\n", db_name); 
            mdb->increment_refcount(); 
            goto get_out; 
         } 
      } 
   } 
   Dmsg0(100, "db_init_database first time\n"); 
   mdb = New(BDB_MYSQL()); 
   if (!mdb) goto get_out; 
   mdb->m_db_name = bstrdup(db_name); 
   mdb->m_db_user = bstrdup(db_user); 
   if (db_password) { 
      mdb->m_db_password = bstrdup(db_password); 
   } 
   if (db_address) { 
      mdb->m_db_address = bstrdup(db_address); 
   } 
   if (db_socket) {
      mdb->m_db_socket = bstrdup(db_socket); 
   } 
   if (db_ssl_mode) {
      mdb->m_db_ssl_mode = bstrdup(db_ssl_mode);
   } else {
      mdb->m_db_ssl_mode = bstrdup("preferred");
   }
   if (db_ssl_key) {
      mdb->m_db_ssl_key = bstrdup(db_ssl_key);
   }
   if (db_ssl_cert) {
      mdb->m_db_ssl_cert = bstrdup(db_ssl_cert);
   }
   if (db_ssl_ca) {
      mdb->m_db_ssl_ca = bstrdup(db_ssl_ca);
   }
   if (db_ssl_capath) {
      mdb->m_db_ssl_capath = bstrdup(db_ssl_capath);
   }
   if (db_ssl_cipher) {
      mdb->m_db_ssl_cipher = bstrdup(db_ssl_cipher);
   }
   mdb->m_db_port = db_port; 
   if (disable_batch_insert) { 
      mdb->m_disabled_batch_insert = true; 
      mdb->m_have_batch_insert = false; 
   } else { 
      mdb->m_disabled_batch_insert = false; 
#ifdef USE_BATCH_FILE_INSERT 
#ifdef HAVE_MYSQL_THREAD_SAFE 
      mdb->m_have_batch_insert = mysql_thread_safe(); 
#else 
      mdb->m_have_batch_insert = false; 
#endif  
#else 
      mdb->m_have_batch_insert = false; 
#endif  
   } 
   mdb->m_allow_transactions = mult_db_connections; 
   mdb->m_dedicated = mult_db_connections; 
get_out: 
   V(mutex); 
   return mdb; 
}
BDB * db_init_database ( JCR * jcr , const char * db_driver , const char * db_name , const char * db_user , const char * db_password , const char * db_address , int db_port , const char * db_socket , const char * db_ssl_mode , const char * db_ssl_key , const char * db_ssl_cert , const char * db_ssl_ca , const char * db_ssl_capath , const char * db_ssl_cipher , bool mult_db_connections , bool disable_batch_insert ) { BDB_MYSQL * mdb = NULL ; if ( ! db_user ) { Jmsg ( jcr , M_FATAL , 0 , _ ( " \n " ) ) ; return NULL ; } P ( mutex ) ; if ( db_list && ! mult_db_connections ) { foreach_dlist ( mdb , db_list ) { if ( mdb -> bdb_match_database ( db_driver , db_name , db_address , db_port ) ) { Dmsg1 ( 100 , " \n " , db_name ) ; mdb -> increment_refcount ( ) ; goto get_out ; } } } Dmsg0 ( 100 , " \n " ) ; mdb = New ( BDB_MYSQL ( ) ) ; if ( ! mdb ) goto get_out ; mdb -> m_db_name = bstrdup ( db_name ) ; mdb -> m_db_user = bstrdup ( db_user ) ; if ( db_password ) { mdb -> m_db_password = bstrdup ( db_password ) ; } if ( db_address ) { mdb -> m_db_address = bstrdup ( db_address ) ; } if ( db_socket ) { mdb -> m_db_socket = bstrdup ( db_socket ) ; } if ( db_ssl_mode ) { mdb -> m_db_ssl_mode = bstrdup ( db_ssl_mode ) ; } else { mdb -> m_db_ssl_mode = bstrdup ( " " ) ; } if ( db_ssl_key ) { mdb -> m_db_ssl_key = bstrdup ( db_ssl_key ) ; } if ( db_ssl_cert ) { mdb -> m_db_ssl_cert = bstrdup ( db_ssl_cert ) ; } if ( db_ssl_ca ) { mdb -> m_db_ssl_ca = bstrdup ( db_ssl_ca ) ; } if ( db_ssl_capath ) { mdb -> m_db_ssl_capath = bstrdup ( db_ssl_capath ) ; } if ( db_ssl_cipher ) { mdb -> m_db_ssl_cipher = bstrdup ( db_ssl_cipher ) ; } mdb -> m_db_port = db_port ; if ( disable_batch_insert ) { mdb -> m_disabled_batch_insert = true ; mdb -> m_have_batch_insert = false ; } else { mdb -> m_disabled_batch_insert = false ; #ifdef USE_BATCH_FILE_INSERT #ifdef HAVE_MYSQL_THREAD_SAFE mdb -> m_have_batch_insert = mysql_thread_safe ( ) ; #else mdb -> m_have_batch_insert = false ; #endif #else mdb -> m_have_batch_insert = false ; #endif } mdb -> m_allow_transactions = mult_db_connections ; mdb -> m_dedicated = mult_db_connections ; get_out : V ( mutex ) ; return mdb ; }
Initialize database data structure.
Initialize database data structure .
/* lock DB queue */ /* 
    * Look to see if DB already open 
    */ /* 
    * Initialize the parent class members. 
    */ /* HAVE_MYSQL_THREAD_SAFE */ /* USE_BATCH_FILE_INSERT */ /* At this time, when mult_db_connections == true, this is for 
    * specific console command such as bvfs or batch mode, and we don't 
    * want to share a batch mode or bvfs. In the future, we can change 
    * the creation function to add this parameter. 
    */