Chinese Word Probllems

There is a field ~ "CodeTypNM" VARCHAR(30) ~ in a table ~ SysCode
i want to insert a value '機型名稱與序號b對應表' into the field "CodeTypNM"
if i format a "insert" sql command ~ it's work
but if i want to use the follwing code to insert the
with sysCode do
begin
...
CodeTypNM := '機型名稱與序號b對應表';
....
end;
dm.aureliusManager.Save(sysCode);

the value in "CodeTypNM" will be '機型名稱與'
Can anyone tell why ? TKS

Hello @user55, welcome to TMS Support Center!

Which database component are you using to save the data? Have you tried to perform a raw insert SQL statement using that component? Which code did you use?

Which database component are you using to save the data?

  1. [Entity]
    [Table('SysCode')]
    [Id('FCodeType', TIdGenerator.None)]
    [Id('FCodeInx', TIdGenerator.None)]
    [Id('FCodeNo', TIdGenerator.None)]
    TSysCode = class....
  2. var sysCode := TSysCode.Create;
  3. i use " aureliusManager.Save(sysCode);" ~ the value in "CodeTypNM" will be '機型名稱與'
    the data has been cutted

Have you tried to perform a raw insert SQL statement using that component?
if i wirite a raw insert SQL statement, it works fine

My question is: what component have you configured to save data? FireDAC? UniDAC? The native MSSQL driver (if you are using Microsoft SQL Server)?

And how did you tried to perform a raw insert SQL? In a database admin tool? From Delphi? If from Delphi, which code did you use to execute the raw SQL?

what component have you configured to save data? FireDAC? UniDAC? The native MSSQL driver (if you are using Microsoft SQL Server)?

And how did you tried to perform a raw insert SQL? In a database admin tool? From Delphi? If from Delphi, which code did you use to execute the raw SQL?

  1. i perform a raw insert SQL using Delphi
  2. using the following code
    Connection := ADOConnection;
    SQL.Clear;
    SQL.Add(GenSysCodeKindSQL(MachNameMapTob,'機型名稱與序號b對應表'))
    ExecSQL;

function GenSysCodeKindSQL(CodeType,CodeTypNM:string): string;
begin
Result := Concat('INSERT INTO SysCode (CodeType,CodeTypNM,CodeInx,CodeNo,CodeNM,CodeDesc,NotShow,CreateDate,CreateUser,UpdateDate,UpdateUser)',
' VALUES(''' + CodeType + ''',''' + CodeTypNM + ''',0,''*'','''','''',''False'',GetDate(),''cova'',Null,'''') ');
end;

I kindly ask you that you refactor your test to use parameters, instead of setting the field content directly into the SQL statement.
My guess is that ADOQuery is cropping the parameter. Try to set the parameter type as ftString or ftWideString, set the value using the Value property and see the behavior, please.

Sorry ~ i do not understand what you mean ?

Create and execute the SQL using parameters:

INSERT INTO SysCode (CodeType,CodeTypNM,CodeInx,CodeNo,CodeNM,CodeDesc,NotShow,CreateDate,CreateUser,UpdateDate,UpdateUser)
VALUES(:p1, :p2, :p3, :p4) ;

And set them using ParamByName:

Query.ParamByName('p2').DataType := ftString;
Query.ParamByName('p2').Value := '機型名稱與序號b對應表';

and also:

Query.ParamByName('p2').DataType := ftWideString;
Query.ParamByName('p2').Value := '機型名稱與序號b對應表';

And please let us know what happens.

i use the following code test insert data
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text := 'INSERT INTO SysCode (CodeType,CodeTypNM,CodeInx,CodeNo) ' +
'VALUES(:p1, :p2, :p3, :p4) ';
ADOQuery1.Parameters.ParamByName('p1').Value := '1';
ADOQuery1.Parameters.ParamByName('p2').DataType := ftString;
ADOQuery1.Parameters.ParamByName('p2').Value:= '機型名稱與序號b對應表';
ADOQuery1.Parameters.ParamByName('p3').Value := '0';
ADOQuery1.Parameters.ParamByName('p4').Value := '*';
ADOQuery1.ExecSQL;

    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Text := 'INSERT INTO SysCode (CodeType,CodeTypNM,CodeInx,CodeNo) ' +
    'VALUES(:p1, :p2, :p3, :p4) ';
    ADOQuery1.Parameters.ParamByName('p1').Value := '2';
    ADOQuery1.Parameters.ParamByName('p2').DataType := ftWideString;
    ADOQuery1.Parameters.ParamByName('p2').Value:= '機型名稱與序號b對應表';
    ADOQuery1.Parameters.ParamByName('p3').Value := '0';
    ADOQuery1.Parameters.ParamByName('p4').Value := '*';
    ADOQuery1.ExecSQL;

two records added and the values in table is OK

Well, that's pretty much what Aurelius does when using ADO, in unit Aurelius.Drivers.dbGo.
You can try to check it yourself, putting a breakpoint in line 148:

      Parameter.DataType := P.ParamType;
      if P.ParamType = ftDateTime then
        Parameter.ParameterObject.Type_ := adDBTimeStamp;
      Parameter.Value := P.ParamValue;
      Parameter.Direction := pdInput;
      if (Parameter.DataType in [ftString, ftFixedChar, ftWideString, ftFixedWideChar]) and (Parameter.Size <= 0) then
        Parameter.Size := 1;

And check the values there (P.ParamType and P.ParamValue). Other than this, we should check and debug to better see what's going on. If after debugging you can't find out what's going on (if maybe it's some configuration in ADO, or database), please send us a minimal project and steps to reproduce the issue, so we can check it at our side. Thank you.

i have send some information to you by mail
please check it
TKS

We didn't receive it. I suggest you send us a private message via this forum, it's more guaranteed that we received (and you can track it) instead of an e-mail.

To send a private message, just click my name and click the button "Message":

image

Please download "TMS.rar" and extract it.

then you will find the delphi project file and "SysCode.sql'

  1. Create a db named "TESTDB"

  2. using SysCode.sql to create the Table "SysCode'

  3. run the project

Well, you are not creating the database field as Unicode, nor asking Aurelius to use Unicode. In this case, it will not work indeed.

Easier way is to do this at the beginning of your application:

uses
  Aurelius.Global.Config;

TGlobalConfigs.GetInstance.MapStringToNationalChar := True;

Problems solved !
TKS

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.