ns::stats::SQLiteHistory method historyConnect (protected)

 <instance of ns::stats::SQLiteHistory[i]> historyConnect config

Defined in

Parameters:
config (required)

Testcases:
No testcase defined.
Source code:
set db [ns_db gethandle -timeout 1 [dict get $config pool]]
if {$db eq ""} {
    error "history pool checkout timed out"
}
try {
    if {[ns_db dbtype $db] ne "sqlite"} {
        error "history requires an nsdbsqlite pool"
    }
    set path [ns_db datasource $db]
    if {$path eq "" || $path eq ":memory:" || [string match file:* $path]} {
        error "history requires a persistent file datasource"
    }
    file attributes $path -permissions 0600
    # A dedicated database avoids altering another application's budget.
    if {[::ns::stats::scalar $db {
        SELECT count(*) FROM sqlite_master WHERE type='table' AND name NOT GLOB 'ns_stats_*' AND name NOT GLOB 'sqlite_*'}]
    } {
        error "history requires a dedicated database"
    }
    foreach query {
        {PRAGMA busy_timeout=1000}
        {PRAGMA journal_mode=DELETE}
        {PRAGMA synchronous=FULL}
        {PRAGMA temp_store=MEMORY}
    } {
        ::ns::stats::sql $db $query
    }
    set page [::ns::stats::scalar $db {PRAGMA page_size}]
    set maximum [expr {int([dict get $config maxBytes]*0.45)/$page}]

    if {[::ns::stats::scalar $db {PRAGMA page_count}]>$maximum} {
        error "existing history database exceeds byte budget"
    }
    ::ns::stats::sql $db "PRAGMA max_page_count=$maximum"
    return $db
} on error {message options} {
    ns_db releasehandle $db
    return -options $options $message
}
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: