Verwenden polnischer Zeichen in einer Dbf-Datei mit DBServer

Deutschsprachiges X#-Forum – German language forum

Moderator: wriedmann

User avatar
pemo18
Posts: 81
Joined: Fri Apr 27, 2018 10:38 am
Location: Germany

Verwenden polnischer Zeichen in einer Dbf-Datei mit DBServer

Post by pemo18 »

Hallo Zusammen,

Unsere Dbf-Datei, die per DBServer angesprochen wird, soll auch polnische Zeichen richtig speichern.

Aktuell wird aus einem Čapek leider ein Capek.

Leider kenne ich mich in der xBase-Welt zu wenig aus, um beurteilen zu können, ob dies eine prinzipielle Einschränkung ist, ob es an der Dbf-Datei liegt, oder ob die DBServer Klasse eine Property bietet (habe in der Doku nichts gefunden).

Laut

https://dbf-software.com/dbf-file-encoding

lässt sich das Encoding setzen. Die Frage wäre, wie es mit DBServer geht.

Bei RDD gibt es die DbfHeader Klasse mit einer Codepage Property. Darüber ließe sich die Codepage setzen. Mir fehlt im Moment allerdings der Zusammenhang zur DBServer Klasse.

Wenn jemand einen Tipp oder das Problem vielleicht sogar gelöst hat, würde ich mich über einen Hinweis freuen.

Danke und viele Grüße,

Peter
User avatar
Chris
Posts: 4910
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Verwenden polnischer Zeichen in einer Dbf-Datei mit DBServer

Post by Chris »

Hi Peter,

What is the SetAnsi() setting that you are using? And is the System Locale in your windows system settings set to Polish? If it is an OEM dbf, then it might be related to a similar problem we found recently and will be fixed in the next X# release (soon), so please give it a try again then.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
pemo18
Posts: 81
Joined: Fri Apr 27, 2018 10:38 am
Location: Germany

Re: Verwenden polnischer Zeichen in einer Dbf-Datei mit DBServer

Post by pemo18 »

Hello Chris,

I didn't know about SetAnsi(). It returns just True.

What I want is that a name with polish characters that is written into the dbf with FieldPut can be read again with FieldGet like

oTest:FIELDPUT("Name","Anton Čapek")

and later

var name := oTest:FIELDGET("Name")
? name

This outputs only "Anton Capek"

I have created the dbf file through the Ole Db provider.

Changing the system setting is not an option. It works with SQL Server etc. but not with the addresses in our dbf file.

Thank you and kind regards,
Peter
User avatar
Chris
Posts: 4910
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Verwenden polnischer Zeichen in einer Dbf-Datei mit DBServer

Post by Chris »

Hi Peter,

Just to understand if that's what's causing the problem, what's the setting for the System Locale in windows?
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Verwenden polnischer Zeichen in einer Dbf-Datei mit DBServer

Post by robert »

Peter,
DBF files can contain only characters from the codepage that is in the DBF header.
That codepage is at (zero based) byte 29 in the DBF header.
You can find the meaning of the values in the following file:
https://github.com/X-Sharp/XSharpPublic ... /Enums.prg
If this byte is not 0x64 (Dos Eastern European) or 0xc8 (Windows Eastern European) then the value will be translated when writing.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
pemo18
Posts: 81
Joined: Fri Apr 27, 2018 10:38 am
Location: Germany

Re: Verwenden polnischer Zeichen in einer Dbf-Datei mit DBServer

Post by pemo18 »

Hello,

The codepage is, depending on who you ask, either 1031, 850 or 1252 (all on the same computer with different kind of queries). But its a "standard German setting".

So, would setting the codepage in the dbf header be an option?

I have tried the following sample code but it looks like it "destroys" the header:

Local dbPfad := Path.Combine(Environment.CurrentDirectory, "Polchars.dbf") As String
var dbInfo := DbOpenInfo{dbPfad, "", 0, False, False}
var dbfFile := Dbf{}
dbfFile:Open(dbInfo)
var header := DbfHeader{dbfFile}
? header:CodePage
header:CodePage := DbfHeaderCodepage.CP_DBF_WIN_EEUROPEAN
header:Write()
dbfFile:Close()

Kind regards,
Peter
User avatar
pemo18
Posts: 81
Joined: Fri Apr 27, 2018 10:38 am
Location: Germany

Re: Verwenden polnischer Zeichen in einer Dbf-Datei mit DBServer

Post by pemo18 »

After trying several things with a hex editor and codepages like cp1250 and utf8 (and even used Python because it has a very good dbf module) I finally gave up.

Its looks like its not possible to save the character Č in a dbf file. And even it if were possible other characters like the umlaute would have to be saved correctly too.

Kind regards,
Peter
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Verwenden polnischer Zeichen in einer Dbf-Datei mit DBServer

Post by wriedmann »

Hi Peter,
unfortunately a DBF file has only 8 bit characters, and most eastern European languages need own character sets to display these characters.
So, if you need to store these characters to a DBF file, you have to use the correct character set for the needed language, and of course you will loose the ability to store characters that are not covered in the selected character set.
I don't know if there are any plans to make DBFs unicode aware, but I think this will be a major work. But this is something only Robert can say.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Verwenden polnischer Zeichen in einer Dbf-Datei mit DBServer

Post by robert »

Guys,

The Windows codepage 1250 has most eastern european characters and umlaut characters:
https://en.wikipedia.org/wiki/Windows-1250
If your DBF has the codepage byte 0xc8 then you should have no problem saving these characters.
I am not sure how you are checking if this succeeded, but if you're using the console window, then please make sure that the console also has the correct codepage.
You can set the codepage with the OutputEncoding property of the console class.

W.r.t. to Unicode in DBFs. We actually support that <g>.
If you create a DBF with the fieldtype "C:U" then we create character fields that can store unicode characters. The 'U' gets encoded in the flags field of the DbfField class. This flags field is also used to mark a field as AutoIncrement ("I:+") and several other properties.

A field declared as "C:U",8,0 will hold 8 bytes (4 unicode characters).
Please note that you should not do this for fields that are included in an index. We have not tested that yet and it will most likely not work.


Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
pemo18
Posts: 81
Joined: Fri Apr 27, 2018 10:38 am
Location: Germany

Re: Verwenden polnischer Zeichen in einer Dbf-Datei mit DBServer

Post by pemo18 »

Hello Robert,

>>If you create a DBF with the fieldtype "C:U" ...

How can this be done in code?

Can you share some of your infinite wisdom with us because the help file does not contain any example for DBServer (or I have overlooked it).

Right now I using plain SQL and the OLEDB provider to create the dbf file (for testing purposes):

var conString := i"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={dbPath};Extended Properties=dBase IV"
var dbCon := OleDbConnection{conString}
dbCon:Open()
// fieldtype "C:U"?
var sqlCommand := "Create Table Polchars (Name char(50), Adresse char(50), Info char(50))"
var dbCommand := OleDbCommand{sqlCommand, dbCon}
dbCommand:ExecuteNonQuery()

I would have to use the DBServer and the DBField class instead?

The name field should contain Unicode (like NVarchar for SQL Server).

And I could not set the encoding byte in the dbf header through code but only with a hex editor.

Kind regards,

Peter
Post Reply