Emacs : Information and code concerning Emacs
Updated: 2/2/2004; 2:41:43 PM.

 

Subscribe to "Emacs" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Friday, January 09, 2004

Within the last six months, I've started using DBVisualizer (http://www.minq.se/products/dbvis/) for accessing databases while I'm coding.  It's a great front end for any relational database that has a JDBC driver.  I highly recommend it.

One of the many cool features is that result sets in the product are displayed in a grid (JTable).  You can select values in the grid and copy them to the clipboard to paste in other applications.  I frequently paste the data into Emacs for use in Java unit tests.

The problem is that the columns of text are not in an array format.  So, I wrote the following Emacs functions to "fix the data up".  After you paste the data into Emacs you can immediately run one of the interactive fix-up functions.  (One of the thousands of beautiful things about Emacs is that it automatically sets the region around the pasted text.)  This will remove the column header and produce a comma delimited list of terms suitable for use in an array.

(defun fixup-dbviz-array (start end replace-string)
"Formats the region for use as an array and replaces the regexp match
with the specified replacement string."

  (unwind-protect
      (progn
        (narrow-to-region start end)
        (goto-char (point-min))
        (kill-line 't)

        (while (re-search-forward "\\(.*?\\)\n" nil t)
          (replace-match replace-string))          
        

        (if (re-search-backward "," nil t)
            (delete-char 1)))
                
    (widen)))

(defun fixup-dbviz-string-array (start end)
"Formats a column of values that are copy and pasted from DB
Visualizer and formats them for use as a String array"
  (interactive "r")
 
  (fixup-dbviz-array start end "\"\1", "))

(defun fixup-dbviz-int-array (start end)
"Formats a column of values that are copy and pasted from DB
Visualizer and formats them for use as a int array"
  (interactive "r")

  (fixup-dbviz-array start end "\\1, "))



12:38:09 PM    comment []

© Copyright 2004 Tom Pierce.



Click here to visit the Radio UserLand website.

 


January 2004
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Oct   Feb

Search

 
How this works

Emacs Sources
 tsql-indent.el
 user-add-sql-folding-marks
 remove-line-boundary-in-region
 convert-camel-to-underscore

My Subscriptions
 Funny
 KM