2011/5/12 Jeff Rogers <dv...@diphi.com>:
> It may be a common situation, but that doesn't mean it is well-defined.  In
> your example below, what would "querygetarray" do when the counts of the
> keys are not the same?  Would it generate blank entries for those, drop the
> keys without enough values, or refuse to process it (possibly by raising an
> error)?

I'm sure that raising error for invalid data is the only true way.

> A fuller specification of what the function does would be helpful.  Does
> this function exist for other frameworks?  Maybe seeing the docs of those
> would help explain things.

 For OpenACS there is some similar functionality but I don't know
about other frameworks.

> Otherwise, this seems like a function specific to using jquery; perhaps it
> would go better in a jquery support library.

AOL has enough functions for HTTP support and I use only this single
additional proc for forms
(as standalone HTTP forms as jQuery AJAX queries) data parsing. For
javascript applications
is needed server-side JSON generator, but input data can be handled as
common HTTP forms.

P.S. With Tcl 8.5 is easy to build AJAX server on AOL platform, as example:

proc returnjson {args} {
    ns_return 200 "text/plain; charset=utf-8" [::json::object_escape {*}$args]
}

proc ad_add {table} {
    if {[catch {
        json_add $table
    } msg]} {
        ns_log Error $::errorInfo
        returnjsonerror $msg
    }
}

# insert a set of new records into database
# and return after the added records from database
# "db" is SQLite3 handler for this connection
proc json_add {table} {
    ns_setexpires 0

    set newid ""
    # use nested catch for errors in SQLite db transaction method
    db transaction {
    if {[catch {
        foreach row [ns_querygetarray] {
            lappend newid [table_insert_row $table $row]
        }
    } msg]} {
        ns_log Error $::errorInfo
        returnjsonerror $msg
        error
    }
    }
    set rid [table_record $table $newid]
    set out [table_json $table $rid]
    returnjsonobject code {"ok"} counter [llength $out] $table \[[join $out ,]\]
}

# add handlers for some tables
foreach table ... {
    ns_register_proc -noinherit POST /json/$table/add/ ad_add $table
}

P.P.S. I use SQLite becouse I need fast full-text realtime search for
all data in database
and SQLite FTS4 extension with snowball stemmers is fine for me.

Single SQLite3 connection handler for each thread is good and fast
solution. As example:
ns_ictl trace create {
    package require sqlite3
...
    sqlite3 db /tmp/test.db
    db timeout 10000
...
}

-- 
Best regards, Alexey Pechnikov.
http://pechnikov.tel/


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to 
<lists...@listserv.aol.com> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: 
field of your email blank.

Reply via email to