Files
@ e0d0a8f4daed
Branch filter:
Location: DistRen/src/server/mysql.c - annotation
e0d0a8f4daed
3.4 KiB
text/plain
Commenting for queries
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 d5f4334ff4e6 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 d5f4334ff4e6 d5f4334ff4e6 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 742325b16d40 9b974d776960 9b974d776960 742325b16d40 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 742325b16d40 9b974d776960 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 9b974d776960 9b974d776960 9b974d776960 9b974d776960 742325b16d40 742325b16d40 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 742325b16d40 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 d5f4334ff4e6 9b974d776960 9b974d776960 9b974d776960 742325b16d40 742325b16d40 17ee4de48309 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 9b974d776960 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 9b974d776960 9b974d776960 9b974d776960 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 d5f4334ff4e6 | /*
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>
/**
local types
*/
#define SEVENTY_FIVE 75
#define FORTY_TWO 42
struct distrend_mysql_con
{
MYSQL *mysqlconn;
short pointlesscheck;
};
struct distrend_mysql_result
{
MYSQL_RES *mysqlresult;
short pointlesscheck;
};
/**
funcs
*/
int mysqlConnect(struct distrend_mysql_con **conn)
{
MYSQL *mysqlconn;
char *server = "zserver1";
char *user = "distren";
char *password = "secretpassword";
char *database = "distren";
mysqlconn = mysql_init(NULL);
mysql_options(mysqlconn, MYSQL_OPT_RECONNECT,"true");
if(!mysql_real_connect(mysqlconn, server, user, password, database, 0, NULL, 0))
{
fprintf(stderr, "%s\n", mysql_error(mysqlconn));
return 1;
}
*conn = malloc(sizeof(struct distrend_mysql_con));
if(!*conn)
{
mysql_close(mysqlconn);
mysql_server_end();
return 2;
}
(*conn)->mysqlconn = mysqlconn;
(*conn)->pointlesscheck = SEVENTY_FIVE;
return 0;
}
int mysqlDisconnect(distrend_mysql_con_t conn)
{
/**
check if this handle is valid
*/
if(conn->pointlesscheck != SEVENTY_FIVE)
fprintf(stderr, "warning, I was passed a bad struct distrend_mysql_con...\n");
/**
invalidate handle :-D
*/
conn->pointlesscheck ++;
mysql_close(conn->mysqlconn);
mysql_server_end();
free(conn);
return 0;
}
distrend_mysql_result_t mysqlQuery(distrend_mysql_con_t conn, char *query)
{
MYSQL_RES *result;
distrend_mysql_result_t distrenresult;
/**
pointless sanity check
*/
if(conn->pointlesscheck != SEVENTY_FIVE)
fprintf(stderr, "warning, I was passed a bad struct distrend_mysql_con...\n");
/** make sure that connection is still alive
*/
if(mysql_ping(conn->mysqlconn))
fprintf(stderr, "MySQL Connection _was_ broken or may be broken, I'm not sure exactly what this return value means\n");
if (mysql_query(conn->mysqlconn, query))
fprintf(stderr, "%s\n", mysql_error(conn->mysqlconn));
result = mysql_use_result(conn->mysqlconn);
distrenresult = malloc(sizeof(struct distrend_mysql_result));
if(!distrenresult)
{
mysql_free_result(result);
return NULL;
}
distrenresult->mysqlresult = result;
distrenresult->pointlesscheck = FORTY_TWO;
return distrenresult;
}
int mysqlResultFree(distrend_mysql_result_t result)
{
if(result->pointlesscheck != FORTY_TWO)
fprintf(stderr, "%s:%d: I didn't get the type of handle I wanted\n", __FILE__, __LINE__);
mysql_free_result(result->mysqlresult);
free(result);
return 0;
}
|