Raised This Month: $ Target: $400
 0% 

Help with the new dbi...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LoWe
Member
Join Date: Mar 2004
Old 09-27-2004 , 11:15   Help with the new dbi...
Reply With Quote #1

Why does this code:
Code:
public dbseinit() {
	get_cvar_string("amx_sql_host",sqlhost,64) // Fetch the database info
	get_cvar_string("amx_sql_user",sqluser,32) // stated in sql.cfg	
	get_cvar_string("amx_sql_pass",sqlpass,32) 
	get_cvar_string("amx_sql_db",sqldbname,32)
	new Sql:dbiSqL = dbi_connect(sqlhost,sqluser,sqlpass,sqldbname,sqlerrormsg,255) // And connect to the database
	if (dbiSqL <= SQL_FAILED) { // If there is an error
		server_print("[Disturbed] %L",LANG_SERVER,"SQL_CANT_CON",sqlerrormsg) // Show the errormessage
		dbi_close(dbiSqL) // Close the connection
		return PLUGIN_HANDLED // Finish the plugin
	} 
	// If Connected Successfuly
	server_print("[Disturbed] %L",LANG_SERVER,"SQL_CONNECTED") // Show the Connected message
	return PLUGIN_CONTINUE // And continue with the rest of plugin
}
generate this error:
Quote:
//// dbse.sma
// D:\HLServer\cstrike\addons\amxmodx\scripting\ dbse.sma(2 : warning 219: loca
l variable "dbiSqL" shadows a variable at a preceding level
I have tryed to change the dbiSqL to a lot of other things but nothing seems to work
LoWe is offline
Send a message via Skype™ to LoWe
Zor
Veteran Member
Join Date: Mar 2004
Location: Toronto, ON
Old 09-27-2004 , 11:29  
Reply With Quote #2

Because you have a bracket or something missing above this function. Its not the DB. Please post the whole .sma

Cheers!
__________________
Zor is offline
Send a message via AIM to Zor Send a message via MSN to Zor Send a message via Yahoo to Zor
LoWe
Member
Join Date: Mar 2004
Old 09-27-2004 , 11:43  
Reply With Quote #3

oh i dont rely see it

