Hello all, i wonder if j00 can help me. I've got the stats code from Snaz but there seems to be a problem in one of the files. Here is the code then i'll tell you the errors.
Code:
// Stats 5 Copyright (C) 2003 Ian Packer <snazbaz at onetel.net.uk>
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// $Id: $
//
#include <stdio.h>
#include <string.h>
#include "main.h"
mysql;
MYSQL_RES;
MYSQL_ROW;
unsigned long *lengths;
unsigned int num_fields;
unsigned long rows;
unsigned int affected_rows;
char mbuf[513];
unsigned long sqlrows() { return rows; }
unsigned int sqlaffected() { return affected_rows; }
char *sql_escape(char *str)
{
static char ret[513];
mysql_real_escape_string(&mysql, ret, str, strlen(str) );
return ret;
}
char *sqlstat()
{
return mysql_stat(&mysql);
}
int sql_connect()
{
if(mysql_real_connect(&mysql, config.sqlhost, config.sqluser, config.sqlpass,
config.sqldb, ( (strcmp(config.sqlhost, "localhost") == 0) ? 0 : 3306 ),
"/var/lib/mysql/mysql.sock", 0) == NULL)
{
dbState = -1;
printf("[mysql] error: %s\n", mysql_error(&mysql) );
return 0;
}
if(arg_verbose)
printf("[mysql] Connected [%s]\n", mysql_get_host_info(&mysql));
dbState = 1;
return 1;
}
int sql_query(const char *query)
{
int err;
#ifdef DEBUG_MODE
printf("%s\n", query);
#endif
err = mysql_real_query( &mysql, query, strlen(query) );
if(err == 0)
{
result = mysql_store_result(&mysql);
if (result) // there are rows
{
num_fields = mysql_num_fields(result);
rows = mysql_num_rows(result);
counter.mysql++;
return 0;
// retrieve rows, then call mysql_free_result(result)
}
else // mysql_store_result() returned nothing; should it have?
{
if(mysql_field_count(&mysql) == 0)
{
// query does not return data
// (it was not a SELECT)
affected_rows = mysql_affected_rows(&mysql);
counter.mysql++;
return 1;
}
else // mysql_store_result() should have returned data
{
printf("Error: %s\n", mysql_error(&mysql));
counter.sqlfail++;
return -1;
}
}
}
counter.sqlfail++;
sprintf(mbuf, "[mysql] error with query: \"%s\" (%s)\n", query, mysql_error(&mysql));
printf(mbuf);
if(connected == 1)
sRelay(mbuf);
return -1;
}
int sql_next()
{
if(!result)
return 0;
if( (row = mysql_fetch_row(result)) )
{
lengths = mysql_fetch_lengths(result);
return 1;
}
//end of rows
sql_free();
#ifdef DEBUG_MODE
printf("[mysql] free'd result\n");
#endif
return 0;
}
int sql_free()
{
mysql_free_result(result);
return 1;
}
char *get_field(char *gbuffer, unsigned int size, unsigned int index)
{
if(!row)
return NULL;
if((unsigned int)lengths[index] > size)
{
return NULL;
}
sprintf(gbuffer, "%.*s", (int) lengths[index], row[index] ? row[index] : "NULL");
// printf("%s\n", buffer);
return gbuffer;
}
Ok now r the errors i get...
Code:
mysql.c:24: warning: type defaults to `int' in declaration of `mysql'
mysql.c:24: warning: data definition has no type or storage class
mysql.c:25: warning: type defaults to `int' in declaration of `MYSQL_RES'
mysql.c:25: warning: data definition has no type or storage class
mysql.c:26: warning: type defaults to `int' in declaration of `MYSQL_ROW'
mysql.c:26: warning: data definition has no type or storage class
mysql.c: In function `sql_escape':
mysql.c:40: warning: implicit declaration of function `mysql_real_escape_string'
mysql.c: In function `sqlstat':
mysql.c:46: warning: implicit declaration of function `mysql_stat'
mysql.c:46: warning: return makes pointer from integer without a cast
mysql.c: In function `sql_connect':
mysql.c:52: warning: implicit declaration of function `mysql_real_connect'
mysql.c:54: warning: comparison between pointer and integer
mysql.c:57: warning: implicit declaration of function `mysql_error'
mysql.c:57: warning: format argument is not a pointer (arg 2)
mysql.c:61: warning: implicit declaration of function `mysql_get_host_info'
mysql.c:61: warning: format argument is not a pointer (arg 2)
mysql.c: In function `sql_query':
mysql.c:74: warning: implicit declaration of function `mysql_real_query'
mysql.c:78: `result' undeclared (first use in this function)
mysql.c:78: (Each undeclared identifier is reported only once
mysql.c:78: for each function it appears in.)
mysql.c:78: warning: implicit declaration of function `mysql_store_result'
mysql.c:81: warning: implicit declaration of function `mysql_num_fields'
mysql.c:82: warning: implicit declaration of function `mysql_num_rows'
mysql.c:89: warning: implicit declaration of function `mysql_field_count'
mysql.c:93: warning: implicit declaration of function `mysql_affected_rows'
mysql.c:99: warning: format argument is not a pointer (arg 2)
mysql.c:107: warning: format argument is not a pointer (arg 4)
mysql.c: In function `sql_next':
mysql.c:117: `result' undeclared (first use in this function)
mysql.c:120: `row' undeclared (first use in this function)
mysql.c:120: warning: implicit declaration of function `mysql_fetch_row'
mysql.c:122: warning: implicit declaration of function `mysql_fetch_lengths'
mysql.c:122: warning: assignment makes pointer from integer without a cast
mysql.c: In function `sql_free':
mysql.c:135: warning: implicit declaration of function `mysql_free_result'
mysql.c:135: `result' undeclared (first use in this function)
mysql.c: In function `get_field':
mysql.c:142: `row' undeclared (first use in this function)
make: *** [mysql.o] Error 1
Pls help meh ;-)
-H4wk