Hi,
I'm having a rather urgent problem that I cannot figure out.
I have the following code in the rest server:
procedure EuroFincoCustomersGet(Request: TWebRequest; Response: TWebResponse; Module: TWebModule; PathDb: string);
var
StringWriter: TStringWriter;
Writer: TJsonTextWriter;
begin
Try
(Module as TWebModuleWaveDesk).QRead.Close;
if Request.QueryFields.Values['email'] = ''
then (Module as TWebModuleWaveDesk).QRead.SQL.Text := 'Select id, last_name, first_name, email from crm_contacts where removed=''0'''
else (Module as TWebModuleWaveDesk).QRead.SQL.Text := 'Select id, last_name, first_name, email from cmr_contacts where removed=''0'' and ' +
'email like ' + QuotedStr('%' + Request.QueryFields.Values['email'] + '%');
(Module as TWebModuleWaveDesk).DbService.Disconnect;
(Module as TWebModuleWaveDesk).DbService.ConnectString :=
'Data Source=127.0.0.1;Database=' + PathDb + ';User ID=SYSDBA;Password=Zandstraat11;' +
'Client Library=fbclient.dll;Character Set=UTF8;Use Unicode=True;Login Prompt=False;Pooling=True';
(Module as TWebModuleWaveDesk).DbService.Options.EnableMemos := True;
(Module as TWebModuleWaveDesk).DbService.Connect;
(Module as TWebModuleWaveDesk).QRead.Open;
if (Module as TWebModuleWaveDesk).QRead.Active
then begin
if (Module as TWebModuleWaveDesk).QRead.RecordCount > 0
then begin
StringWriter := TStringWriter.Create;
Writer := TJsonTextWriter.Create(StringWriter);
try
Writer.Formatting := TJSonFormatting.Indented;
Writer.WriteStartObject;
Writer.WritePropertyName('Crm_contacts');
Writer.WriteStartArray;
(Module as TWebModuleWaveDesk).QRead.First;
while (not (Module as TWebModuleWaveDesk).QRead.Eof)
do begin
Writer.WriteStartObject;
Writer.WritePropertyName('id');
Writer.WriteValue((Module as TWebModuleWaveDesk).QRead.FieldByName('Id').AsInteger);
Writer.WritePropertyName('last_name');
Writer.WriteValue((Module as TWebModuleWaveDesk).QRead.FieldByName('Last_name').AsString);
Writer.WritePropertyName('first_name');
Writer.WriteValue((Module as TWebModuleWaveDesk).QRead.FieldByName('First_name').AsString);
Writer.WritePropertyName('email');
Writer.WriteValue((Module as TWebModuleWaveDesk).QRead.Fieldbyname('Email').asString);
Writer.WriteEndObject;
(Module as TWebModuleWaveDesk).QRead.Next;
end;
Writer.WriteEndArray;
Writer.WriteEndObject;
finally
Response.ContentType := 'application/json';
Response.StatusCode := 200;
Response.Content := StringWriter.ToString;
Writer.Free;
StringWriter.Free;
end;
end
else begin
Response.ContentType := 'application/json';
Response.StatusCode := 204;
Response.Content := '';
end;
end;
Finally
(Module as TWebModuleWaveDesk).QRead.Close;
(Module as TWebModuleWaveDesk).DbService.Disconnect;
End;
end;
When using this code, I get a lot of funny symbols in the output and an error in the restsponse component with the message 'Error while trying to execute the request the following error occurred: REST request failed: No mapping for the Unicode character exists in the target multi-byte code page'.
This is sample output in the browser:
{
"id": 5576,
"last_name": "Grulois ",
"first_name": "G�rald",
"email": "[email protected]"
},
Then I tried changing the connectionstring with excluding Use Unicode.
This greatly reduces the funny characters in the output but not completely, I only have 3 left on 6436 records.
This is the content of one of the records.
Value in the plain text editor of IbExpert: SCHRÖDER FRANK AG SA
Value in the Unicode editor of IbExpert: SCHRÖDER FRANK AG SA
The fields are defined as archer(30) with charset UTF8 en collate UNICODE_CI.
Can somebody help me with this?
I need to get an idea how I can solve this correctly.
Thank you,
Bernaert Dominique
Problem streaming data from rest server to client
Re: Problem streaming data from rest server to client
Hello,
Please provide more information on the issue. We need a small sample project demonstrating the incorrect behavior, including the scripts for creating and filling the database objects. Please send them to us through the form: https://devart.com/company/contactform.html
wbr, Oleg
Devart Team
Please provide more information on the issue. We need a small sample project demonstrating the incorrect behavior, including the scripts for creating and filling the database objects. Please send them to us through the form: https://devart.com/company/contactform.html
wbr, Oleg
Devart Team