Forum > Networking and Web Programming

[SOLVED]fcl-mustache, sqlite, httpserver issue.


Having an fphttpserver simple program running on windows. When responding to root (/) request, I read data from sqlite database & render html page using fcl-mustache package.
but results looks like ugly, the fields results precedes with questions marks (ex: a field value of ABCD will looks like ????ABCD).
here is a simple code.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure route3(aReq: TRequest; AResponse: TResponse);   Function StringOrFile(S : String) : TMustacheString;  begin    With TFileStream.Create(S,fmOpenRead or fmShareDenyNone) do    try      SetLength(Result,Size);      ReadBuffer(Result[1],Size);    finally      Free;    end;  end; var  lCnt: TSQLite3Connection;  ltr: TSQLTransaction;  lDs: TSQLQuery;   lText: TMustacheString;  lTextRes: UTF8String;//TMustacheString;   lM: TMustache;  lC: TMustacheDBContext; begin  ltr := TSQLTransaction.Create(nil);   // transaction  lCnt := TSQLite3Connection.Create(nil);  // Connection  lCnt.Transaction := ltr;  lCnt.DatabaseName := 'gsystem.db';  lCnt.KeepConnection := True;  lCnt.Open();  lDs := TSQLQuery.Create(nil);   // Query  lDs.DataBase := lCnt;  lDs.SQL.Text := 'SELECT * FROM uc_system Where del=0';  lDS.Open();    lM := TMustache.Create(Nil);   try         lText := StringOrFile('app.tpl');         lC := TMustacheDBContext.Create(Nil);        lC.AddDataset(lDs, 'sysparam');         lM.Template := lText;        lTextRes := lM.Render(lC);                AResponse.ContentType := 'text/html; charset=utf-8';        AResponse.ContentEncoding := 'UTF-8';        AResponse.Content := lTextRes;        AResponse.SendContent();   finally    lM.Free;    lC.Free;    lDs.Free;    lCnt.Free;    ltr.Free;  end;end;        
The strange thing, also, is that when using a simple GUI program (not web), It works perfectly.
I think, I miss something when it comes to serve a web page.

Thank you in advence.

Finally there is no problem. there is an issue in then encoding of fields in sqlite database.
This is strange since sqlite db is cross plateform.


[0] Message Index

Go to full version