Code:
/* amx_auth script by lowe *   1.0 First Working Version *   1.2 amxx-0.20 *   *     */ #include <amxmodx> // Includes the #include <dbi> // include-files new sqlhost[64],sqluser[64],sqlpass[64],sqldbname[64],sqlerrormsg[256] // SQL connection related variables public plugin_init() {     register_plugin("DB.se - Script","1.2","lowe") //register the pluginname, version, and creator     register_dictionary("db.se.txt") // Registers the DB.se dictionary     register_clcmd("amx_auth","auth_me",0,"<nick> <password> Registers your STEAM ID in the Disturbed.se database") // amx_auth commando, to register your steamid into the database     set_task(10.0,"dbseinit") } public plugin_modules() {    require_module("DBI") } // ************************************************************************************************************* public dbseinit() {     get_cvar_string("amx_sql_host",sqlhost,64) // Fetch the database info     get_cvar_string("amx_sql_user",sqluser,32) // stated in sql.cfg     get_cvar_string("amx_sql_pass",sqlpass,32)     get_cvar_string("amx_sql_db",sqldbname,32)     new Sql:dbiSqL = dbi_connect(sqlhost,sqluser,sqlpass,sqldbname,sqlerrormsg,255) // And connect to the database     if (dbiSqL <= SQL_FAILED) { // If there is an error         server_print("[Disturbed] %L",LANG_SERVER,"SQL_CANT_CON",sqlerrormsg) // Show the errormessage         dbi_close(dbiSqL) // Close the connection         return PLUGIN_HANDLED // Finish the plugin     }     // If Connected Successfuly     server_print("[Disturbed] %L",LANG_SERVER,"SQL_CONNECTED") // Show the Connected message     return PLUGIN_CONTINUE // And continue with the rest of plugin } // ************************************************************************************************************* new g_regged[33] // Adds a variable used to check if a user is regged. // ********************************Auther Starts Here*********************************************************** public auth_me(id) { // the auther     new iargs = read_argc() // reads the number of arguments     if (iargs != 3) { // if there is to few or to many...         console_print(id,"[AMXX] %L", LANG_PLAYER, "AUTH_MISS_ARGS") // echo an errormessage to users console         return PLUGIN_CONTINUE // and finish the auther function     }     new aname[32],apassword[64],asteamid[32] // Variabels for users nick + pass + steamid     read_argv(1,aname,32) // Save name in variable     read_argv(2,apassword,64) // save password in variable     get_user_authid(id,asteamid,31) // save steamid to variable     g_regged[id] = auther(asteamid, aname, apassword) // execute the auther boolesk function     if (g_regged[id]) { // if auther() returns 1             console_print(id,"[Disturbed] %L",LANG_SERVER,"AUTH_REGGED",asteamid) // Write a confirmation in the console     } else { // if not             console_print(id,"[Disturbed] %L",LANG_SERVER,"AUTH_REGG_FAIL",asteamid,aname) // Echo Failure Msg     }     return PLUGIN_CONTINUE // Continue =) } // *****************************************Auther Continue**************************************************** bool:auther(asteamid[], aname[], apassword[]) { // the auther() function     const LONGER = 128 // Save the length of the query variable in a constant     new query[LONGER + 1] // Create variables for query             format(query, LONGER, "SELECT `id` FROM members WHERE nick = '%s' AND pass = ENCODE('%s','Secret :P)", aname, apassword) // Formate Query to check if user is registered     new Result:result = dbi_query(dbiSqL, query) // Execute the query         if (result == RESULT_NONE) { // If nothing is returned         return false // Fail the function     }     if ( result == RESULT_FAILED ) { // If there is a error...                 dbi_error(dbiSqL,sqlerrormsg,255) // save error in sqlerrormsg                 server_print("[Disturbed] %L",LANG_SERVER,"SQL_ERROR", sqlerrormsg) // and echo the errormessage to the console             return false // Fail the function       }     new aid = dbi_getfield(dbiSqL, 1) // save the users userid     dbi_free_result(result) // Free the result from the query             format(query, LONGER, "SELECT `gid` FROM gamelink where game = 'cstrike' AND id = '%s'", aid) // Formate Query to check if user has a registered steamid     new Result:result = dbi_query(dbiSqL, query) // Execute the query     if ( result == RESULT_FAILED ) { // If there is a error...                 dbi_error(dbiSqL,sqlerrormsg,255) // save error in sqlerrormsg                 server_print("[Disturbed] %L",LANG_SERVER,"SQL_ERROR", sqlerrormsg) // and echo the errormessage to the console             return false // Fail the function       }         if (result == RESULT_NONE) { // If nothing is returned (aka. First time to set steamid)         dbi_free_result(result) // free the results from the query         format(query, LONGER, "insert into gamelink(gid,id,game) VALUES('%s','%s','cstrike')",asteamid,aid)  // Formate Query to save the steamid in the database         new Result:result = dbi_query(dbiSqL, query) // Execute the query             if ( result == RESULT_FAILED ) { // If there is a error...                     dbi_error(dbiSqL,sqlerrormsg,255) // save error in sqlerrormsg                     server_print("[Disturbed] %L",LANG_SERVER,"SQL_ERROR", sqlerrormsg) // and echo the errormessage to the console                 return false // Fail the function               }     }     else { // if things are returned (aka. not first time the query is executed)         dbi_free_result(result)         format(query, LONGER, "update gamelink set gid = '%s' WHERE id = '%s' AND game = 'cstrike' LIMIT 1",asteamid,aid)  // Formate Query to save the steamid in the database         new Result:result = dbi_query(dbiSqL, query) // Execute the query         if ( result == RESULT_FAILED ) { // If there is a error...             dbi_error(dbiSqL,sqlerrormsg,255) // save error in sqlerrormsg             server_print("[Disturbed] %L",LANG_SERVER,"SQL_ERROR", sqlerrormsg) // and echo the errormessage to the console             return false // Fail the function           }     }     return true } // **************************************************End of Auther**********************************************
LoWe is offline
Send a message via Skype™ to LoWe
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 09-27-2004 , 12:36  
Reply With Quote #4

You need to take a few steps back here.

Firstly, go and look at some well-indented code. Your code lacks good indentation, it will give you troubles, just like you have troubles now. Indentation is worthless for the compiler, but not worhtless for you and me, which means in the end we will write crappy code if we can't see what we're doing. And that is something the compiler eventually will bug us about.

