#1 2018-09-09 10:45:36

poirot
Member
Registered: 2018-09-09
Posts: 2

How to view string field in a dbgrid

Hi everyone, I'am new with mormot. I want to know what should i do to view string field in a dbgrid?
Below is my coding:

FPropsPostgreSQL:= TSQLDBZEOSConnectionProperties.Create
    (TSQLDBZEOSConnectionProperties.URI (dPostgreSQL, '192.168.0.1:5432'),
     'mydatabase', 'user', 'password');

ds01.DataSet.Free;   

ds01.DataSet:= ToDataSet (ds01,
    FPropsPostgreSQL.Execute ('select * from mytable', []));

The record is shown but all string fields is showing with chinese character...
Am I missing something?

Thank you in advanced.

Offline

#2 2018-09-09 11:34:15

poirot
Member
Registered: 2018-09-09
Posts: 2

Re: How to view string field in a dbgrid

Sorry, i just found the solution from other post:

var
  s: RawUTF8;
  sResultJSON: UTF8String;

  mystmt: TSQLDBStatement;
  myTable: TSQLTable;

FPropsPostgreSQL:= TSQLDBZEOSConnectionProperties.Create
    (TSQLDBZEOSConnectionProperties.URI (dMySQL, '192.168.0.1:3306'),
     'mydatabase', 'user', 'password');

ds01.DataSet.Free;

s:= 'select * from mytable';

try
  FPropsPostgreSQL.ThreadingMode:= tmMainConnection;
  FPropsPostgreSQL.MainConnection.Connect;

  try
    mystmt:= FPropsPostgreSQL.NewThreadSafeStatement;
    mystmt.Prepare (s, True);
    mystmt.ExecutePrepared;
    sResultJSON:= mystmt.FetchAllAsJSON (True);
  finally
    mystmt.Free;
  end;

  myTable:= TSQLTableJSON.Create ('', sResultJSON);
  ds01.DataSet:= TSynSQLTableDataSet.Create (Self, myTable);
finally

end;

But i am still curious, is there any faster method of doing this?


Thank you.

Offline

Board footer

Powered by FluxBB