MainSource Code Downloads API Documentation Mailing Lists Bugs Developers

nsdbi - NaviServer Database Interface

  set formatted_result [dbi_rows {select first, last from people where id = :id} {
      <li>$first $last</li>

nsdbi provides a Tcl interface to an SQL database from within the naviserver web server (and, potentially from within a tclsh). It is a combination of the ideas from the original ns_db interface (available standalone as nstcl) and the higher level interface provided by openacs. Some new features include:

  • Bind Variables. The original ns_db interface had no support, and the openacs interface supports it with an extension for oracle and through emulation for postgres. A uniform syntax (:variablename) is supported for all databases. In the example above, :id is a bind variable and the value of the Tcl variable $id is passed to the database to substitute.
  • Prepared Statements. All statements are prepared when first seen and the handle is cached using the query as the key. This is transparent to the Tcl programmer.
  • Handle Management. A pool of handles is maintained, shared among all threads/interps. Handles are retrieved from the pool when needed and returned after each command. In the above example, the default handle is being used. The -db name option may be used to specify some other handle.
  • High Performance. The code operates reasonably quickly: in the example above, no Tcl objects are allocated at runtime. The query and template are parsed once and cached. The formatted result is assembled by appending the bytes directly into the result buffer.

See the documentation[L1 ] for more.

Drivers are available for:



Source Code:

    $ hg clone https://bitbucket.org/naviserver/nsdbi/


See Also: