Search code examples
tcleggdrop

Split MySQL by new line


I have in my tcl script a mysql select qry, and this is vertical. There are about 30 issues from the query with 3-6 letters. I want to split it after 80 characters to a new line

set sql_network "SELECT `grp` FROM `name` WHERE `network` LIKE '$network'"
set result_network [mysqlsel $db_handle $sql_network -list]
putquick "PRIVMSG $channel :Results: \002$result_network\002"

I have this tested, but it does not work. I suspect it refers to the individual short words

set length [::textutil::adjust $result_network -length 80 -strictlength true]

Solution

  • The textutil::adjust command returns the adjusted text. You need to do a bit more work before sending it out:

    set LINE_LENGTH 80
    
    set sql_network "SELECT `grp` FROM `name` WHERE `network` LIKE '$network'"
    set result_network [mysqlsel $db_handle $sql_network -list]
    
    set text [::textutil::adjust $result_network -length $LINE_LENGTH -strictlength true]
    foreach line [split $text "\n"] {
        putquick "PRIVMSG $channel :Results: \002$line\002"
    }