Raised This Month: $42 Target: $400
 10% 

sql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lexzor
Senior Member
Join Date: Nov 2020
Old 02-06-2021 , 19:19   sql
Reply With Quote #1

how could i empty a sql table ?
lexzor is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-06-2021 , 20:01   Re: sql
Reply With Quote #2

DELETE FROM table
__________________

Last edited by Bugsy; 02-07-2021 at 10:53.
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-07-2021 , 06:37   Re: sql
Reply With Quote #3

I bet if you've searched for the answer you got it much faster.
__________________
@Jailbreak Main Mod v2.6.4 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
lexzor
Senior Member
Join Date: Nov 2020
Old 02-07-2021 , 10:26   Re: sql
Reply With Quote #4

i searched for it but i didn t find anything.

delete it's not what i m searching for because it will delete just 1 row, i want to empty the table because i have a sql chat logger and that table it's getting very big.

will "TRUNCATE" work ? every time when i clear the table manually from phpmyadmin it's showing me this:

You are about to TRUNCATE a complete table! Do you really want to execute "TRUNCATE `s243_csgo`.`amx_chat_log`"?
lexzor is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-07-2021 , 10:41   Re: sql
Reply With Quote #5

if your table has a column id you can use this method.

Code:
DELETE FROM `table` WHERE id > 0;
or you can use any other logic.

i'm not sure DELETE * FROM table will work for all sql versions.
__________________
@Jailbreak Main Mod v2.6.4 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Last edited by Natsheh; 02-07-2021 at 10:42.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
lexzor
Senior Member
Join Date: Nov 2020
Old 02-07-2021 , 10:42   Re: sql
Reply With Quote #6

where can i see sql version ? also, the plugin has an id

Last edited by lexzor; 02-07-2021 at 10:43.
lexzor is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-07-2021 , 10:44   Re: sql
Reply With Quote #7

Yeah that may have been my bad, I think just DELETE FROM will work. I very rarely delete records as I create a 'Deleted' bool field in most tables and set it to true when I want a record excluded from queries/reports.

Just use 'DELETE FROM table' and you can add any conditions that you need with a WHERE condition, like Natsheh suggested. This can be 'ID > 0' or 'DateEntered >= #1/1/2021#', etc.
__________________

Last edited by Bugsy; 02-07-2021 at 10:47.
Bugsy is offline
lexzor
Senior Member
Join Date: Nov 2020
Old 02-08-2021 , 10:22   Re: sql
Reply With Quote #8

