int CfConnectDB(CfdbConn *cfdb, enum cfdbtype dbtype, char *remotehost, char *dbuser, char *passwd, char *db) { cfdb->connected = false; cfdb->type = dbtype; /* If db == NULL, no database was specified, so we assume it has not been created yet. Need to open a generic database and create */ if (db == NULL) { db = "no db specified"; } CfOut(cf_verbose, "", "Connect to SQL database \"%s\" user=%s, host=%s (type=%d)\n", db, dbuser, remotehost, dbtype); switch (dbtype) { case cfd_mysql: cfdb->data = CfConnectMysqlDB(remotehost, dbuser, passwd, db); break; case cfd_postgres: cfdb->data = CfConnectPostgresqlDB(remotehost, dbuser, passwd, db); break; default: CfOut(cf_verbose, "", "There is no SQL database selected"); break; } if (cfdb->data) cfdb->connected = true; cfdb->blank = xstrdup(""); return true; }
int CfConnectDB(CfdbConn *cfdb, DatabaseType dbtype, char *remotehost, char *dbuser, char *passwd, char *db) { cfdb->connected = false; cfdb->type = dbtype; /* If db == NULL, no database was specified, so we assume it has not been created yet. Need to open a generic database and create */ if (db == NULL) { db = "no db specified"; } Log(LOG_LEVEL_VERBOSE, "Connect to SQL database '%s', user '%s', host '%s', type %d", db, dbuser, remotehost, dbtype); switch (dbtype) { case DATABASE_TYPE_MYSQL: cfdb->data = CfConnectMysqlDB(remotehost, dbuser, passwd, db); break; case DATABASE_TYPE_POSTGRES: cfdb->data = CfConnectPostgresqlDB(remotehost, dbuser, passwd, db); break; default: Log(LOG_LEVEL_VERBOSE, "There is no SQL database selected"); break; } if (cfdb->data) cfdb->connected = true; cfdb->blank = xstrdup(""); return true; }