Sunday 15 June 2014

Unable to insert Unicode into SQL Server 2008 using Delphi ZeosLib and Delphi 7 -


I'm having difficulty in integrating Unicode into a SQL Server database using Delphi Zioslib and Delphi 7, and Then read the insert value. I have created a simple test program that inserts first and then asks the inserted value.

Test table schema:

  create table [dbo]. [Original] [basic]   

I downloaded the simple test program source (Including ZeosLib source) to download for uploading [incoming logs] [nvarchar] (500) NULL) is. I have also included ntwdblib.dll but you can use your own.

The examination program also requires a TNT component which can be downloaded from

. Using the test program, Unicode characters, I have appeared in the form of question marks on recovery - I am not sure whether the problem is with the insert code or the query code.

I have tried to encode the data before inserting it and then decoding the data after getting it from utf-8 - please search the "inserted as // // utf" in the test program source . I am able to see Unicode after decoding, so this method works, however, for my actual application, I can not convert it as UTF-8 because SQL Server is completely UTF-8 Does not support - Some characters can not be archived. See my previous questions.

Any indication will appreciate. :)

Meanwhile, the source of the test program is here:

  unit unit 1; The interface uses ZConnection, Windows, Messaging, SysUtils, Variants, Classes, Graphics, Controlls, Forms, Dialogs, ZAbostrotetsets, Jeborbysdatasets, ZsetTable, Zetsetset, Stedecetrils, TNTSTCTLL; Type TForm1 = Square (TForm) Button 1: Tibbon; TntMemo1: TTNTMMO; Button 2: Tibbon; TntEdit1: TTntEdit; Click Process Button 1 (Sender: Tubect); Process Button2Click (Sender: Tubect); Private {Private Announcement} public {public declaration} end; Var Form 1: Teform 1; FZ Connection: TZConnection; FZQuery: TZQuery; Implementation {$ R *. Dfm} Process TForm1.Button1Click (Sender: Tubbed); Start tntmemo1.Lines.Clear; FZConnection: = TZConnection.Create (owner); FZConnection.LoginPrompt: = Incorrect; FZQuery: = TZQuery.Create (Owner); FZ Connection: = FZConnection; FZConnection.Protocol: = 'mssql'; FZConnection.Database: = 'Replace-your-db'; FZConnection.HostName: = 'localhost'; FZConnection.User: = 'sa'; FZConnection.Password: = 'Replace with your password'; FZConnection.Connect; FZQuery.SQL.Text: = 'Select from Encloid Log'; FZQuery.ExecSQL; FZQuery.Open; FZQuery.First; While FZQuery.EOF do not start tntmemo1.Lines.add (FZQuery.FieldByName ('Message'). AsString); // tntmemo1.Lines.add (utf8decode (FZQuery.FieldByName ('Message'). AsString)); // FZQuery.ext; inserted as utf8; End; End; Process TForm1.Button2lick (Sender: Tubbed); Var sqlstring, data: width; Start FZConnection: = TZConnection.Create (Owner); FZConnection.LoginPrompt: = Incorrect; FZQuery: = TZQuery.Create (Owner); FZ Connection: = FZConnection; FZConnection.Protocol: = 'mssql'; FZConnection.Database: = 'Replace-your-db'; FZConnection.HostName: = 'localhost'; FZConnection.User: = 'sa'; FZConnection.Password: = 'Replace with your password'; FZConnection.Connect; Data: = tntedit1.Text; // data: = utf8encode (tntedit1.Text); // utf8 added as sqlstring: = 'Include in INOMINGLog ([message]) value (N' '+ + + + Data +' '') '; FZQuery.SQL.Text: = sqlstring; FZQuery.ExecSQL; End; End.    

I have not tested your example, but I have to save and retrieve Without the problem on the SQL Server database without the Unicode characters Delphi 7 VCL / CLX and zeoslib.

I think that in your case, this will adequately change your process like this:

  Process TForm1.Button2lick (Sender: Tubect); Var sqlstring: width; Data: UTF 8 string; Start FZConnection: = TZConnection.Create (Owner); FZConnection.LoginPrompt: = Incorrect; FZQuery: = TZQuery.Create (Owner); FZ Connection: = FZConnection; FZConnection.Protocol: = 'mssql'; FZConnection.Database: = 'Replace-your-db'; FZConnection.HostName: = 'localhost'; FZConnection.User: = 'sa'; FZConnection.Password: = 'Replace with your password'; FZConnection.Connect; Data: = UTF8 string (utf8encode (tntedit1.Text)); Sqlstring: = Include in 'INOMINGLOG ([message]) value (: data)'; FZQuery.SQL.Text: = sqlstring; FZQuery.ParamByName ('DATA'). AsString: = Data; FZQuery.ExecSQL; End;   

The point is changing your data string variable in UTF8String type, and passes the data string to the query using the parameters ... Honestly I used it with ZTable and Post commands. But it should be like ZQuery like you ...

No comments:

Post a Comment