PHP Code:
check()
{
    new 
iKey 150
    
new iTS
    
if(nvault_lookup(nVaultiKeyiCurrentTimesizeof(iCurrentTime), iTS) != 1)
    {
        new 
iCurrentTime get_systime() 
        
nvault_set(nVaultiKeyiCurrentTime)
    }
    else
    {
        if(
get_systime() >= (iCurrentTime get_systime(259200)))
        {
            new 
query[128]
            
formatex(querysizeof(query), "DELETE * FROM %s WHERE id > 0"table)
            
SQL_ThreadQuery(q_SqlX"QueryHandle"query)
        }
    }

is this correct ?

Last edited by lexzor; 02-08-2021 at 10:23.
lexzor is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-08-2021 , 16:31   Re: sql
Reply With Quote #9

I do not know enough and the code is wrong.

1. nVault supports strings for the key and value fields, it will not accept your iKey variable.
2. What does "iKey = 150" represent .. what does the 150 value correspond to?
3. If the key does not exist, iCurrentTime = get_systime() will never get called so the value will be 0 when used in your else condition.
4. In your else, I believe you want this: if(iTS >= (iCurrentTime + get_systime(259200)))
But I think it, and a lot of your code, can still be improved once I know better what you're doing.
5. The SQL can be changed to "DELETE FROM %s;"
__________________
Bugsy is offline
lexzor
Senior Member
Join Date: Nov 2020
Old 02-08-2021 , 16:55   Re: sql
Reply With Quote #10

this is the plugin:

PHP Code:
/*

Chat Logger SQL
Version 0.5
AUTHOR: aake ([email protected])
Website : http://naputtaja.no-ip.org

This plugin save chat message to MySQL Database

Installing the plugin:
1. Copy chat_logger_sql.amxx file to plugins folder
2. Add line chat_logger_sql.amxx to plugins.ini file
*/

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <sqlx>
#include <nvault>


#define PLUGINNAME    "Chat Logger SQL"
#define VERSION        "0.8b"
#define AUTHOR        "naputtaja"
#define table           "chat_logger"
#define MAXLEN 511
#define MAX_WORDS 150

// SQL Settings
new Handle:g_SqlX
new Handle:g_SqlConnection
new g_error[512]
new 
g_No_Save_Words[MAX_WORDS][20]
new 
g_No_Save_Num

new const TEAMNAME[_:CsTeams][] = {"(DEAD)""(Terrorist)""(Counter-Terrorist)""(Spectator)"}
new const 
nVaultName[] = "ChatLoggerEmptyTable"
new nVault


public check_sql()
{
    
    new 
host[64], user[64], pass[64], db[64], errorcodequery_create[1001]
    
    
get_cvar_string("amx_sql_host"host63)
    
get_cvar_string("amx_sql_user"user63)
    
get_cvar_string("amx_sql_pass"pass63)
    
get_cvar_string("amx_sql_db"db63)
    
    
g_SqlX SQL_MakeDbTuple(hostuserpassdb)
    
g_SqlConnection SQL_Connect(g_SqlX,errorcode,g_error,511);
    
    if (!
g_SqlConnection
    {
        
console_print(0,"Chat log SQL: Could not connect to SQL database.!")
        
log_amx("Chat log SQL: Could not connect to SQL database.")
    }
    
    
format(query_create,1000,"CREATE TABLE IF NOT EXISTS `%s`(`id` int(11) NOT NULL auto_increment,`name` varchar(100) NOT NULL default '',`authid` varchar(100) NOT NULL default '',`ip` varchar(100) NOT NULL default '',`alive` int(11) NOT NULL default '0', `team` varchar(100) NOT NULL default '',`date` date NOT NULL default '0000-00-00',`time` time NOT NULL default '00:00:00',`cmd` varchar(100) NOT NULL default '',`message` text NOT NULL,PRIMARY KEY  (`id`));",table)
    
SQL_ThreadQuery(g_SqlX,"QueryHandle",query_create)
    
    
console_print(0,"[AMXX SQL] Connected!")
    
nVault nvault_open(nVaultName)
    
    if ( 
nVault == INVALID_HANDLE)
        
set_fail_state("[CHATLOGGER] Failed to open nvault file!")
    
    return 
PLUGIN_CONTINUE 
}

check()
{
    new 
iKey 150
    
new iTS
    
if(nvault_lookup(nVaultiKeyiCurrentTimesizeof(iCurrentTime), iTS) != 1)
    {
        new 
iCurrentTime get_systime() 
        
nvault_set(nVaultiKeyiCurrentTime)
    }
    else
    {
        if(
get_systime() >= (iCurrentTime get_systime(259200)))
        {
            new 
query[128]
            
formatex(querysizeof(query), "DELETE * FROM %s WHERE id > 0"table)
            
SQL_ThreadQuery(q_SqlX"QueryHandle"query)
        }
    }
}

public 
chat_log_sql(id
{
    if(
is_user_bot(id)) return
    
    
    
    static 
datestr[11]
    new 
authid[16],name[32],ip[16],timestr[9]
    new 
cmd[9
    
    if(!
is_user_connected(id)) return    
    
    
read_argv(0,cmd,8
    
    new 
message[192
    
read_args(message,191)
    
remove_quotes(message)
    
    new 
0
    
while ( g_No_Save_Num )
    {
        if ( (
containi messageg_No_Save_Words[i++] ) != -1) || (containi message"@") != -1) ) return 
    }
    
    new 
CsTeams:team cs_get_user_team(id)
    
get_user_authid(id,authid,15)  
    
get_user_name(id,name,31)
    
get_user_ip(idip151)
    
    
get_time("%Y.%m.%d"datestr10)
    
get_time("%H:%M:%S"timestr8)
    
    new 
query[1001]
    
formatex(query,1000,"INSERT into %s (name,authid,ip,alive,team,date,time,message,cmd) values ('%s','%s','%s','%d','%s','%s','%s','%s','%s')",table,name,authid,ip,is_user_alive(id),TEAMNAME[_:team],datestr,timestr,message,cmd
    
SQL_ThreadQuery(g_SqlX,"QueryHandle",query)



public 
QueryHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
        return 
log_amx("Chat log SQL: Could not connect to SQL database.")
    
    else if(
FailState == TQUERY_QUERY_FAILED)
        return 
log_amx("Chat log SQL: Query failed")
    
    if(
Errcode)
        return 
log_amx("Chat log SQL: Error on query: %s",Error)
    
    new 
DataNum
    
while(SQL_MoreResults(Query))
    {
        
DataNum SQL_ReadResult(Query,0)
        
server_print("zomg, some data: %s",DataNum)
        
SQL_NextRow(Query)
    }
    return 
PLUGIN_CONTINUE
}

readList()
{
new 
Configsdir[64]
new 
NoSaveWords_file[64]
get_configsdirConfigsdir63 )
format(NoSaveWords_file63"%s/ChatLoggerSQL_NoSaveWords.ini"Configsdir )

if ( !
file_exists(NoSaveWords_file) )
{
    
log_amx"Chat log SQL: ChatLoggerSQL_NoSaveWords.ini  File not found" )
    
server_print "====================================================================" )
    
server_print "[Chat Logger Sql] loaded ChatLoggerSQL_NoSaveWords.ini File not found"g_No_Save_Num )
    
server_print "====================================================================" )
}


new 
leni=0
while( MAX_WORDS && read_fileNoSaveWords_fileg_No_Save_Words[g_No_Save_Num], 19len ) )
{
    
i++
    if( 
g_No_Save_Words[g_No_Save_Num][0] == ';' || len == )
        continue
        
g_No_Save_Num++
    }
    
    
i=0
    
    server_print 
"======================================================" )
    
server_print "[Chat Logger Sql] loaded %d No Save words"g_No_Save_Num )
    
server_print "======================================================" )
    
    return 
PLUGIN_CONTINUE
    
}

public 
plugin_end() 

    
SQL_FreeHandle(g_SqlConnection)
    return


public 
plugin_init()
{
    
register_plugin(PLUGINNAMEVERSIONAUTHOR)
    
register_cvar("amx_chat_logger",VERSION,FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_UNLOGGED|FCVAR_SPONLY)
    
    
register_clcmd("say""chat_log_sql")
    
register_clcmd("say_team""chat_log_sql")
    
readList()
    
set_task(0.1"check_sql")
    return 
PLUGIN_CONTINUE 
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1035\\ f0\\ fs16 \n\\ par }
*/ 
i don t know what key i should use to save that data because i know just how to save nvault using player steamid/ip/name as a key

it will this work ?

PHP Code:
new iKey[10] = "nVaultKey" 

Last edited by lexzor; 02-08-2021 at 20:54.
lexzor 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 00:56.


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