Structured Query Language (or SQL, pronounced "Sequel") accesses RDBMS instances.
In principle, one uses the same SQL to interrogate and update Oracle, PostgreSQL, SQLite, etc. ... databases.
In practice however ... :(
I think SQL queries should look structured but tools like Microsoft Query make it very hard to read. So I wanted a program that I could cut and paste from the tool and as it pasted it would structure it, e.g. convert
SELECT ORDERS.ORDERNUMBER, ORDERS.CUSTNUM, ORDERITEM.AMOUNT, PART.TYPE, PART.MODEL, PART.PRICE FROM VTHOMAS.ORDERITEM ORDERITEM, VTHOMAS.ORDERS ORDERS, VTHOMAS.PART PART WHERE ORDERS.ORDERNUMBER = ORDERITEM.ORDERNUM AND PART.PARTNUM = ORDERITEM.PARTNUM
into
SELECT ORDERS.ORDERNUMBER , ORDERS.CUSTNUM , ORDERITEM.AMOUNT , PART.TYPE , PART.MODEL , PART.PRICE FROM VTHOMAS.ORDERITEM ORDERITEM , VTHOMAS.ORDERS ORDERS , VTHOMAS.PART PART WHERE ORDERS.ORDERNUMBER = ORDERITEM.ORDERNUM and PART.PARTNUM = ORDERITEM.PARTNUM
so here it is in Tcl
package require Tk proc my_textPaste w { $w delete 1.0 end set txt [::tk::GetSelection $w CLIPBOARD] regsub -all {,} $txt "\n ," txt regsub -nocase -all {\sand\s} $txt "\n and " txt $w insert 1.0 $txt } text .t -width 80 -height 40 pack .t bind . <<Paste>> {my_textPaste %W; break}
A testament to the power of the text widget. Let me see, that many lines in Java? I'd still be putting a stream together. - Vincent Thomas
Anyone have a good function built to escape user defined variables for inclusion in SQL statements? If so, why not put it here.
MG mainly accesses MySQL from PHP, and often uses the addslashes() function for escaping data for MySQL queries. So, here it is, extremely simply, in Tcl:
proc addslashes {str} { return [string map [list \" "\\\"" \' "\\\'" "\\" "\\\\" "\00" "\\\00"] $str]; };# addslashes % addslashes {This "is" MG's test string} This \"is\" MG\'s test string