REBOL [ Title: "Name block to select list" Purpose: {Given a block of blocks, with each sub-block containing one word, convert that block of block to a string that is the 'select" statement for all those words.} ] ;; [---------------------------------------------------------------------------] ;; [ This is a function for a very specific situation. ] ;; [ This SQL command: ] ;; [ select ] ;; [ COLUMN_NAME ] ;; [ from information_schema.columns ] ;; [ where (TABLE_NAME = 'xxxxxxxx') -- xxxxxxx is a table name ] ;; [ order by ORDINAL_POSITION, COLUMN_NAME ] ;; [ will produce a result set that is a block of blocks, and each sub-block ] ;; [ will have one item which will be a column name from the table, list this: ] ;; [ [ [colname-1] [colname-2] ... [colname-n] ] ] ;; [ This function will take that result set and turn it into an SQL ] ;; [ "select" statment like this: ] ;; [ select ] ;; [ colname-1 ] ;; [ ,colname-2 ] ;; [ ,... ] ;; [ ,colname-n ] ;; [---------------------------------------------------------------------------] NAMEBLOCK-TO-SELECTLIST: func [ RESULTSET /local SELECTSTRING ] [ SELECTSTRING: copy "" append SELECTSTRING rejoin ["select " newline] foreach SUBBLOCK RESULTSET [ append SELECTSTRING rejoin ["," "[" first SUBBLOCK "]" newline] ] replace SELECTSTRING "," "" ;; replace just the first comma return SELECTSTRING ] ;;Uncomment to test ;TESTRESULTSET: [ ; [COL-1] ; [COL-2] ; [COL-3] ; [COL-4] ; [COL-5] ;] ;TESTSTRING: NAMEBLOCK-TO-SELECTLIST TESTRESULTSET ;probe TESTSTRING ;halt