Class ::nsmcp::SQLiteDatabase

::nsmcp::SQLiteDatabase[i] create ... \
           [ -maxBytes:integer (default "1073741824") ] \
           [ -path path ] \
           [ -pool:required pool:required ]

Defined in /usr/local/ns/tcl/nsmcp/lib/database.tcl

Class Relations

  • class: ::nx::Class[i]
  • superclass: ::nx::Object[i]
::nx::Class create ::nsmcp::SQLiteDatabase \
     -superclass ::nx::Object

Methods (to be applied on instances)

  • connect (scripted, public)

     <instance of nsmcp::SQLiteDatabase[i]> connect

    Testcases:
    No testcase defined.
    if {![llength [info commands ns_db]]} {error "databasePool requires nsdb/nsdbsqlite loaded before nsmcp"}
    set handle [ns_db gethandle -timeout 2 ${:pool}]
    if {$handle eq ""} {error "MCP database pool timed out"}
    try {
        if {[ns_db dbtype $handle] ne "sqlite"} {error "MCP databasePool must use nsdbsqlite"}
        set source [ns_db datasource $handle]
        if {$source eq "" || $source eq ":memory:" || [string match file:* $source]} {error "MCP cache requires a persistent file datasource"}
        set :path [file normalize $source]
        file attributes ${:path} -permissions 0600
        set db [::nsmcp::DatabaseSession new -handle $handle]
    } on error {message options} {
        ns_db releasehandle $handle
        return -options $options $message
    }
    try {
        $db execute {PRAGMA busy_timeout=2000; PRAGMA journal_mode=DELETE; PRAGMA synchronous=FULL; PRAGMA temp_store=MEMORY}
        set pages [expr {int(${:maxBytes}*0.45)/[$db scalar {PRAGMA page_size}]}]
        set current [$db scalar {PRAGMA page_count}]
        if {$current>$pages} {error "existing database exceeds configured byte budget"}
        $db execute "PRAGMA max_page_count=$pages"
        return $db
    } on error {message options} {
        $db close
        return -options $options $message
    }
  • path (scripted, public)

     <instance of nsmcp::SQLiteDatabase[i]> path

    Testcases:
    No testcase defined.
    return ${:path}