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

Few questions from idiot


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LambdaLambda
AlliedModders Donor
Join Date: Oct 2010
Location: London
Old 10-23-2012 , 15:19   Few questions from idiot
Reply With Quote #1

Hey,

i've done my own plugin. The idea is, to work with MySQL database. To insert, select etc. data into/from it. Everything was goig right until i had to seperate the servers somehow. So i choosen the string option. Like, to put as a table name a string, which gets data from cVar.

Ookay, so i've done it.
PHP Code:
Format(testsizeof(test), "INSERT INTO %t(steamid, ingame) VALUES ('%s',1)"tablenameauth); 
It does compile, looks like it gonna work. But when i connect to the server, when the plugin have to send data to mysql, it just doesn't, and i do get errors in errorlogs.
Quote:
[0] Line 98, test.sp::OnClientAuthorized()
Native "SQL_TQuery" reported: Invalid database Handle 0 (error: 4)
Any ideas how to fix it? Or maybe it's impossible what i'm trying to do?

Last edited by LambdaLambda; 10-26-2012 at 14:02.
LambdaLambda is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-23-2012 , 15:24   Re: String as a table in MySQL part
Reply With Quote #2

%t should be %s in your Format line or you're missing arguments for your translation phrase.

Weird, I made a similar mistake in a test plugin just the other day.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-23-2012 at 15:26.
Powerlord is offline
LambdaLambda
AlliedModders Donor
Join Date: Oct 2010
Location: London
Old 10-23-2012 , 16:49   Re: String as a table in MySQL part
Reply With Quote #3

When i put the table name, then it works great. Saves data inside my database etc.
[PHP]Format(test, sizeof(test), "INSERT INTO fort(steamid, ingame) VALUES ('%s',1)", auth);[PHP] - it works.

But when i will put there %s, so it will look like this:
PHP Code:
Format(testsizeof(test), "INSERT INTO %s(steamid, ingame) VALUES ('%s',1)"tablenameauth); 
- then it doesn't work. Just like it was skipping.

Did you actually try to put a string as a table name? Or maybe there is other solution?

But i didn't told you why i need to easy change that table. It will be on more than one server, and i need to have a seperate table for each server.


Thanks for help, btw.

Last edited by LambdaLambda; 10-23-2012 at 17:01.
LambdaLambda is offline
Root_
Veteran Member
Join Date: Jan 2012
Location: ryssland
Old 10-23-2012 , 17:32   Re: String as a table in MySQL part
Reply With Quote #4

Add two single quotes in a string. Should looks like '%s'
A tip: in dbi stuff you should quote strings, however, no need to do it for float, bool or integer
__________________


dodsplugins.com - Plugins and Resources for Day of Defeat
http://twitch.tv/zadroot
Root_ is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 10-23-2012 , 17:38   Re: String as a table in MySQL part
Reply With Quote #5

Quote:
Originally Posted by LambdaLambda View Post
%s(steamid, ingame)
O_o i'm no professional when it comes to SQL, but i think there needs to be a space between the table name and the values column names..
Only other thing that i could recommend is that you make it FailState when it gets an error on the callback. and See what's happening.

Last edited by Mitchell; 10-23-2012 at 17:43.
Mitchell is offline
Root_
Veteran Member
Join Date: Jan 2012
Location: ryssland
Old 10-23-2012 , 17:41   Re: String as a table in MySQL part
Reply With Quote #6

Quote:
Originally Posted by Mitchell View Post
but i think there needs to be a space between the table name and the values column names..
If database is not defined as "table "
__________________


dodsplugins.com - Plugins and Resources for Day of Defeat
http://twitch.tv/zadroot
Root_ is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 10-23-2012 , 17:52   Re: String as a table in MySQL part
Reply With Quote #7

Quote:
Originally Posted by Root_ View Post
If database is not defined as "table "
Then shame on the code for:
1. not having a logical variable, thus making it harder to find the problem if you forget that space. and
2. for not even telling use the variable string he is inputting.
Mitchell is offline
LambdaLambda
AlliedModders Donor
Join Date: Oct 2010
Location: London
Old 10-25-2012 , 20:08   Re: String as a table in MySQL part
Reply With Quote #8

Okay guys. Sorry for not answear, my work didn't allow me for it. I did it, that was only a fucked up string.

PS there's quotes like this ' ' doesn't work in MySQL, you have to use ` `. That's why i had a little mish mash in my head, because i did try quotes, but the first ones.

Now, to not opening new topic will ask shortly. I did download that plugin http://forums.alliedmods.net/showthread.php?p=1824790 (version light). And i did try to change it. It works like that, if i have buyed a slot, then that menu dont allow me to buy a slot again, because it says me the rest of my slot's time. It's okay, but i did try to change it. That what i wanted to do is to allow you to click a slot to buy, but if you already have it, it says you that. I thought it gonna work, but when compiling theres no others errors than one "Error 100: Function Prototypes do not match"

And that what i've changed is:

