This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

deleted

Help for those learning Tcl or writing their own scripts.
Post Reply
P
Psyfire
Voice
Posts: 36
Joined: Sun Nov 05, 2006 12:32 pm

deleted

Post by Psyfire »

deleted
Last edited by Psyfire on Mon May 04, 2009 4:12 pm, edited 1 time in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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: Select all

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
P
Psyfire
Voice
Posts: 36
Joined: Sun Nov 05, 2006 12:32 pm

Post by Psyfire »

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?
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

Code: Select all

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: Select all

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
P
Psyfire
Voice
Posts: 36
Joined: Sun Nov 05, 2006 12:32 pm

Post by Psyfire »

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)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

@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
P
Psyfire
Voice
Posts: 36
Joined: Sun Nov 05, 2006 12:32 pm

ddf

Post by Psyfire »

dfdf
Last edited by Psyfire on Mon May 04, 2009 4:13 pm, edited 1 time in total.
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

You can use:

Code: Select all

string map { "\{" "" } ?var?
or

Code: Select all

string range ?var? 0 end-1
or maybe even

Code: Select all

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
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
P
Psyfire
Voice
Posts: 36
Joined: Sun Nov 05, 2006 12:32 pm

deleted

Post by Psyfire »

deleted
Last edited by Psyfire on Mon May 04, 2009 4:13 pm, edited 1 time in total.
P
Psyfire
Voice
Posts: 36
Joined: Sun Nov 05, 2006 12:32 pm

Post by Psyfire »

Nobody can help me? :-(
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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
P
Psyfire
Voice
Posts: 36
Joined: Sun Nov 05, 2006 12:32 pm

Post by Psyfire »

I dont understand that sorry, can you modify the source with my 180 minutes example?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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
Post Reply