// ! Support file only, run TreeUTF8Store.html instead ! //. This file is used as both data url and SaveUrl //. Generates data for FastGrid by get() function or saves received changes to database by set() function //. Uses UTF8Store object from UTF8Store.js to create FastGrid JSON data with UTF8Store format // ----------------------------------------------------------------------------------------------------------------------------- //. Reads data from database and returns them in JSON function get(req,res){ var sql = require('better-sqlite3'), db = new sql('SQLite.db'); //. It uses SQLite3 database engine on database in file SQLite.sb var UTF8Store = require("./UTF8Store.js"); try { var rows = db.prepare("SELECT * FROM TreeData ORDER BY (SELECT TRIM(pid || ' ' || id))").all(); } //. Selects the whole table and calls the process function with the results catch(e){ err("SQL select error: "+e.message,res); return; } var s = "FGrid.Data={"; s += "Cfg:{IgnoreDVOnU:1},"; //. Ignores default V defined in default rows for rows with U attribute s += "Body_Cfg:{Par:'P'},"; //. Assigns the defined par "P" for all rows in Body. The Body definition is now one strings, where every row consists of 11 characters (id = 3 chars, L = 1 char, U = 7 chars) s += "Body:\""; var F = "\",Foot:["; var Ids = [], Products = []; Names = []; Amounts = [], Prices = [], Discounts = [], Shippings = []; var uid = UTF8Store.AddToUCode(0xE4,1), uD = UTF8Store.GetUCode(1,0,0,1,9), uE = UTF8Store.GetUCode(2,0,2,100), uI = UTF8Store.AddToUCode(0x4,new Date(2005,7,1)); for(var i=0;i summary of ucode sizes: [A] 1 char + [C] 1 char + [D] 1 char + [E] 2 chars + [G+H] 1 char, [I] 1 char s += "]}}"; end(s,res); } // ----------------------------------------------------------------------------------------------------------------------------- //. Saves changed data in JSON to database function set(req,res){ var qstr = require('querystring'), body = ""; req.on('data',function(data){ body += data.toString(); }); req.on('end', function(){ var D = qstr.parse(body).Data; if(!D) { err("Empty request",res); return; } D = JSON.parse(D); if(!D ||!D.ChangedRows) { err("Request without ChangedRows",res); return; } D = D.ChangedRows; for(var di=0,S=[];di