Raised This Month: $51 Target: $400
 12% 

SQL_FetchString/Row etc?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 09-11-2015 , 14:00   SQL_FetchString/Row etc?
Reply With Quote #1

Hey, so i'm nearly done with what i wanted to create.. but the mysql is being a bit annoying.

PHP Code:
StartSQL()
{
    
SQL_TConnect(DB_Connect"xxxx");
}

public 
DB_Connect(Handle:ownerHandle:hndl, const String:error[], any:client)
{
    if (
hndl == INVALID_HANDLE)
    {
        
LogError("error: %s"error);
        
DBConnectionIsRIP true;
    }
    else
    {
        
g_hDB hndl;
    }


public 
Action:Command_Alert(clientargs)
{
    new 
String:query[128];
    
FormatEx(querysizeof(query), "SELECT globalAlert FROM Settings");
    
SQL_TQuery(g_hDBalert_callbackquery);
}

public 
alert_callback(Handle:ownerHandle:hndl, const String:error[], any:data)
{
    
PrintToChatAll("callback works, but query?!?! You're bad at coding Danian :C");
    
    while(
SQL_FetchRow(hndl))
    {
        
SQL_FetchString(hndl3alertMessagesizeof(alertMessage));
        
CPrintToChatAll("{red}Arctek ★ Alert: %s"alertMessage);
    }

Database:


This compiles fine, but the server shows this whenever i use it:
Code:
[SM] Native "SQL_FetchString" reported: Error fetching data from field 3
Any help is appreciated!
__________________
SourcePawn Coding Level: Novice
DJ Data is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-11-2015 , 14:18   Re: SQL_FetchString/Row etc?
Reply With Quote #2

"SELECT globalAlert FROM Settings" is only fetching a single field, globalAlert.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
DJ Data
SourceMod Donor
Join Date: Dec 2012
Location: Switzerland
Old 09-11-2015 , 14:51   Re: SQL_FetchString/Row etc?
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
"SELECT globalAlert FROM Settings" is only fetching a single field, globalAlert.
I tried "SELECT globalAlert FROM Settings WHERE 'index' = 1" and it did nothing.

If i would then remove the FetchRow check, it tells me there is no result. Which is obvious, since we have to call FetchRow first.

So im really at a dead end here.

EDIT:
Ohhhh!!
I just got what you meant!
I'll try it with 0 then.

EDIT 2: Fixed!! Thank you so much <3
__________________
SourcePawn Coding Level: Novice

Last edited by DJ Data; 09-11-2015 at 14:55.
DJ Data is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 09-11-2015 , 16:40   Re: SQL_FetchString/Row etc?
Reply With Quote #4

Quote:
Originally Posted by DJ Data View Post
I tried "SELECT globalAlert FROM Settings WHERE 'index' = 1" and it did nothing.

If i would then remove the FetchRow check, it tells me there is no result. Which is obvious, since we have to call FetchRow first.

So im really at a dead end here.

EDIT:
Ohhhh!!
I just got what you meant!
I'll try it with 0 then.

EDIT 2: Fixed!! Thank you so much <3
As far as I'm aware, the results returned are an array who's field at an index match the index it went into the Select statement
__________________
WildCard65 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-11-2015 , 17:09   Re: SQL_FetchString/Row etc?
Reply With Quote #5

Yeah, if you have to use a raw database API1, they're basically all like this for SELECT statements:
  1. Execute a SELECT statement.
  2. Fetch a row (DB API may do this for you for the first row)
  3. Fetch the field(s) you want.
  4. Do something with it.
  5. Repeat steps 2-4 until you run out of rows.

1As opposed to an ORM (Object Relational Model) which turns result sets into objects in an OO language.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 09-11-2015 at 17:10.
Powerlord is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 09-11-2015 , 17:37   Re: SQL_FetchString/Row etc?
Reply With Quote #6

smlib's sql_fetch*byname functions let you avoid the dum field indices
Miu is offline
Reply



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 01:47.


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