#include "demo_guard.h" RENDER(Request& context) { if(!test_demo_request_allowed(context)) { test_demo_render_restricted_html(context, "SQLite demo", "write to a server-side SQLite database"); return; } String db_path = "/tmp/uce-demo-sqlite.sqlite"; SQLite* db = sqlite_connect(db_path); sqlite_query(db, "create table if not exists notes(id integer primary key autoincrement, body text not null, created_at text not null)"); if(context.params["REQUEST_METHOD"] == "POST" && trim(context.post["body"]) != "") { StringMap params; params["body"] = trim(context.post["body"]); params["created_at"] = time_format_utc("%Y-%m-%d %H:%M:%S"); sqlite_query(db, "insert into notes(body, created_at) values(:body, :created_at)", params); sqlite_disconnect(db); redirect("sqlite.uce", 303); return; } DValue notes = sqlite_query(db, "select id, body, created_at from notes order by id desc limit 10"); String error = sqlite_error(db); ?>

UCE Demo / SQLite

This demo stores rows in with runtime SQLite helpers and named prepared parameters.

#