Raised This Month: $32 Target: $400
 8% 

SQL Query is not working.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NC.svtrade
Senior Member
Join Date: Nov 2015
Old 11-30-2019 , 16:53   SQL Query is not working.
Reply With Quote #1

Create Table
PHP Code:
Format(buffersizeof(buffer), "CREATE TABLE IF NOT EXISTS sql_matches (");
    
Format(buffersizeof(buffer), "%s match_id bigint(20) NOT NULL,"buffer);
    
Format(buffersizeof(buffer), "%s name varchar(65) NOT NULL,"buffer);
    
Format(buffersizeof(buffer), "%s uid bigint(20) NOT NULL,"buffer);
    
Format(buffersizeof(buffer), "%s team int(11) NOT NULL,"buffer);
    
Format(buffersizeof(buffer), "%s kills int(11) NOT NULL,"buffer);
    
Format(buffersizeof(buffer), "%s assists int(11) NOT NULL,"buffer);
    
Format(buffersizeof(buffer), "%s deaths int(11) NOT NULL,"buffer);
    
Format(buffersizeof(buffer), "%s dmg int(11) NOT NULL,"buffer);
    
Format(buffersizeof(buffer), "%s adr float(8) NOT NULL,"buffer);
    
Format(buffersizeof(buffer), "%s rws float(8) NOT NULL,"buffer);
    
Format(buffersizeof(buffer), "%s rating float(8) NOT NULL);"buffer); 
Query
PHP Code:
SQL_EscapeString(dbPlayerName[i], PlayerName[i], sizeof(PlayerName[]));

Format(buffersizeof(buffer), "INSERT INTO sql_matches");
Format(buffersizeof(buffer), "%s (match_id, uid, name, team, kills, assists, deaths, dmg, adr, rws, rating)"buffer);
Format(buffersizeof(buffer), "%s VALUES (LAST_INSERT_ID(), '%i', '%s', '%i', '%i', '%i', '%i', '%i', '%f', '%f', '%f');"bufferPlayerUID[i], PlayerName[i], PlayerTeam[i], GetTotalSum(PlayerKillsiRounds),
GetTotalSum(PlayerAssistsiRounds), 
GetTotalSum(PlayerDeathsiRounds), 
GetTotalSum(PlayerDamageiRounds), PlayerADR[i], PlayerRWS[i], PlayerRating[i]);
SQL_AddQuery(txnbuffer); 
I tested with logs and I confirmed that plugin arrives on query section.
NC.svtrade is offline
Balimbanana
Member
Join Date: Jan 2017
Old 11-30-2019 , 18:35   Re: SQL Query is not working.
Reply With Quote #2

Are you sure the buffer string is large enough for all those values?
You can also see if the database looks correct with SQLite tools: https://www.sqlite.org/2019/sqlite-t...86-3300100.zip
Then you use
Code:
.open "path/to/sourcemod-local.sq3"
and you can use SQL queries as normal and you can list the tables in the database with
Code:
.tables
and you can see what schema structure it has with
Code:
.schema tablename
So you can see if all the values are correctly there.

It might be a bit more messy, but you *can* create a table in SourceMod on one line with something like in this case:
Code:
SQL_FastQuery(Handle_Database,"CREATE TABLE IF NOT EXISTS sql_matches(match_id bigint(20) NOT NULL,name varchar(65) NOT NULL,uid bigint(20) NOT NULL,team int(11) NOT NULL,kills int(11) NOT NULL,assists int(11) NOT NULL,deaths int(11) NOT NULL,dmg int(11) NOT NULL,adr float(8) NOT NULL,rws float(8) NOT NULL,rating float(8) NOT NULL);");
It would ensure that no buffer clamp is happening.
Also, after all the SQL_AddQuery's is there an ending:
Code:
void SQL_ExecuteTransaction(Handle db, Transaction txn, SQLTxnSuccess onSuccess, SQLTxnFailure onError, any data, DBPriority priority)
Because the SQL_AddQuery will only keep adding to the transaction table but not send it.
If so, then does SQL_GetError return anything afterwards?
Balimbanana is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 12-01-2019 , 01:39   Re: SQL Query is not working.
Reply With Quote #3

Increase the size of buffer to something like 512

Also, you need to be escaping the player names or else people can write to your database
headline 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 19:48.


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