Secondly, when creating a db connection that you intend to use throughout the rest of the plugin, you should save that db handle - which you aren't doing here because the db handle you get when you create the connection in dbseinit is only stored locally in the variable dbiSqL. I can see that you try to access "the same" variable in other functions, but as they aren't defined anywhere in the scopes of those functions, you won't either be able to reach them.

A solution: define dbiSql globally. It would make sense. Probably you intended to do this all the time (just agree now ;-)).

The small compiler is far from even good: the problem here was not that dbiSqL was defined at an earlier level: it was not created at all... I don't really know why the compiler does this, but it sure looks like a bug in the compiler to me.
Johnny got his gun is offline
Zor
Veteran Member
Join Date: Mar 2004
Location: Toronto, ON
Old 09-27-2004 , 16:08  
Reply With Quote #5

Ok here is a good copy of the file. I only get one warning and I dont know why. Now I would pay attention to the coding style, its using a convention and one that you should use. Its not the only one but its one that is EASY to read. Your code was very difficult and hard to comprehend. It took about 1/2 an hour just to decifer. But as JGHG has stated you should learn to use a convention of some such:

Code:
/* amx_auth script by lowe *   1.0 First Working Version *   1.2 amxx-0.20 *   *       */ // Includes the include-files #include <amxmodx> #include <dbi> // DBI new Sql:dbiSqL new errormsg[256] // Adds a variable used to check if a user is regged new g_regged[33] public plugin_init() {     //register the pluginname, version, and creator     register_plugin("DB.se - Script","1.2","lowe")         // Registers the DB.se dictionary     register_dictionary("db.se.txt")         // amx_auth commando, to register your steamid into the database     register_clcmd("amx_auth","auth_me",0,"<nick> <password> Registers your STEAM ID in the Disturbed.se database")     return PLUGIN_CONTINUE } public plugin_modules() {     require_module("DBI")         return PLUGIN_CONTINUE } public plugin_cfg() {     new sqlhost[64], sqluser[64], sqlpass[64], sqldbname[64]         // Fetch the database info stated in sql.cfg     get_cvar_string("amx_sql_host",sqlhost,64)     get_cvar_string("amx_sql_user",sqluser,32)         get_cvar_string("amx_sql_pass",sqlpass,32)     get_cvar_string("amx_sql_db",sqldbname,32)         dbiSqL = dbi_connect(sqlhost,sqluser,sqlpass,sqldbname,errormsg,255)         if(dbiSqL <= SQL_FAILED)     {         // If there is an error Show the errormessage         server_print("[Disturbed] %L",LANG_SERVER,"SQL_CANT_CON",errormsg)                 // Close the connection         dbi_close(dbiSqL)             return PLUGIN_HANDLED     }         // If Connected Successfuly and Show the Connected message     server_print("[Disturbed] %L",LANG_SERVER,"SQL_CONNECTED")         return PLUGIN_CONTINUE } public auth_me(id) {     // reads the number of arguments     new iargs = read_argc()     // if there is to few or to many...     if(iargs != 3)     {         // echo an errormessage to users console and finish the auther function         console_print(id,"[AMXX] %L", LANG_PLAYER, "AUTH_MISS_ARGS")         return PLUGIN_CONTINUE     }         // Variabels for users nick + pass + steamid     new aname[32],apassword[64],asteamid[32]     // Save name in variable     read_argv(1,aname,32)     // save password in variable     read_argv(2,apassword,64)     // save steamid to variable     get_user_authid(id,asteamid,31)         // execute the auther boolesk function     g_regged[id] = auther(asteamid, aname, apassword)     // if auther() returns 1     if(g_regged[id])     {         // Write a confirmation in the console         console_print(id,"[Disturbed] %L",LANG_SERVER,"AUTH_REGGED",asteamid)     }         // if not     else     {         // Echo Failure Msg         console_print(id,"[Disturbed] %L",LANG_SERVER,"AUTH_REGG_FAIL",asteamid,aname)     }         return PLUGIN_CONTINUE } // the auther() function bool:auther(asteamid[], aname[], apassword[]) {     // Create variables for query     new query[128], Result:theResult     // Formate Query to check if user is registered     format(query, 127, "SELECT 'id' FROM members WHERE nick = '%s' AND pass = ENCODE('%s','Secret :P)", aname, apassword)     // Execute the query     theResult = dbi_query(dbiSqL, query)     // If nothing is returned     if(theResult == RESULT_NONE)     {         return false       }         // If there is a error...     if(theResult == RESULT_FAILED)     {         // save error in sqlerrormsg         dbi_error(dbiSqL,errormsg,255)                   // and echo the errormessage to the console         server_print("[Disturbed] %L",LANG_SERVER,"SQL_ERROR", errormsg)         return false     }         // save the users userid     new aid = dbi_field(dbiSqL, 1)     dbi_free_result(theResult)     // Formate Query to check if user has a registered steamid     format(query, 127, "SELECT 'gid' FROM gamelink where game = 'cstrike' AND id = '%s'", aid)         // Execute the query     theResult = dbi_query(dbiSqL, query)     // If there is a error...     if( theResult == RESULT_FAILED )     {         dbi_error(dbiSqL,errormsg,255)         server_print("[Disturbed] %L",LANG_SERVER,"SQL_ERROR", errormsg)                 return false     }     // If nothing is returned (aka. First time to set steamid)       if(theResult == RESULT_NONE)     {         dbi_free_result(theResult)         format(query, 127, "insert into gamelink(gid,id,game) VALUES('%s','%s','cstrike')",asteamid,aid)         theResult = dbi_query(dbiSqL, query)                 if(theResult == RESULT_FAILED)         {             dbi_error(dbiSqL,errormsg,255)             server_print("[Disturbed] %L",LANG_SERVER,"SQL_ERROR", errormsg)             return false         }     }         // if things are returned (aka. not first time the query is executed)     else     {         dbi_free_result(theResult)         format(query, 127, "update gamelink set gid = '%s' WHERE id = '%s' AND game = 'cstrike' LIMIT 1",asteamid,aid)         theResult = dbi_query(dbiSqL, query)         if(theResult == RESULT_FAILED)         {             dbi_error(dbiSqL,errormsg,255)             server_print("[Disturbed] %L",LANG_SERVER,"SQL_ERROR", errormsg)             return false         }     }         return true }

