Raised This Month: $32 Target: $400
 8% 

SQL Error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
Old 08-05-2010 , 19:13   SQL Error
Reply With Quote #1

I'm trying to fix a friend's code, but I don't understand SQL at all. Basically no data is loading. It might be because it isn't saving too. The only error in the logs is this:

Code:
[SM] Native "SQL_FetchInt" reported: Error fetching data from field 3
What does this mean?
__________________
almcaeobtac is offline
Dravu
Senior Member
Join Date: May 2010
Old 08-06-2010 , 03:42   Re: SQL Error
Reply With Quote #2

In your SQL query, you only return 2 columns. Your coding is trying to grab a 3rd column that doesn't exist.
Dravu is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 08-06-2010 , 06:05   Re: SQL Error
Reply With Quote #3

Columns use indexes, so you start with getting from column "0"

(It's a lot easier to see what's wrong if you show what you did, aka. your query ;p)
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.

Last edited by Monkeys; 08-06-2010 at 06:44.
Monkeys is offline
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
Old 08-06-2010 , 08:26   Re: SQL Error
Reply With Quote #4

It's difficult. It's not my code, and he doesn't want to share it. Plus, in the error logs, it doesn't even return the correct line number for the error.
__________________
almcaeobtac is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 08-06-2010 , 09:17   Re: SQL Error
Reply With Quote #5

Well, most likely it's just a wrong index used for the column.

Check the query, the "SELECT ... FROM" part. The results are arranged exactly as they are there. Each column is seperated by a comma and they start with index 0.

So this "SELECT alpha, and, omega FROM universe WHERE god = 0;"
would result in
column 0: alpha
column 1: and
column 2: omega

In his case, he probably fetched from column 3 while he meant column 2. Or column 3 isn't an int.


(Offtopic: That isn't a query I just made up, it's actually part of a project I once made )
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
Old 08-06-2010 , 09:45   Re: SQL Error
Reply With Quote #6

What about when it's like this:

Code:
Format(buffer, sizeof(buffer),"SELECT * FROM Player WHERE STEAMID = '%s';",SteamId);
__________________
almcaeobtac is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 08-06-2010 , 10:03   Re: SQL Error
Reply With Quote #7

Quote:
Originally Posted by almcaeobtac View Post
What about when it's like this:

Code:
Format(buffer, sizeof(buffer),"SELECT * FROM Player WHERE STEAMID = '%s';",SteamId);
You'll need to know how your Player table is made up. It'll follow that format.
But I'd like to suggest that you never use *, just for this very reason
You don't need all data anyway.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
Old 08-06-2010 , 10:27   Re: SQL Error
Reply With Quote #8

I'm completely confused xD, thanks anyway though.
__________________
almcaeobtac is offline
Antithasys
Moderator
Join Date: Apr 2008
Old 08-06-2010 , 11:36   Re: SQL Error
Reply With Quote #9

When dealing with a database as a coder, you... the coder, need access to the database through some means... like phpmyadmin for mysql or something. There you can see all the tables and fields in the database.

The problem you are having is that you are selecting all the fields (SELECT * ) in the "Player" table and you don't actually know what those fields are, or what datatypes they are.

SQL SELECT queries are formatted like this:

PHP Code:
SELECT field1field2field3 FROM table1 WHERE field1 'matchme'
You are selecting all the fields with a wildcard * from the Players table if the steam id matches. It is possible that you are not getting any results at all (no matches for that steamid), or you do not have the field count/datatype right. Always check to make sure you actually got results before asking for them.
__________________
[my plugins]

When you think about asking a question... consider what have you tried?

Last edited by Antithasys; 08-06-2010 at 12:12. Reason: formatting
Antithasys is offline
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
Old 08-06-2010 , 11:50   Re: SQL Error
Reply With Quote #10

Ahh ok, so I have to remove the * and format it like that?
__________________
almcaeobtac is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:30.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode