<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Atomized &#187; sql-mode</title>
	<atom:link href="http://atomized.org/tag/sql-mode/feed/" rel="self" type="application/rss+xml" />
	<link>http://atomized.org</link>
	<description>Fragmenting reality.</description>
	<lastBuildDate>Mon, 23 May 2011 23:46:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>User experience and the need to document</title>
		<link>http://atomized.org/2009/04/user-experience-and-the-need-to-document/</link>
		<comments>http://atomized.org/2009/04/user-experience-and-the-need-to-document/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 06:53:24 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[sql-mode]]></category>
		<category><![CDATA[ux]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=542</guid>
		<description><![CDATA[And the debate rages on. I basically agree with Jared, at least as far as the broken UX of sql-mode goes. If you say it’s broken, it’s broken. What I don’t understand is this: Here we have a coder, willing to investigate solutions to his problems. Reads documentation. Presumably Googles. Finds something that appears to [...]]]></description>
			<content:encoded><![CDATA[<p>And <a href="http://curiousprogrammer.wordpress.com/2009/04/18/shoddy-documentation/">the debate rages on</a>.</p>
<p>I basically agree with Jared, at least as far as the broken UX of sql-mode goes. <a href="http://sethgodin.typepad.com/seths_blog/2009/04/this-is-broken.html">If you say it’s broken, <em>it’s broken</em></a>.</p>
<p>What I don’t understand is this: Here we have a coder, willing to investigate solutions to his problems. Reads documentation. Presumably Googles. Finds something that appears to be what he wants. Tries it, and gets <em>one error message</em>. Gives up and writes his own.</p>
<p>I like to think I’m well acquainted with human laziness, but this is a species I just don’t understand. But that’s somewhat off point now.</p>
<p>So. We can agree that:</p>
<ul>
<li>The UX of sql-mode is bad.</li>
<li>Nobody has clearly explained how to use it.</li>
</ul>
<p>Given this situation, I think it’s insane to say that the correct solution is to document how to work around the bad UX. So, I’ve put my money where my mouth is and patched sql-mode to improve it’s behavior. So with this patch, SQL-mode:</p>
<ul>
<li>Has a <code>sql-change-buffer</code> function, which can set or change the <code>sql-interactive</code> buffer the sql-mode buffer will send commands to. The command has a default keybinding, and auto-completes buffer names. It only completes names of live interactive SQL buffers.</li>
<li>Has a visual indicator (in the mode-line) of which SQLi buffer the current SQL buffer is tied to.</li>
<li>If you run one of the <code>sql-send-*</code> commands, and <code>sql-buffer</code> isn’t pointing to a live SQLi buffer, you get an error which points you to <code>sql-change-buffer</code>.</li>
</ul>
<p>Here’s the patch: <a href="http://atomized.org/wp-content/uploads/2009/04/sql-change-buffer.diff">sql-change-buffer</a>, against Emacs’ CVS HEAD. It’s still a bit rough around the edges. In particular, I’m not thrilled with how <code>sql-buffer</code> is indicated in the mode-line. Contributions are welcomed.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2009/04/user-experience-and-the-need-to-document/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Central Documentation and Wasted Effort</title>
		<link>http://atomized.org/2009/04/central-documentation-and-wasted-effort/</link>
		<comments>http://atomized.org/2009/04/central-documentation-and-wasted-effort/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 22:15:13 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[sql-mode]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=536</guid>
		<description><![CDATA[Jared responds to my comment on his database-mode, defending himself by blaming a lack of centralized documentation. Now, I agree with this to a point. Documentation for third-party Emacs packages can be scattered and hard to come by. The EmacsWiki search is terrible, and shouldn’t be relied on. But in this specific case, I just [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://curiousprogrammer.wordpress.com/">Jared</a> <a href="http://curiousprogrammer.wordpress.com/2009/04/16/dangerous-elisp/">responds to</a> <a href="http://www.squidoo.com/emacs-db-mode">my comment</a> on his database-mode, defending himself by blaming a lack of centralized documentation.</p>
<p>Now, I agree with this to a point. Documentation for third-party Emacs packages can be scattered and hard to come by. The <a href="http://emacswiki.org/">EmacsWiki</a> search is <i>terrible</i>, and shouldn’t be relied on. But in this specific case, I just don’t buy it.</p>
<p>SQL-mode is built in to Emacs, and Emacs is called self-documenting for a reason. All the packages it ships with have easily accessible documentation; even a cursory search of sql-mode should have shown that the feature he wanted already existed. For the record: In a SQL buffer, accessing the major mode help (C-h m) shows this in the very first sentence of the description:</p>
<blockquote><p>You can send SQL statements to the SQLi buffer using C-c C-r.</p></blockquote>
<p>Which just goes to show that it doesn’t matter how good the documentation is when people don’t bother to read it.</p>
<p>Now, this isn’t to say that it’s pointless to reinvent the wheel. You’ve got to learn to make wheels somehow, right? But my problems with database-mode run a little deeper than this.</p>
<p>On a personal level, I find it hard to trust the code of someone who can’t RTFM. If they didn’t bother figuring out that their feature already exists, what else have they overlooked?  I admit that this is pedantic and unfair in some cases. But I feel the point has some validity: If you can’t be trusted with the small stuff, why should I trust you with the big stuff?</p>
<p>The other point I want to make is that forks like this hurt the community. The active Emacs developer community is pretty small compared to some other projects, so the available developer effort is small and precious. Spending it reimplementing features already available in vanilla Emacs seems like a waste to me.</p>
<p>Everyone has been guilty of this at some point, <a href="http://github.com/ieure/phpunit-el/tree">myself</a> <a href="http://nschum.de/src/emacs/test-case-mode/">included</a>. We owe it to ourselves and the community to do better.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2009/04/central-documentation-and-wasted-effort/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Enhancing Emacs’ SQL Mode</title>
		<link>http://atomized.org/2008/10/enhancing-emacs%e2%80%99-sql-mode/</link>
		<comments>http://atomized.org/2008/10/enhancing-emacs%e2%80%99-sql-mode/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 20:04:22 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql-mode]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=370</guid>
		<description><![CDATA[I use sql-mode a lot. It’s incredibly handy to have my abbrevs and Emacs bindings available when I’m interacting with SQL servers. But there’s always room for improvement, so I’ve identified a few areas where sql-mode could work a bit better, and fixed them. Better Buffer Naming I found this code somwhere a while back, [...]]]></description>
			<content:encoded><![CDATA[<p>I use <code>sql-mode</code> a lot. It’s incredibly handy to have my abbrevs and Emacs bindings available when I’m interacting with SQL servers. But there’s always room for improvement, so I’ve identified a few areas where <code>sql-mode</code> could work a bit better, and fixed them.</p>
<h2>Better Buffer Naming</h2>
<p>I found this code somwhere a while back, and threw in some enhancements:</p>
<ol>
<li>If <code>sql-name</code> is set, that is used in the buffer name, e.g. “*SQL sql-name*”</li>
<li>Otherwise, the name will include the hostname of <code>sql-server</code> and <code>sql-database</code>. If <code>sql-server</code> is an IP address, it’s used; if it’s a DNS name, the hostname part is used. e.g. “*SQL: dbhost/dbname*” or “*SQL 192.168.0.1/dbname”</li>
</ol>
<pre>
(defun sql-make-smart-buffer-name ()
  "Return a string that can be used to rename a SQLi buffer.

This is used to set `sql-alternate-buffer-name' within
`sql-interactive-mode'."
  (or (and (boundp 'sql-name) sql-name)
      (concat (if (not(string= "" sql-server))
                  (concat
                   (or (and (string-match "[0-9.]+" sql-server) sql-server)
                       (car (split-string sql-server "\\.")))
                   "/"))
              sql-database)))

(add-hook 'sql-interactive-mode-hook
          (lambda ()
            (setq sql-alternate-buffer-name (sql-make-smart-buffer-name))
            (sql-rename-buffer)))
</pre>
<h2>Support for TCP Ports</h2>
<p>At Digg, we have a lot of databases. As <a href="http://blog.digg.com/?p=213">you may have read</a>, we have four main pools of databases. Each of these has one write master and several slaves. We have this setup duplicated in many places for production, development, QA, and so on. While the less-stable environments don’t require the full setup, we try to balance consistency with resource usage. What we’ve settled on is one physical host running four different MySQL instance, one for each pool, each listening on a different port. Unfortunately, <code>sql-mode</code> has no support for this. You can set the <code>sql-*-options</code> variables, but this is cumbersome when you need to quickly connect to servers on different ports.</p>
<p>This simple advice will add <code>sql-port</code> into <code>sql-mysql-options</code>, if it’s set.</p>
<pre>
(defadvice sql-connect-mysql (around sql-mysql-port activate)
  "Add support for connecting to MySQL on other ports"
  (let ((sql-mysql-options (or (and (boundp 'sql-port) sql-port (cons (concat "-P " (or (and (numberp sql-port) (number-to-string sql-port)) sql-port)) sql-mysql-options)) sql-mysql-options)))
    ad-do-it))
</pre>
<p>Currently, this ony works for MySQL. It should be trivial to extend the support for other databases.</p>
<p>This doesn’t get read interactively like the other options, so you’ll have to create a new function with a let binding to connect. This isn’t such a bad thing when you throw in the next enhancement.</p>
<h2>Support for Preset Connections</h2>
<p>It’s not much fun to enter your connection information every time you want to connect. I had some functions which used let expressions to set the correct defaults for connections, but this was suboptimal, since you had to hit RET a bunch of times before the connection would start. This is fixed with preset connections. You define <code>sql-connection-alist</code> with a connection name and a list of sql variables to bind. Then you may call <code>sql-connect-preset</code> with the connection name, and you get your connection immediately.</p>
<p>Note that you can specify <code>sql-port</code> in the connection definition. Also, <code>sql-name</code> is defined to the name of the connection, so you can set the buffer name there, as well.</p>
<p>At some point in the future, it would be a good idea to make an interactive version of <code>sql-connect-preset</code>, which prompts you for one of the defined connections. For now, though, you need to define a function.</p>
<p>Example code:</p>
<pre>
(setq sql-connection-alist
      '((pool-a
         (sql-product 'mysql)
         (sql-server "1.2.3.4")
         (sql-user "me")
         (sql-password "mypassword")
         (sql-database "thedb")
         (sql-port 3306))
        (pool-b
         (sql-product 'mysql)
         (sql-server "1.2.3.4")
         (sql-user "me")
         (sql-password "mypassword")
         (sql-database "thedb")
         (sql-port 3307))))

(defun sql-connect-preset (name)
  "Connect to a predefined SQL connection listed in `sql-connection-alist'"
  (eval `(let ,(cdr (assoc name sql-connection-alist))
    (flet ((sql-get-login (&#038;rest what)))
      (sql-product-interactive sql-product)))))

(defun sql-pool-a ()
  (interactive)
  (sql-connect-preset 'pool-a))
</pre>
<p>Now, you can just run <code>sql-pool-a</code> and get connected right away. Because the buffers have good names, you can easily fire up many connections.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2008/10/enhancing-emacs%e2%80%99-sql-mode/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

