0

how can i show the output to each other? At the moment everything is in a row

bind pub "-|-" !sql pub:test:sql
proc pub:test:sql{ nick host handle channel arg } {

set name "%test%"

sqlite3 pre test.db
set result [pre eval {SELECT * FROM pre WHERE rlsname LIKE $name}]
if {$result == ""} {
putnow "PRIVMSG $channel :empty"
} else {
putnow "PRIVMSG #test :result $result"
set id [lindex [split $result] 0]
set outname [lindex [split $result] 1]
set time [lindex [split $result] 2]
putnow "PRIVMSG #test :$outname $time"
}
}

at the moment the result looks like this :

[09.02.20/21:00:43:243] <testbot> result 4 1.test.1 1581256802 160 2.test.2 1581262727
[09.02.20/21:00:43:243] <testbot> output 1.test.1 1581256802

and this is how it should look, among each other :

[09.02.20/21:00:43:243] <testbot> result 4 1.test.1 1581256802
[09.02.20/21:00:43:243] <testbot> result 160 2.test.2 1581262727

Thank you very much for your help Regards

Shawn
  • 47,241
  • 3
  • 26
  • 60
user385411
  • 71
  • 1
  • 5
  • What's the structure of the pre table? how many rows are selected? – glenn jackman Feb 09 '20 at 23:40
  • Why not use [`lassign`](https://www.tcl.tk/man/tcl8.6/TclCmd/lassign.htm) instead of all those repeated `set`/`lindex`/`split` lines? – Shawn Feb 10 '20 at 00:45
  • For `foreach` with multiple variables to accept the elements from that `select`? Though the answer below is generally better for that as it works _with_ the DB engine instead. – Donal Fellows Feb 10 '20 at 02:00
  • @Jerry Actually a bad idea, since each line has to be prefixed when dealing with IRC, as it ultimately uses a line-oriented protocol. – Donal Fellows Feb 11 '20 at 06:24

1 Answers1

2

If you wish to process the selected rows one row at a time, one option is to use optional arguments to the eval command to specify a variable name and script. In that form of the eval command, each row is assigned to the variable as an array and the script is executed. In your case:

per eval {select * from PER ...} per_result {
    puts "$per_result(somecolumn1) $per_result(somecolumn2)"
}

or something like that where the array indices are column names.

See the eval manual page for more details and examples.

andy mango
  • 1,526
  • 1
  • 8
  • 13