This:
PHP Code:
public Action:CommandLP(clientargs)
{
    new 
Handle:menu CreateMenu(MenuHandler);
    
SetMenuTitle(menu"Loyalty Point System");
    
AddMenuItem(menu"1""Show LP");
    
    if (
HaveClientRS(client))
    {
        new 
String:s_menu5[100];
        new 
client_rsmin GetRSMIN(client);
        if (
client_rsmin <= 60)
        {
            
Format(s_menu5sizeof(s_menu5), "Your RS access end in %i min"GetRSMIN(client));
        }
        else if (
client_rsmin <= 1440)
        {
            
Format(s_menu5sizeof(s_menu5), "Your RS access end in %i h"GetRSMIN(client)/60);
        }
        else
        {
            
Format(s_menu5sizeof(s_menu5), "Your RS access end in %i d"GetRSMIN(client)/1440);
        }
        
AddMenuItem(menu"6"s_menu5ITEMDRAW_DISABLED);
    }
    else
    {
        
AddMenuItem(menu"7""Reserved Slot");
    }
    
    
DisplayMenu(menuclientMENU_TIME_FOREVER);
    
    return 
Plugin_Handled;

To this:
PHP Code:
public Action:CommandLP(clientargs)
{
    new 
Handle:menu CreateMenu(MenuHandler);
    
SetMenuTitle(menu"Loyalty Point System");
    
AddMenuItem(menu"1""Show LP");
    
AddMenuItem(menu"7""Reserved Slot");

    return 
Plugin_Handled;


And this:
PHP Code:
public MenuRS(Handle:menuMenuAction:actionparam1param2)
{
    if (
action == MenuAction_Select)
    {
        new 
String:info[32];
        
GetMenuItem(menuparam2infosizeof(info));
        
        new 
lp GetLP(param1)
        
        switch(
StringToInt(info))
        {
            case 
1:
            {
                if (
lp >= price_rs_1day)
                {
                    
RemoveLP(param1price_rs_1day)
                    
GiveRS(param11440);
                    
                    if (
IsClientInGame(param1))
                    {
                        
PrintToChat(param1"\x04[LP]\x01 You have bought RS! If Server is full, connect by console to use your reserved slot.")
                    }
                }
                else 
                {
                    
PrintToChat(param1"\x04[LP]\x01 You have %i lp, but you need %i for 1 Day RS!"lpprice_rs_1day);
                }
            }
            case 
2:........ 
To this:
PHP Code:
public MenuRS(Handle:menuMenuAction:actionparam1param2client)
{
    if (
action == MenuAction_Select)
    {
        new 
String:info[32];
        
GetMenuItem(menuparam2infosizeof(info));
        
        new 
lp GetLP(param1)
        
        switch(
StringToInt(info))
        {
            case 
1:
            {if (
HaveClientRS(client))
            {
                    
PrintToChat(param1"You already have a slot");
            }
            else
            {
                    if (
lp >= price_rs_1day)
                    {
                        
RemoveLP(param1price_rs_1day)
                        
GiveRS(param11440);
                    
                        if (
IsClientInGame(param1))
                        {
                            
PrintToChat(param1"\x04[LP]\x01 You have bought RS! If Server is full, connect by console to use your reserved slot.")
                        }
                    }
                    else 
                    {
                        
PrintToChat(param1"\x04[LP]\x01 You have %i lp, but you need %i for 1 Day RS!"lpprice_rs_1day);
                    }
                }
            }
            case 
2:... 
The full code of that plugin you can check in the link above. Can anyone tell me how to fix it?

Last edited by LambdaLambda; 10-25-2012 at 20:16.
LambdaLambda is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 10-26-2012 , 07:47   Re: String as a table in MySQL part
Reply With Quote #9

Why did you change the prototype of MenuRS?
__________________
FaTony is offline
LambdaLambda
AlliedModders Donor
Join Date: Oct 2010
Location: London
Old 10-26-2012 , 14:24   Re: Few questions from idiot
Reply With Quote #10

coz i'm idiot. Thanks.

One more, and last one.

IMO, this should check if in table pfield_content is filled in field_11, and if it's client's steamid. And if there is filled in, to get member_id. And then if it has found steamid in there to send as a true, or if not to send as a false. The point is, it doesn't work. It do connects to database etc. And the error console says is "[0] Line 529, testytest.sp::ForumAccount()"
PHP Code:
bool:ForumAccount(client)
{
    if (
IsClientInGame(client))
    {
        new 
String:steamid[50];
        
GetClientAuthString(clientsteamidsizeof(steamid))
        new 
String:sqlstring[200];
        
Format(sqlstringsizeof(sqlstring), "SELECT member_id FROM pfields_content WHERE field_11 = %s "steamid);
        
SQL_LockDatabase(dbconipb);
        new 
Handle:sql SQL_Query(dbconipbsqlstring);
        new 
forumek_bool SQL_GetRowCount(sql);
        
CloseHandle(sql);
        
SQL_UnlockDatabase(dbconipb);
        
        if (
forumek_bool)
        {
            return 
true;
        }
        else
        {
            return 
false;
        }
    }
    
    return 
true;

What's wrong in here?
LambdaLambda 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 05:25.


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