Cheers! And Luck.
__________________
Zor is offline
Send a message via AIM to Zor Send a message via MSN to Zor Send a message via Yahoo to Zor
BigBaller
Veteran Member
Join Date: Mar 2004
Location: Everett, WA
Old 09-27-2004 , 16:33  
Reply With Quote #6

yea, instead of using the code tags

use the
Code:
 tags
instead.
__________________

BigBaller is offline
LoWe
Member
Join Date: Mar 2004
Old 09-27-2004 , 18:33  
Reply With Quote #7

I realy love you, you didnt have to make it so good indented, i was going to fix that anyway, and to you Johnny got his gun, I agree with the things you wanted me to agree to, and i agree that it was stupid of me tho come and ask for help with that "ugly" code

zor, you must have bean realy bored this day?

Edit: You shouldnt have return PLUGIN_CONTINUE in the modules part, or atleast you doesnt need it, may that have created the error?

Edit:
new aid = dbi_field(dbiSqL, 1)
This gives me a tag missmatch error, can someone explain whats wrong?
LoWe is offline
Send a message via Skype™ to LoWe
Zor
Veteran Member
Join Date: Mar 2004
Location: Toronto, ON
Old 09-27-2004 , 20:31  
Reply With Quote #8

Ok. Just figured it out. Ok:

Code:
// save the users userid dbi_nextrow(theResult) new aid = dbi_result(theResult, "id") dbi_free_result(theResult)

The way you had it you were passing the SQL reference to it not the RESULT. I fixed it here. I also changed it to dbi_result instead of dbi_field this is better I think. That way you are referencing the exact variable.

Cheers!
__________________
Zor is offline
Send a message via AIM to Zor Send a message via MSN to Zor Send a message via Yahoo to Zor
LoWe
Member
Join Date: Mar 2004
Old 09-28-2004 , 03:23  
Reply With Quote #9

:O, Before i was using !mysq_nextrow to check if there was any errors, i guess thats what moved it forward there

thanks a lot
LoWe is offline
Send a message via Skype™ to LoWe
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 17:21.


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