egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

deleted

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Psyfire
Voice


Joined: 05 Nov 2006
Posts: 36

PostPosted: Thu Mar 29, 2007 9:51 pm    Post subject: deleted Reply with quote

deleted

Last edited by Psyfire on Mon May 04, 2009 4:12 pm; edited 1 time in total
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Fri Mar 30, 2007 10:59 am    Post subject: Reply with quote

If you're using mysql, you could use the "SELECT .... INTO newtable" construct.

As for your second query, it seems you're having alittle trouble keeping track of variable-spaces. That is, you're just inserting the string 'player_id' into the player_id field, rather than the value from the first query.
Mysql does support session-variables where you can store and use values/variables directly on the server although this can be abit tricky until you've fully learned the mechanics of it. Other than that, you would have to extract the value from the result of the first query, store it in a tcl-variable, and insert it into your second query-string.

Ex:
Code:
set data [mysqlsel $handle "SELECT (data1) FROM my-db WHERE id = 1" -flatlist]
mysqlsel $handle "INSERT INTO my-other-db (foobar, data) VALUES ('foobar', '[lindex $data 0]')" -flatlist]

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Psyfire
Voice


Joined: 05 Nov 2006
Posts: 36

PostPosted: Fri Mar 30, 2007 12:50 pm    Post subject: Reply with quote

Hello,

I use mysql yes, also I tried what you said, but I cant get it work. Can you please help me with my code, to add your example in it?
Back to top
View user's profile Send private message
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Fri Mar 30, 2007 12:51 pm    Post subject: Reply with quote

Code:
mysqlsel $sql(handle) "INSERT INTO amx_banhistory(bhid,player_ip,player_id,player_nick,admin_ip,admin_id,admin_nick,ban_type,ban_reason,ban_created,ban_length,server_ip,server_name,unban_created,unban_reason,unban_admin_nick) VALUES('bhid','0.0.0.0','player_id','player_nick','$host','admin_id','$nick','ban_type','$unban_unban_reason','$unban_ban_time','ban_length','$chan','IRC','$unban_unban_created','$unban_unban_reason','$nick');"
               mysqlclose $sql(handle)


... all i can say here is, your not actually adding anything you selected.

just because you selected 'player_id' it doesn't mean you can use 'player_id' in the insert. All the select'd data is stored in the 'sma(qry)' variable, and if im correct, your using mysqltcl, and i think you need to use mysqlget/mysqlgetquery <id>, of which you get the id from the sma(qry) variable.

I also see that you add all the data from the amx_bans history is inserted in the same order into the amx_banhistory db with 3 extra bits of data.

You can try something like this:



Code:

set sma(qry) [mysqlsel $sql(handle) "SELECT bid,player_ip,player_id,player_nick,admin_ip,admin_id,admin_nick,ban_type,ban_reason,ban_created,ban_length,server_ip,server_name FROM amx_bans WHERE player_id = '$arg' OR bid = '$arg'" -list]
if {$sma(qry) == ""} {
    putserv "NOTICE $nick :No matches for '$arg'..."
    return
}
mysqlsel $sql(handle) "INSERT INTO amx_banhistory (bid,player_ip,player_id,player_nick,admin_ip,admin_id,admin_nick,ban_type,ban_reason,ban_created,ban_length,server_ip,server_name,unban_created,unban_reason,unban_admin_nick) VALUES('[lindex [split $sma(qry)] 0]' , '[lindex [split $sma(qry)] 1]' , '[lindex [split $sma(qry)] 2]' , '[lindex [split $sma(qry)] 3]' , '[lindex [split $sma(qry)] 4]' , '[lindex [split $sma(qry)] 5]' , '[lindex [split $sma(qry)] 6]' , '[lindex [split $sma(qry)] 7]' , '[lindex [split $sma(qry)] 8]' , '[lindex [split $sma(qry)] 9]' , '[lindex [split $sma(qry)] 10]' , '[lindex [split $sma(qry)] 11]' , '[lindex [split $sma(qry)] 12]' , '$unban_unban_created' , '$unban_unban_reason' , '$nick')"
mysqlclose $sql(handle)
putserv "NOTICE $nick :Done."   


