Raised This Month: $ Target: $400
 0% 

SQL Query Result Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nhdriver4
Senior Member
Join Date: Nov 2005
Old 03-22-2006 , 02:27   SQL Query Result Help
Reply With Quote #1

Im writing a plugin, and I cant seem to get my sql querys to return any results.

Code:
    new name[32],authid[35]     get_user_authid(id,authid,35)     get_user_name(id,name,32)     new query[350]     format(query,350,"SELECT steamid,tag FROM `%s` WHERE steamid = '%s' ",sql_table,authid)     new Result:result = dbi_query(dbc,query)

I created a log_amx line with the same variables below. It's picking up the table name fine. That's defined at the top of the document. My problem is trying to get the authid to show up with the users steam id in the query.

Any ideas?
__________________
nhdriver4 is offline
Send a message via AIM to nhdriver4
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 03-22-2006 , 02:41  
Reply With Quote #2

Make all of your lengths minus one ( except where you declare the new variables ).
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
nhdriver4
Senior Member
Join Date: Nov 2005
Old 03-22-2006 , 03:03  
Reply With Quote #3

Quote:
Originally Posted by v3x
Make all of your lengths minus one ( except where you declare the new variables ).
Thanks for the suggestion, but still didn't work

Here's the code:
Code:
new name[32],authid[35]     get_user_authid(id,authid,35)     get_user_name(id,name,32)         new query[350]     format(query,350,"SELECT steamid,tag FROM `%s` WHERE steamid ='%s'",sql_table,authid)     log_amx("SELECT steamid,tag FROM `%s` WHERE steamid = '%s'",sql_table,authid)     new Result:result = dbi_query(dbc,query)

Here's the log:
Code:
L 03/22/2006 - 03:04:31: [tagline.amxx] SELECT steamid,tag FROM `tagline` WHERE steamid = ''
L 03/22/2006 - 03:04:31: [tagline.amxx] [AMXXSQL] Database returned no results

Any other ideas?
__________________
nhdriver4 is offline
Send a message via AIM to nhdriver4
teame06
i have a hat
Join Date: Feb 2005
Location: Hat City
Old 03-22-2006 , 03:29  
Reply With Quote #4

Show us the full code
__________________
No private support via Instant Message
GunGame:SM Released
teame06 is offline
Send a message via AIM to teame06
nhdriver4
Senior Member
Join Date: Nov 2005
Old 03-22-2006 , 03:45  
Reply With Quote #5

Sure. Dont mind the mess. It's my first plug using a database.

