But sometimes I want to give more context or write the code as a story, or a question-answer dialogue. In those occasions, org-babel is the way to go.
This piece of elisp enables a bunch of languages to be evaluated in org file blocks:
(org-babel-do-load-languages 'org-babel-load-languages '((ditaa . t) (tcl . t) (ruby . t) (sqlite . t) (clojure . t) (lisp . t) (http . t) (sql . t)))
Now, in the org file itself, place this kind of block:
#+BEGIN_SRC sqlite :db pieces-and-providers.sqlite #+END_SRC
Now, when pressing c-c c-c inside a block, a new block called RESULTS will be created underneath with the result of the eval'ed block.
There are many other options on exporting org-blocks and other options for fine tunning how results are shown, or formatted. For me, this is a nice way to have my experiments documented, or leave exercises for my future me to solve. For example, I copied most of the sql exercises wikibook and created this repo with the stories/exercises as org files so I can try them in an interactive way.