Recent

Author Topic: Codepage WIN1251  (Read 10056 times)

samsuser

  • New Member
  • *
  • Posts: 17
Codepage WIN1251
« on: April 12, 2011, 11:45:51 pm »
Hi

I have delphi project working with Interbase tables with  collate WIN1251 .
I convert  it to Lazarus .
When i open my Interbase tables with components SQLdb from Lazarus ,
I can not read the contents of fields table because they are distorted
We'll see garbled characters
how to solve the problem?

many thanks


PS

 The exact same problem when opening a DBF  spreadsheet with the coding DOS 866. ( dBASE RUS cp866)


« Last Edit: April 12, 2011, 11:47:34 pm by samsuser »

bobo

  • Full Member
  • ***
  • Posts: 171
Re: Codepage WIN1251
« Reply #1 on: April 13, 2011, 04:08:32 am »
Lazarus works only with UTF-8 strings, so all components expect that.
I do not know about the SQLDB components coming with Lazarus, but if you use ZEOS instead, you can set the client code page to UTF-8 and see your DB data properly in Lazarus programs.
You can put a "codepage=UTF8" in the ZConnection.Properties to accomplish this.

I use the following for MySQL:
Code: [Select]
...
      SQLConnection.Properties.Text :=
        'character_set_client=utf8'#13#10+
        'character_set_connection=utf8'#13#10+
        'character_set_database=utf8'#13#10+
        'character_set_results=utf8'#13#10+
        'character_set_server=utf8'#13#10+
        'character_set_system=utf8'#13#10+
        'collation_connection=utf8_general_ci'#13#10+
        'collation_database=utf8_general_ci'#13#10+
        'collation_server=utf8_general_ci'#13#10+
        'Codepage=utf8';
...
and both reading and writing are ok , even with non UTF-8 databases.
It can be different for your database though...

samsuser

  • New Member
  • *
  • Posts: 17
Re: Codepage WIN1251
« Reply #2 on: April 14, 2011, 07:19:53 am »

Sorry,  could you do a little example ?

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: Codepage WIN1251
« Reply #3 on: April 14, 2011, 04:47:47 pm »
These properties affect the connection in general. Then when you do SELECT, INSERT etc. you will get data in the UTF8 format.
Conscience is the debugger of the mind

samsuser

  • New Member
  • *
  • Posts: 17
Re: Codepage WIN1251
« Reply #4 on: April 20, 2011, 07:06:06 am »
Lazarus works only with UTF-8 strings, so all components expect that.
I do not know about the SQLDB components coming with Lazarus, but if you use ZEOS instead, you can set the client code page to UTF-8 and see your DB data properly in Lazarus programs.
You can put a "codepage=UTF8" in the ZConnection.Properties to accomplish this.

I use the following for MySQL:
Code: [Select]
...
      SQLConnection.Properties.Text :=
        'character_set_client=utf8'#13#10+
        'character_set_connection=utf8'#13#10+
        'character_set_database=utf8'#13#10+
        'character_set_results=utf8'#13#10+
        'character_set_server=utf8'#13#10+
        'character_set_system=utf8'#13#10+
        'collation_connection=utf8_general_ci'#13#10+
        'collation_database=utf8_general_ci'#13#10+
        'collation_server=utf8_general_ci'#13#10+
        'Codepage=utf8';
...
and both reading and writing are ok , even with non UTF-8 databases.
It can be different for your database though...

 How about UIB  component ?
 Where use thise code ?

bobo

  • Full Member
  • ***
  • Posts: 171
Re: Codepage WIN1251
« Reply #5 on: April 20, 2011, 07:45:16 am »
Codepage=utf8

should work with IB too. The Zeos "TZConnection" component (SQLConnection above in the code snippet) has - among others - a "Protocol" property where you can set the database connection type. "mysql-5" or "interbase-6" or "firebird-2.5", etc.
The best if you test it first with a simple example application.

samsuser

  • New Member
  • *
  • Posts: 17
Re: Codepage WIN1251
« Reply #6 on: April 21, 2011, 01:26:32 am »

 

TinyPortal © 2005-2018