X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2FmysqlConn.c;h=dfc65a9f042742bc1c5013380b5de71f0834c300;hb=ff6c5041af889bbc986199316daba8676b8e9cfd;hp=5965e6aafa6d171434bbc11bb3262279f7340a5c;hpb=9d2bbd34f22639745b23b7916ed3123c0dfed557;p=NeonServV5.git diff --git a/src/mysqlConn.c b/src/mysqlConn.c index 5965e6a..dfc65a9 100644 --- a/src/mysqlConn.c +++ b/src/mysqlConn.c @@ -1,6 +1,22 @@ +/* mysqlConn.c - NeonServ v5.1 + * Copyright (C) 2011 Philipp Kreil (pk910) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include "mysqlConn.h" -#define DATABASE_VERSION "1" +#define DATABASE_VERSION "4" struct used_result { MYSQL_RES *result; @@ -82,6 +98,7 @@ void init_mysql(char *host, int port, char *user, char *pass, char *base) { version = atoi(row[0]); } } + printf("%d \n", version); if(!version) { //CREATE DATABASE FILE *f = fopen("database.sql", "r"); @@ -92,30 +109,31 @@ void init_mysql(char *host, int port, char *user, char *pass, char *base) { int query_buffer_pos = 0; while (fgets(line, sizeof(line), f)) { query_buffer_pos += sprintf(query_buffer + query_buffer_pos, " %s", line); - if(line[(strlen(line) - 1)] == ';') { - mysql_query(mysql_conn, query_buffer); + if(line[(strlen(line) - 2)] == ';') { + if(mysql_query(mysql_conn, query_buffer)) + show_mysql_error(); query_buffer_pos = 0; } } fclose(f); } f = fopen("database.defaults.sql", "r"); - mysql_set_server_option(mysql_conn, MYSQL_OPTION_MULTI_STATEMENTS_ON); if (f) { - char line[2048]; - char query_buffer[65536]; + char line[4096]; + char query_buffer[131072]; int query_buffer_pos = 0; while (fgets(line, sizeof(line), f)) { query_buffer_pos += sprintf(query_buffer + query_buffer_pos, " %s", line); - if(line[(strlen(line) - 1)] == ';') { - mysql_query(mysql_conn, query_buffer); + if(line[(strlen(line) - 2)] == ';') { + if(mysql_query(mysql_conn, query_buffer)) + show_mysql_error(); query_buffer_pos = 0; } } fclose(f); } mysql_set_server_option(mysql_conn, MYSQL_OPTION_MULTI_STATEMENTS_OFF); - mysql_query(mysql_conn, "UPDATE `version` SET `database_version` = '" DATABASE_VERSION "'"); + mysql_query(mysql_conn, "INSERT INTO `version` (`database_version`) VALUES ('" DATABASE_VERSION "')"); } else if(version < atoi(DATABASE_VERSION)) { //UPDATE DATABASE @@ -137,8 +155,13 @@ void init_mysql(char *host, int port, char *user, char *pass, char *base) { use_querys = 1; } } + if(query_buffer_pos) { + if(mysql_query(mysql_conn, query_buffer)) + show_mysql_error(); + } fclose(f); - } + } else + perror("database.sql missing!"); mysql_set_server_option(mysql_conn, MYSQL_OPTION_MULTI_STATEMENTS_OFF); mysql_query(mysql_conn, "UPDATE `version` SET `database_version` = '" DATABASE_VERSION "'"); }