2003-08-31 05:33:59 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2004-01-15 23:53:13 +00:00
|
|
|
//
|
2003-08-31 05:33:59 +00:00
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
2004-01-15 23:53:13 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2003-08-31 05:33:59 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2004-01-15 23:53:13 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2003-08-31 05:33:59 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef _DB_BASE_
|
|
|
|
#define _DB_BASE_
|
|
|
|
|
2003-08-31 01:21:31 +00:00
|
|
|
#include "mysql.h"
|
|
|
|
|
|
|
|
struct CURSOR {
|
|
|
|
bool active;
|
|
|
|
MYSQL_RES *rp;
|
|
|
|
};
|
|
|
|
|
2003-09-05 21:26:21 +00:00
|
|
|
// represents a connection to a database
|
|
|
|
//
|
2003-09-27 23:20:40 +00:00
|
|
|
class DB_CONN {
|
2003-09-05 21:26:21 +00:00
|
|
|
public:
|
|
|
|
DB_CONN();
|
2004-01-15 23:53:13 +00:00
|
|
|
int open(char* name, char* host, char* user, char* passwd);
|
2004-01-14 20:24:24 +00:00
|
|
|
int do_query(char*);
|
2003-09-05 21:26:21 +00:00
|
|
|
void close();
|
|
|
|
int insert_id();
|
|
|
|
void print_error(char*);
|
|
|
|
const char* error_string();
|
2004-06-30 18:17:21 +00:00
|
|
|
bool is_high_priority;
|
2003-09-05 21:26:21 +00:00
|
|
|
|
|
|
|
MYSQL* mysql;
|
|
|
|
};
|
|
|
|
|
2003-08-31 01:21:31 +00:00
|
|
|
// Base for derived classes that can access the DB
|
|
|
|
// Defines various generic operations on DB tables
|
|
|
|
//
|
|
|
|
class DB_BASE {
|
|
|
|
public:
|
2003-09-05 21:26:21 +00:00
|
|
|
DB_BASE(DB_CONN&, char *table_name);
|
2003-08-31 01:21:31 +00:00
|
|
|
int insert();
|
|
|
|
int update();
|
2004-01-14 20:24:24 +00:00
|
|
|
int update_field(char*);
|
2003-08-31 01:21:31 +00:00
|
|
|
int lookup_id(int id);
|
|
|
|
int lookup(char*);
|
|
|
|
int enumerate(char* clause="");
|
2004-05-18 18:33:01 +00:00
|
|
|
int end_enumerate();
|
2003-08-31 01:21:31 +00:00
|
|
|
int count(int&, char* clause="");
|
|
|
|
int sum(double&, char* field, char* clause="");
|
|
|
|
int get_double(char* query, double&);
|
|
|
|
int get_integer(char* query, int&);
|
2004-06-30 18:25:14 +00:00
|
|
|
bool is_high_priority;
|
2003-08-31 01:21:31 +00:00
|
|
|
|
2003-09-05 21:26:21 +00:00
|
|
|
DB_CONN* db;
|
2003-08-31 01:21:31 +00:00
|
|
|
const char *table_name;
|
|
|
|
CURSOR cursor;
|
|
|
|
virtual int get_id();
|
|
|
|
virtual void db_print(char*);
|
|
|
|
virtual void db_parse(MYSQL_ROW&);
|
|
|
|
};
|
|
|
|
|
2003-12-07 18:58:08 +00:00
|
|
|
#define strcpy2(x, y) \
|
|
|
|
{ \
|
|
|
|
char* z = y; \
|
|
|
|
if (!z) { \
|
|
|
|
x[0]=0; \
|
|
|
|
} else { \
|
2004-06-09 00:12:22 +00:00
|
|
|
strlcpy(x, z, sizeof(x)); \
|
2003-12-07 18:58:08 +00:00
|
|
|
} \
|
|
|
|
}
|
2003-12-26 06:03:03 +00:00
|
|
|
|
2004-04-09 23:33:50 +00:00
|
|
|
void escape_string(char* field, int len);
|
|
|
|
void unescape_string(char* p, int len);
|
2003-08-31 05:33:59 +00:00
|
|
|
|
|
|
|
#endif
|