Raised This Month: $ Target: $400
 0% 

SQL syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
krekers
Junior Member
Join Date: Jul 2007
Old 07-15-2007 , 16:38   SQL syntax
Reply With Quote #1

Code:
dbi_query(dbc, "INSERT INTO table (blah) VALUES (variable)")
How can I put there working variable? I tried many ways:

Code:
dbi_query(dbc, "INSERT INTO table (blah) VALUES (variable)")
dbi_query(dbc, "INSERT INTO table (blah) VALUES (\"variable\")")
dbi_query(dbc, 'INSERT INTO table (blah) VALUES ("variable")')
It doesn't work. Please help me
krekers is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 07-15-2007 , 17:17   Re: SQL syntax
Reply With Quote #2

Format a string.
Code:
new String[256] format(String,255,"%i",myVariable); dbi_query(dbc,String);
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 07-15-2007 , 17:40   Re: SQL syntax
Reply With Quote #3

SixTwin that's not the answer and you don't have to use format.
PHP Code:
 dbi_query(dbc"INSERT INTO %s (%s) VALUES ('%d')"table_namecolumn_namevalue
krekers try :
PHP Code:
 dbi_query(dbc"INSERT INTO table (blah) VALUES ('variable')"
replace variable with formatting code
__________________
Impossible is Nothing
Sylwester is offline
krekers
Junior Member
Join Date: Jul 2007
Old 07-16-2007 , 07:19   Re: SQL syntax
Reply With Quote #4

Thank you very much

All ok, but when I compiled, there showed some warning:

PHP Code:
// plugin.sma(31) : warning 217: loose indentation 
the code:

PHP Code:
dbi_query(dbc"INSERT INTO table (blah) VALUES ('amx')"
The plugin works, but why there showed warning?
krekers is offline
DotNetJunkie
Senior Member
Join Date: May 2005
Location: In front of my pc
Old 07-16-2007 , 08:06   Re: SQL syntax
Reply With Quote #5

Quote:
Originally Posted by krekers View Post
Thank you very much

All ok, but when I compiled, there showed some warning:

PHP Code:
// plugin.sma(31) : warning 217: loose indentation 
the code:

PHP Code:
dbi_query(dbc"INSERT INTO table (blah) VALUES ('amx')"
The plugin works, but why there showed warning?
That warning does not effect the runtime of your plugin, its just a compiler
warning telling you that you have messy code usually.

One thing I'd like to point out is that if you want to protect your server from
SQL injection then use full quotions:

Code:
dbi_query(dbc, "INSERT INTO `table` ( `blah` ) VALUES ( ^"variable^" );");
__________________
DotNetJunkie is offline
Send a message via ICQ to DotNetJunkie Send a message via AIM to DotNetJunkie Send a message via MSN to DotNetJunkie Send a message via Yahoo to DotNetJunkie
krekers
Junior Member
Join Date: Jul 2007
Old 07-16-2007 , 15:45   Re: SQL syntax
Reply With Quote #6

Please help me with SELECT.
I have read tutorial, but i didn't understand...
Can someone write some example ? The query:
Code:
dbi_query(dbc, "SELECT map FROM maps LIMIT 10")
I need the result print to chat. ( client_print() )


Thanks.
krekers is offline
DotNetJunkie
Senior Member
Join Date: May 2005
Location: In front of my pc
Old 07-16-2007 , 23:22   Re: SQL syntax
Reply With Quote #7

Quote:
Originally Posted by krekers View Post
Please help me with SELECT.
I have read tutorial, but i didn't understand...
Can someone write some example ? The query:
Code:
dbi_query(dbc, "SELECT map FROM maps LIMIT 10")
I need the result print to chat. ( client_print() )


Thanks.
Do you have to use DBI? SQLx is much better.

Code:
new Handle:mapQuery = SQL_PrepareQuery(g_Database, "SELECT `map` FROM `maps` LIMIT 10;");
if( !SQL_Execute(mapQuery) )
{
SQL_FreeHandle(mapQuery);
return PLUGIN_HANDLED;
}
new numMaps = SQL_NumResults(mapQuery);
new i = 0;
if( numMaps > 0 )
{
new printstr[512];
add(printstr, sizeof(printstr)-1, "We have the following maps: ");
while( SQL_MoreResults(mapQuery) )
{
new mapName[64];
SQL_ReadResult(mapQuery, 0, mapName, sizeof(mapName)-1);
if( i >= numMaps )
{
add(printstr, sizeof(printstr)-1, " and ");
}
else
{
add(printstr, sizeof(printstr)-1, ", ");
}
add(printstr, sizeof(printstr)-1, mapName);
i++;
SQL_NextRow(mapQuery);
}
client_print(id, print_chat, printstr);
}
else
{
client_print(id, print_chat, "We have no available maps.");
}
SQL_FreeHandle(mapQuery);
return PLUGIN_HANDLED;
Not tested so I don't know if it'll work without changes.
I haven't used DBI in awhile so I can't remember off the top of my head.
__________________
DotNetJunkie is offline
Send a message via ICQ to DotNetJunkie Send a message via AIM to DotNetJunkie Send a message via MSN to DotNetJunkie Send a message via Yahoo to DotNetJunkie
krekers
Junior Member
Join Date: Jul 2007
Old 07-25-2007 , 16:10   Re: SQL syntax
Reply With Quote #8

Is there some simpler examle ? I have to learn basic and later i need to learn advanced scripting :]

I need just the query and print

Thank you anyway
krekers 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 21:35.


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