Raised This Month: $68 Target: $400
 17% 

Solved Send text to database


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
4ever16
Veteran Member
Join Date: Apr 2015
Old 05-15-2019 , 05:15   Send text to database
Reply With Quote #1

When i say .text then a text message is sent to database.
When new .text is send the the old one is deleted.

say .text "this is my message"

Last edited by 4ever16; 05-17-2019 at 05:26.
4ever16 is offline
Godofwar
AlliedModders Donor
Join Date: Dec 2015
Location: Germany
Old 05-15-2019 , 13:38   Re: Send text to database
Reply With Quote #2

u should be more exactly. I am sure, nobody understand your request.
Godofwar is offline
AmXDusT
Member
Join Date: Feb 2019
Location: Italy / Albania
Old 05-15-2019 , 13:54   Re: Send text to database
Reply With Quote #3

Hi, this should work:
Quote:
.text my message
will save "my message"
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>


#define TEXT_ACCESS ADMIN_BAN
new const host[] = ""
new const user[] = ""
new const pass[] = ""
new const db[] = ""
new const table[] = "sql_text"


#define PLUGIN "SQL Save Note"
#define VERSION "1.0"

new Handle:g_Tuple
public plugin_init(){
    
register_plugin(PLUGINVERSION"DusT")
    
register_clcmd("say""sqlSay")
}

public 
plugin_cfg(){
    
set_task(0.5"connectDb")
}

public 
sqlSay(id){
    new 
arg[6]
    
read_argv(1argcharsmax(arg))
    if(!
equali(arg".text"))
        return 
PLUGIN_CONTINUE
    
    
if(!(get_user_flags(id) & TEXT_ACCESS))
        return 
PLUGIN_HANDLED
    
new message192 ], length strlen(arg) + 1
    read_args
(messagecharsmax(message))
    
remove_quotes(message)
    
remove_quotes(message[length])
    if(!
message[length])
        return 
PLUGIN_HANDLED

    updateDb
(idmessage[length])
    
client_print(idprint_chat"* Message Saved")
    
    return 
PLUGIN_HANDLED
}

public 
connectDb(){
    
g_Tuple SQL_MakeDbTuple(hostuserpassdb)
    
    new 
query[512]
    
formatex(querycharsmax(query), "CREATE TABLE IF NOT EXISTS %s(admin VARCHAR(31) NOT NULL,admin_steamid VARCHAR(35) NOT NULL,datetime DATETIME NOT NULL,message VARCHAR(192) NOT NULL)"table)
    
SQL_ThreadQuery(g_Tuple"checkTable"query)
}
public 
checkTable(failStateHandle:query, const error[], errNum)
{
    if (
errNum)
        
set_fail_state(error)
}
public 
resetDb(){
    new 
query[128]
    
formatex(querycharsmax(query), "DELETE FROM %s"table)
    
SQL_ThreadQuery(g_Tuple"ignoreHandle"query)
}
public 
updateDb(idmessage[]){
    
resetDb()
    new 
name[32], escName[64], steamid[35], escMessage280 ]
    
get_user_name(idnamecharsmax(name))
    
SQL_QuoteString(Empty_HandleescNamecharsmax(escName), name)
    
SQL_QuoteString(Empty_HandleescMessagecharsmax(escMessage), message)
    
get_user_authid(idsteamidcharsmax(steamid))
    
    new 
query[512]
    
formatex(querycharsmax(query), "INSERT INTO %s VALUES('%s','%s',NOW(),'%s')"tableescNamesteamidescMessage)
    
SQL_ThreadQuery(g_Tuple"ignoreHandle"query)
}
public 
ignoreHandle(FailState,Handle:queryerror[], errNum)
{
    
SQL_FreeHandle(query)
    return 
PLUGIN_HANDLED


Last edited by AmXDusT; 07-13-2019 at 00:42.
AmXDusT is offline
4ever16
Veteran Member
Join Date: Apr 2015
Old 05-17-2019 , 05:26   Re: Send text to database
Reply With Quote #4

Thanks AmXDusT works perfectly!
4ever16 is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 05-17-2019 , 08:31   Re: Send text to database
Reply With Quote #5

@AmXDusT can you explain in a little details (cant find anyting specified on net) what
Code:
SQL_QuoteString
is doing? how it seems it is the function i need but im not sure if it is working well...also why 'Empty_Handle' ? Thanks in advance!
__________________
KZ Public Autocup

Private works:
KZ Melee & 1v1 Cup plugin & MapPool (like for XJ)
PrimeKZ
PrimeBAN
Checkpoin zones for KZ (& DR)
Deathrun Timer
JocAnis is offline
AmXDusT
Member
Join Date: Feb 2019
Location: Italy / Albania
Old 05-18-2019 , 22:43   Re: Send text to database
Reply With Quote #6

Quote:
Originally Posted by JocAnis View Post
@AmXDusT can you explain in a little details (cant find anyting specified on net) what
Code:
SQL_QuoteString
is doing? how it seems it is the function i need but im not sure if it is working well...also why 'Empty_Handle' ? Thanks in advance!
the empty_handle should be the SQL_Connect which I didn't do

quotestring should escape the string you're putting there to avoid having some backticks breaking your query. I'm not 100% sure tho, seen it in a few plugins and started using it as well for safety.
AmXDusT is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 05-20-2019 , 07:18   Re: Send text to database
Reply With Quote #7

@AmXDust Thanks, i still dont get why Empty_handle but only with that one im not getting errors, how it seems its working well...probably QuoteString is doing the same as replace_all, cuz it requires buffer of strlen*2 of name

i was getting duplicated rows in a table..so i thought it was a character problem but with gotten logs im sure its the problem in sqlx as stated some years ago...so if anyone else struggling: add boolen on plugin_end() and check that bool for every threaded query...also what i found while searching for this fix:
Code:
SQL_SetCharset( g_SqlTuple, "utf8" )
only for 1.8.3 (couldnt test yet to see if it is working 100% but i guess it is)
__________________
KZ Public Autocup

Private works:
KZ Melee & 1v1 Cup plugin & MapPool (like for XJ)
PrimeKZ
PrimeBAN
Checkpoin zones for KZ (& DR)
Deathrun Timer

Last edited by JocAnis; 05-20-2019 at 07:19.
JocAnis is offline
4ever16
Veteran Member
Join Date: Apr 2015
Old 05-20-2019 , 12:22   Re: Send text to database
Reply With Quote #8

JocAnis, worked for me without problem. Used amxx 1.9
4ever16 is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 05-20-2019 , 12:38   Re: Send text to database
Reply With Quote #9

ok im talking about for totally another plugin but with the same function (quotestring)...
__________________
KZ Public Autocup

Private works:
KZ Melee & 1v1 Cup plugin & MapPool (like for XJ)
PrimeKZ
PrimeBAN
Checkpoin zones for KZ (& DR)
Deathrun Timer
JocAnis is offline
Reply


Thread Tools
Display Modes

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 01:44.


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