That code is not tested, so i can't say if it will work or not, but its a base for you to work on...
_________________
r0t3n @ #r0t3n @ Quakenet
Back to top
View user's profile Send private message MSN Messenger
Psyfire
Voice


Joined: 05 Nov 2006
Posts: 36

PostPosted: Fri Mar 30, 2007 1:08 pm    Post subject: Reply with quote

It inserted all right, expect from when I add a new ban and want to insert it again with this command he says:

Tcl error [ban:db:unban]: mysqlsel: handle already closed (dangling pointer)
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Fri Mar 30, 2007 1:40 pm    Post subject: Reply with quote

@Tosser^^:
No need to split as mysqlsel is called with the -list (or -flatlist) option. Should already return a proper list

@Psyfire:
If you wish to use the "SELECT .... INTO newtable" construct, you must make sure your query exactly matches the structure of the new table; ie, if newtable has two integer fields, your select must return exactly two integers per result.
Ex:
newtable has fields: char(64) nick, char(64) ban, timestamp created, int valid
oldtable has fields: int id, timestamp creat, char(64) nickname, char(64) banmask
As I recall, a proper query would then be:
"SELECT (nickname, banmask, creat,1) FROM oldtable WHERE id = 21 INSERT INTO newtable"

Checking the manual at mysql.com might be a good idea.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Psyfire
Voice


Joined: 05 Nov 2006
Posts: 36

PostPosted: Sun Apr 01, 2007 4:21 pm    Post subject: ddf Reply with quote

dfdf

Last edited by Psyfire on Mon May 04, 2009 4:13 pm; edited 1 time in total
Back to top
View user's profile Send private message
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Mon Apr 02, 2007 4:34 am    Post subject: Reply with quote

You can use:

Code:
string map { "\{" "" } ?var?

or
Code:
string range ?var? 0 end-1

or maybe even
Code:
string trimright ?var? }


All of those should cancel out the }, the middle one (string range) will always trim 1 off the end of the string, so it might not be the best solution...
_________________
r0t3n @ #r0t3n @ Quakenet
Back to top
View user's profile Send private message MSN Messenger
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Mon Apr 02, 2007 7:58 pm    Post subject: Reply with quote

How to write eggdrop scripts that won't choke on special characters
_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
Psyfire
Voice


Joined: 05 Nov 2006
Posts: 36

PostPosted: Mon Apr 16, 2007 6:03 pm    Post subject: deleted Reply with quote

deleted

Last edited by Psyfire on Mon May 04, 2009 4:13 pm; edited 1 time in total
Back to top
View user's profile Send private message
Psyfire
Voice


Joined: 05 Nov 2006
Posts: 36

PostPosted: Wed Apr 18, 2007 12:12 pm    Post subject: Reply with quote

Nobody can help me? Sad
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Apr 18, 2007 12:29 pm    Post subject: Reply with quote

Validate that the bantime is a number, and then do a simple conditional to test wether it is less than your threshold. If not, set it to the threshold value.

You might wish to check the string command for testing for types. Also, you really should'nt use lindex or lrange on a plain string (arg) like you do, split it into a list first...
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Psyfire
Voice


Joined: 05 Nov 2006
Posts: 36

PostPosted: Wed Apr 18, 2007 4:31 pm    Post subject: Reply with quote

I dont understand that sorry, can you modify the source with my 180 minutes example?
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Fri Apr 20, 2007 2:02 pm    Post subject: Reply with quote

Checking the manual-page for string shows there is a function for testing a strings type, "string is <type>", which will, amogn others, allow you to check wether a string is an integer (number) or not.
Testing wether a number is greater than another number is trivial. If not, the manpage for if should provide enough information to sort that out.

If you just want someone to write it for you, rather than getting help on how to do it yourself, considder posting under Script Requests.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber