mirror of https://github.com/BOINC/boinc.git
parent
9d6799c583
commit
f968d6110f
2
db/db.h
2
db/db.h
|
@ -238,7 +238,7 @@ struct RESULT {
|
|||
int parse_from_client(FILE*);
|
||||
};
|
||||
|
||||
extern int db_open(char*);
|
||||
extern int db_open(char* dbname, char* passwd);
|
||||
extern int db_close();
|
||||
extern void db_print_error(char*);
|
||||
extern int db_insert_id();
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "mysql.h"
|
||||
#include "mysql_util.h"
|
||||
|
@ -39,11 +38,10 @@ static MYSQL_ROW row;
|
|||
|
||||
#define MAX_QUERY_LEN 8192
|
||||
|
||||
int db_open(char* name) {
|
||||
//assert(name!=NULL);
|
||||
int db_open(char* dbname, char* password) {
|
||||
mp = mysql_init(0);
|
||||
if (!mp) return -1;
|
||||
mp = mysql_real_connect(mp, 0, 0, "", name, 0, 0, 0);
|
||||
mp = mysql_real_connect(mp, 0, 0, password, dbname, 0, 0, 0);
|
||||
if (!mp) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -54,7 +52,6 @@ int db_close() {
|
|||
}
|
||||
|
||||
void db_print_error(char* p) {
|
||||
assert(p!=NULL);
|
||||
if (mp) {
|
||||
printf("<br>%s: Database error: %s\n", p, mysql_error(mp));
|
||||
}
|
||||
|
@ -62,7 +59,6 @@ void db_print_error(char* p) {
|
|||
|
||||
// convert ' to \' in place
|
||||
void escape(char* field) {
|
||||
assert(field!=NULL);
|
||||
char buf[MAX_QUERY_LEN];
|
||||
char* q = buf, *p = field;
|
||||
while (*p) {
|
||||
|
@ -80,7 +76,6 @@ void escape(char* field) {
|
|||
|
||||
void unescape(char* p) {
|
||||
char* q;
|
||||
assert(p!=NULL);
|
||||
while (1) {
|
||||
q = strstr(p, "\\'");
|
||||
if (!q) break;
|
||||
|
@ -90,13 +85,11 @@ void unescape(char* p) {
|
|||
|
||||
// assumes ID is first
|
||||
static int* id(void* vp, int type) {
|
||||
assert(vp!=NULL);
|
||||
return (int*) vp;
|
||||
}
|
||||
|
||||
int db_new(void* vp, int type) {
|
||||
char buf[MAX_QUERY_LEN], sbuf[MAX_QUERY_LEN];
|
||||
assert(vp!=NULL);
|
||||
struct_to_str(vp, sbuf, type);
|
||||
sprintf(buf, "insert into %s set %s", table_name[type], sbuf);
|
||||
return mysql_query(mp, buf);
|
||||
|
@ -118,7 +111,6 @@ int db_delete(int id, int type) {
|
|||
|
||||
int db_lookup_id(int i, void* vp, int type) {
|
||||
char buf[MAX_QUERY_LEN];
|
||||
assert(vp!=NULL);
|
||||
sprintf(buf, "select * from %s where id=%d", table_name[type], i);
|
||||
mysql_query(mp, buf);
|
||||
rp = mysql_store_result(mp);
|
||||
|
@ -131,8 +123,6 @@ int db_lookup_id(int i, void* vp, int type) {
|
|||
|
||||
int db_lookup(void* vp, int type, char* clause) {
|
||||
char buf[MAX_QUERY_LEN];
|
||||
assert(vp!=NULL);
|
||||
assert(clause!=NULL);
|
||||
sprintf(buf, "select * from %s where %s", table_name[type], clause);
|
||||
mysql_query(mp, buf);
|
||||
rp = mysql_store_result(mp);
|
||||
|
@ -145,7 +135,6 @@ int db_lookup(void* vp, int type, char* clause) {
|
|||
|
||||
int db_update(void* vp, int type) {
|
||||
char buf[MAX_QUERY_LEN], sbuf[MAX_QUERY_LEN];
|
||||
assert(vp!=NULL);
|
||||
struct_to_str(vp, sbuf, type);
|
||||
sprintf(
|
||||
buf,
|
||||
|
@ -157,8 +146,6 @@ int db_update(void* vp, int type) {
|
|||
|
||||
int db_enum(ENUM& e, void* p, int type, char* clause, int limit) {
|
||||
char buf[MAX_QUERY_LEN], buf2[256];
|
||||
//assert(p!=NULL);
|
||||
//assert(clause!=NULL);
|
||||
if (!e.active) {
|
||||
e.active = 1;
|
||||
sprintf(buf, "select * from %s %s", table_name[type], clause?clause:"");
|
||||
|
@ -183,8 +170,6 @@ int db_enum(ENUM& e, void* p, int type, char* clause, int limit) {
|
|||
|
||||
int db_enum_field(ENUM& e, int type, char* field, char* clause) {
|
||||
char buf[MAX_QUERY_LEN];
|
||||
assert(field!=NULL);
|
||||
assert(clause!=NULL);
|
||||
if (!e.active) {
|
||||
e.active = 1;
|
||||
sprintf(buf, "select %s from %s %s", field, table_name[type], clause);
|
||||
|
@ -203,8 +188,6 @@ int db_enum_field(ENUM& e, int type, char* field, char* clause) {
|
|||
}
|
||||
|
||||
int db_query_int(int* ip, char* query) {
|
||||
assert(ip!=NULL);
|
||||
assert(query!=NULL);
|
||||
mysql_query(mp, query);
|
||||
rp = mysql_store_result(mp);
|
||||
if (!rp) return -1;
|
||||
|
@ -217,9 +200,6 @@ int db_query_int(int* ip, char* query) {
|
|||
|
||||
int db_count(int* np, char* what, int type, char* clause) {
|
||||
char buf[MAX_QUERY_LEN];
|
||||
assert(np!=NULL);
|
||||
assert(what!=NULL);
|
||||
assert(clause!=NULL);
|
||||
sprintf(buf, "select count(%s) from %s %s", what, table_name[type], clause);
|
||||
return db_query_int(np, buf);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ struct ENUM {
|
|||
MYSQL_RES *rp;
|
||||
};
|
||||
|
||||
extern int db_open(char*);
|
||||
extern int db_open(char* dbname, char* password);
|
||||
extern int db_close();
|
||||
extern void db_print_error();
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ CFLAGS = -g -Wall @DEFS@ \
|
|||
-I@top_srcdir@/lib \
|
||||
-I@top_srcdir@/tools \
|
||||
-DBOINC_DB_NAME=\"$(BOINC_DB_NAME)\" \
|
||||
-DBOINC_DB_PASSWD=\"$(BOINC_DB_PASSWD)\" \
|
||||
-DBOINC_KEY=$(BOINC_KEY) \
|
||||
-DBOINC_KEY_DIR=\"$(BOINC_KEY_DIR)\" \
|
||||
-DBOINC_UPLOAD_DIR=\"$(BOINC_UPLOAD_DIR)\" \
|
||||
|
|
|
@ -191,7 +191,7 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
ssp = (SCHED_SHMEM*)p;
|
||||
ssp->init();
|
||||
retval = db_open(getenv("BOINC_DB_NAME"));
|
||||
retval = db_open(getenv("BOINC_DB_NAME"), getenv("BOINC_DB_PASSWD"));
|
||||
if (retval) {
|
||||
fprintf(stderr, "feeder: db_open: %d\n", retval);
|
||||
exit(1);
|
||||
|
|
|
@ -84,7 +84,7 @@ int main() {
|
|||
exit(1);
|
||||
}
|
||||
//fprintf(stderr, "got ready flag\n");
|
||||
retval = db_open(BOINC_DB_NAME);
|
||||
retval = db_open(BOINC_DB_NAME, BOINC_DB_PASSWD);
|
||||
if (retval) {
|
||||
exit(return_error("BOINC scheduler - Compiled by BOINC_USER: can't open database"));
|
||||
}
|
||||
|
|
|
@ -253,7 +253,7 @@ void add_user() {
|
|||
int main(int argc, char** argv) {
|
||||
int i, retval;
|
||||
|
||||
retval = db_open(getenv("BOINC_DB_NAME"));
|
||||
retval = db_open(getenv("BOINC_DB_NAME"), getenv("BOINC_DB_PASSWD"));
|
||||
if (retval) {
|
||||
printf("can't open DB %s\n", getenv("BOINC_DB_NAME"));
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ int main(int argc, char** argv) {
|
|||
printf("must define BOINC_DOWNLOAD_DIR");
|
||||
exit(1);
|
||||
}
|
||||
if (db_open(getenv("BOINC_DB_NAME"))) {
|
||||
if (db_open(getenv("BOINC_DB_NAME"), getenv("BOINC_DB_PASSWD"))) {
|
||||
printf( "Error opening database.\n" );
|
||||
exit(0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue