title: How do I create an Emacs SQL buffer?
body: <p>I can connect manually by doing:</p>
  
  <p>M-x sql-postgres</p>
  
  <p>and type the User, Database, Host, Server</p>
  
  <p>I'd like to do something like:</p>
  
  <p>(connect-foo (user "me")(database "bar")(host "earth"))</p>
  
  <p>Solution so far:</p>
  
  <p>I grabbed some code from sql.el and changed it so I can use it non-interactively.</p>
  
  <pre><code>(defun sql-create-buffer (profile)
    "derived from sql-product-interactive in sql.el which is"
    "covered by GNU General Public License version 3."
  
    (setq sql-user     (cdr (assoc 'user profile))
          sql-password (cdr (assoc 'password profile))
          sql-server   (cdr (assoc 'server profile))
          sql-database (cdr (assoc 'database profile)))
    (setq product 'postgres) ;;(cdr (assoc 'product profile)))
    (when (sql-product-feature :sqli-connect product)
      (if (comint-check-proc "*SQL*")
      (pop-to-buffer "*SQL*")
        ;; Connect to database.
        (message "Login...")
        (funcall (sql-product-feature :sqli-connect product))
        ;; Set SQLi mode.
        (setq sql-interactive-product product)
        (setq sql-buffer (current-buffer))
        (sql-interactive-mode)
        ;; All done.
        (message "Login...done")
        (pop-to-buffer sql-buffer))))
  
  (setq bar-profile '(
        (product  . "postgres")
        (user     . "me")
        (password . "")
        (server   . "earth")
        (database . "bar")))
  </code></pre>
  
  <p>I don't know what to do with the 'product' parameter, so I left it hard coded for now.
  It is 'postgres in sql.el.</p>
  
  <pre><code>(sql-create-buffer bar-profile)
  </code></pre>