Changeset - 742325b16d40
[Not reviewed]
default
0 2 2
ethanzonca - 16 years ago 2010-02-09 18:24:32
ez@ethanzonca.com
Added mysql wrapper functions
4 files changed with 109 insertions and 1 deletions:
0 comments (0 inline, 0 general)
Makefile.am
Show inline comments
 
@@ -57,13 +57,15 @@ distrend_LDFLAGS = $(AM_LDFLAGS) $(MYSQL
 
distrend_SOURCES = $(SERVER_SOURCES) \
 
	src/server/distrend.c \
 
	src/server/distrend.h \
 
	src/server/user_mgr.c \
 
	src/server/user_mgr.h \
 
	src/server/listen.h \
 
	src/server/listen.c
 
	src/server/listen.c \ 
 
	src/server/mysql.h \
 
	src/server/mysql.c
 
distrend_LDADD = libdistrencommon.la
 
# distrenslave:
 
distrenslave_SOURCES = $(SERVER_SOURCES) \
 
	src/server/slave.c
 
distrenslave_LDADD = libdistrencommon.la
 

	
src/server/distrend.c
Show inline comments
 
@@ -20,12 +20,13 @@
 

	
 
/* This file contains the code which both processes (renders) jobs as a slave, and the code which distributes frames to slaves after receiving them from the client portion of the codebase. */
 

	
 
#include "distrenjob.h"
 
#include "listen.h"
 
#include "slavefuncs.h"
 
#include "mysql.h"
 

	
 
#include "common/asprintf.h"
 
#include "common/execio.h"
 
#include "common/options.h"
 
#include "common/protocol.h"
 

	
src/server/mysql.c
Show inline comments
 
new file 100644
 
/*
 
  Copyright 2009 Nathan Phillip Brink, Ethan Zonca, Matthew Orlando
 

	
 
  This file is a part of DistRen.
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU Affero General Public License for more details.
 

	
 
  You should have received a copy of the GNU Affero General Public License
 
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
*/
 

	
 
#include "mysql.h"
 
#include <mysql/mysql.h>
 

	
 
#include "common/asprintf.h"
 

	
 
#include <stdio.h>
 
#include <string.h>
 
#include <unistd.h>
 
#include <stdlib.h>
 
#include <sys/stat.h>
 
#include <fcntl.h>
 

	
 
MYSQL mysqlConnect(){
 
  MYSQL *conn;
 

	
 
  char *server = "zserver1";
 
  char *user = "distren";
 
  char *password = "secretpassword";
 
  char *database = "distren";
 

	
 
  conn = mysql_init(NULL);
 
  mysql_options(conn, MYSQL_OPT_RECONNECT,"true");
 

	
 
  if(!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0))
 
    fprintf(stderr, "%s\n", mysql_error(conn));
 

	
 
  return *conn;
 
}
 

	
 
MYSQL_RES mysqlQuery(MYSQL *conn, char *query){
 
  if (mysql_query(conn, query))
 
     fprintf(stderr, "%s\n", mysql_error(conn));
 

	
 
  MYSQL_RES *result;
 
  result = mysql_use_result(conn);
 
  return *result;
 
}
 

	
 
// Check if connection is alive, reconnect if broken.
 
int mysqlPing(MYSQL *conn){
 
  if(mysql_ping(conn)){
 
    fprintf(stderr, "MySQL Connection broken, attempting reconnection...");
 
    return 1;
 
  }
 
  else
 
    return 0; // Connection is still alive
 
}
 

	
 
int mysqlFree(MYSQL_RES *res, MYSQL *conn){
 
  mysql_free_result(res);
 
  mysql_close(conn);
 
  return 0;
 
}
src/server/mysql.h
Show inline comments
 
new file 100644
 
/*
 
  Copyright 2009 Nathan Phillip Brink, Ethan Zonca, Matthew Orlando
 

	
 
  This file is a part of DistRen.
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU Affero General Public License for more details.
 

	
 
  You should have received a copy of the GNU Affero General Public License
 
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
*/
 

	
 

	
 
#ifndef MYSQL_H_
 
#define MYSQL_H_
 

	
 
#include <mysql/mysql.h>
 

	
 
MYSQL mysqlConnect();
 
MYSQL_RES mysqlQuery(MYSQL *conn, char *query);
 
MYSQL_RES mysqlQuery(MYSQL *conn, char *query);
 
int mysqlFree(MYSQL_RES *res, MYSQL *conn);
 

	
 
#endif /* MYSQL_H_ */
0 comments (0 inline, 0 general)