Code:
#include <amxmodx> #include <amxmisc> #include <engine> #include <dbi> #define PLUGIN "SQL Tagline" #define VERSION "0.1" #define AUTHOR "Wuss" //Sql_Parameter #define sql_host  "localhost"   // Host Name #define sql_user  "root"    // User Name #define sql_pass  ""        // Password #define sql_dbase   "amxx"      // Datbase Name #define sql_table  "tagline"    // The name of the table to create for tagline storage new Sql:dbc; new Result:result; new qerror[128]; new g_TagsON = 1; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_concmd("amx_tagline","tagCreate",ADMIN_RESERVATION,"<message> - Creates a tagline that's displayed when you connect to the server")     check_connection() //  create_table()     } // Attempt the Connection public check_connection() {         dbc = dbi_connect(sql_host,sql_user, sql_pass, sql_dbase, qerror,128);         // Verify our database connection has worked     if ( dbc == SQL_OK )     {         log_amx( "[AMXXSQL] Connection to %s database successful",sql_host);         return PLUGIN_CONTINUE;             }     else     {         log_amx( "[AMXXSQL] Connection to %s database failed",sql_host);     }     return PLUGIN_HANDLED } // Make the table if it doesn't exist // NOT WORKING YET /* public create_table() {     new Result:ret = dbi_query(dbc,"CREATE TABLE IF NOT EXISTS `%s` (`steamid` VARCHAR(35) NOT NULL DEFAULT '',`tag` VARCHAR(256) NOT NULL DEFAULT '')",sql_table)         if ( ret < RESULT_NONE )     {         log_amx( "[AMXXSQL] Database not created")         return PLUGIN_CONTINUE;     }     return PLUGIN_HANDLED } */ public tagCreate(id) {     new authid[64],tag[256],name[32];     get_user_authid(id,authid,63);     get_user_name(id,name,31);     read_argv(1,tag,255)     new Result:res = dbi_query(dbc,"REPLACE INTO %s VALUES ( '%s','%s' )",sql_table,authid,tag);         if (res < RESULT_NONE)     {         log_amx("Error creating a tag entry for %s",name);         console_print(id,"Sorry %s, it didn't work!",name);         return PLUGIN_HANDLED     }         dbi_free_result(res);     console_print(id,"[AMXX] Tagline for %s inserted into database.",authid);     return PLUGIN_HANDLED } // This is the routnie that displays the tagline upon connecting public client_authorized(id) {     set_task(5.0,"tagDisplay") } public tagDisplay(id) {     new name[32],authid[35]     get_user_authid(id,authid,35)     get_user_name(id,name,32)         new query[351]     format(query,351,"SELECT steamid,tag FROM `%s` WHERE steamid ='%s'",sql_table,authid)     log_amx("SELECT steamid,tag FROM `%s` WHERE steamid = '%s'",sql_table,authid)     new Result:result = dbi_query(dbc,query)             if (result == RESULT_FAILED)     {         log_amx("[AMXXSQL] Database connection failed")         return PLUGIN_HANDLED     }         else if (result == RESULT_NONE)     {         log_amx("[AMXXSQL] Database returned no results")         return PLUGIN_HANDLED     }         if(g_TagsON)     {         new rsteamid[35], rtag[256]         dbi_field(Result,1,rsteamid,35)         dbi_field(Result,2,rtag,256)         dbi_free_result(result)                 if(g_TagsON)         {             client_print(0,print_chat,"[AMXX] %s: %s",name,rtag)             log_amx( "[AMXXSQL] %s %s",name,rtag)         }     }     else     {         client_print(0,print_chat,"No tagline is defined for %s",name)         log_amx("[AMXXSQL] No tageline is defined for %s",name)     }         } /* /////////////////////////////////////////////////////////////// public client_disconnect(id){     new szQuery[256],name[32]         new authid[64],ip[32]     get_user_authid(id,authid,63)     get_user_name(id,name,31)     get_user_ip(id,ip,31)     format(szQuery, 511, "REPLACE INTO `%s` (`steamid`,`name`,`ip`, `time`) VALUES ('%s','%s','%s', 'NOW()')", sql_table,authid,name,ip);         new Result:res = dbi_query(sql, szQuery)         if (res < RESULT_NONE)         {         log_amx("Error in querying database, location: %d", id);     }         dbi_free_result(res); }
__________________
nhdriver4 is offline
Send a message via AIM to nhdriver4
teame06
i have a hat
Join Date: Feb 2005
Location: Hat City
Old 03-22-2006 , 04:01  
Reply With Quote #6

Your not passing the id...

Code:
set_task(5.0,"tagDisplay", id)


When you do only set_task(5.0,"tagDisplay") not passing any number. It will be zero.
__________________
No private support via Instant Message
GunGame:SM Released
teame06 is offline
Send a message via AIM to teame06
nhdriver4
Senior Member
Join Date: Nov 2005
Old 03-22-2006 , 04:51  
Reply With Quote #7

Fixed my problem perfect. Thanks.

It now retrieved the information from the databse. However, I now receive this error:
Code:
L 03/22/2006 - 04:52:39: [MYSQL] Invalid result handle -1
L 03/22/2006 - 04:52:39: [AMXX] Displaying debug trace (plugin "tagline.amxx")
L 03/22/2006 - 04:52:39: [AMXX] Run time error 10: native error (native "dbi_nextrow")
L 03/22/2006 - 04:52:39: [AMXX]    [0] tagline.sma::tagDisplay (line 118)
There can only be one result. Am I using the wrong format here?
__________________
nhdriver4 is offline
Send a message via AIM to nhdriver4
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 03-22-2006 , 05:20  
Reply With Quote #8

Quote:
Originally Posted by nhdriver4
Fixed my problem perfect. Thanks.

It now retrieved the information from the databse. However, I now receive this error:
Code:
L 03/22/2006 - 04:52:39: [MYSQL] Invalid result handle -1
L 03/22/2006 - 04:52:39: [AMXX] Displaying debug trace (plugin "tagline.amxx")
L 03/22/2006 - 04:52:39: [AMXX] Run time error 10: native error (native "dbi_nextrow")
L 03/22/2006 - 04:52:39: [AMXX]    [0] tagline.sma::tagDisplay (line 118)
There can only be one result. Am I using the wrong format here?

change
Code:
if(g_TagsON)
to
Code:
else if(g_TagsON)
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
nhdriver4
Senior Member
Join Date: Nov 2005
Old 03-22-2006 , 05:26  
Reply With Quote #9

The tag still shows, along with the error
__________________
nhdriver4 is offline
Send a message via AIM to nhdriver4
Sandurr
Senior Member
Join Date: Aug 2005
Old 03-22-2006 , 05:29  
Reply With Quote #10

be sure ur connected to the database
Sandurr 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 16:46.


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