| |
 |
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
|
|
© Copyright 2004 Tom Pierce.
|
|
|
|
| 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
|
|
Emacs Sources
tsql-indent.el
This is an indentation function for SQL mode. It was written with Transact SQL in mind.
user-add-sql-folding-marks
This is a simple function that adds folding-mode marks to SQL sources. It is quick and dirty, but is fairly useful for me.
remove-line-boundary-in-region
This function removes all the line boundaries in a region. This, in effect, collapses all the lines in the region onto one line.
convert-camel-to-underscore
This function converts all the text that is camel cased in a particular region to underscore separated text.
My Subscriptions
|
|
|