User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Closed Thread
Thread Tools Display Modes
Unread 14 Mar 2003, 17:54   #1
h4wk
Guest
 
Posts: n/a
Mysql

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
 
Unread 14 Mar 2003, 18:05   #2
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
I have no idea. What's it suposed to do?
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline  
Unread 15 Mar 2003, 13:36   #3
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
<stating the='obvious'>You havent installed/configured mysql correctly and/or havent included the relevant mysql header</stating>
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline  
Unread 17 Mar 2003, 10:37   #4
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
I don't respond to being called "j00".
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline  
Unread 17 Mar 2003, 14:56   #5
Starbucks
It was a Stupid Dream
 
Starbucks's Avatar
 
Join Date: Jun 2002
Location: Winchester, UK
Posts: 2,077
Starbucks is on a distinguished road
Quote:
Originally posted by Mong
I don't respond to being called "j00".
screw j00self



as said, you havent included relevent mysql info
Starbucks is offline  
Unread 31 Mar 2003, 17:43   #6
Laze
Registered User
 
Join Date: Jul 2001
Posts: 15
Laze is an unknown quantity at this point
It looks like you are not including the mysql header files. I would check to see what is #included by main.h
Laze is offline  
Unread 31 Mar 2003, 18:40   #7
queball
Ball
 
queball's Avatar
 
Join Date: Oct 2001
Posts: 4,410
queball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so little
Woops, this was solved ages ago.

<H4wk0r> I've got it workin

He didn't have libmysqlclient installed, and several other problems.
__________________
#linux
queball is offline  
Closed Thread



Forum Jump


All times are GMT +1. The time now is 03:54.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018