SQLite and cyrillic in filepath lazarus / 16-Databases ---------------------------------------------------------------------- wizbowes · 2014-10-27 00:21 I have a user of an application who has an issue.  The application creates a database in the app data of the user.  The path is found something like this: Code: [Select]DBConnection.DatabaseName := GetEnvironmentVariable('appdata') + '\MyPath\MyDatabase.db'; However it throws an error 'DBConnection: Unable to open database file' Upon some investigation the user is Russian and therefore there are Cyrillic letters in the file path returned above.  I'm guessing that SQLite doesn't like cyrillic in the file path.  I can't find anything on Google about this.  Is there an alternative I can use - I really don't want to move the database location. Any ideas gratefully received. ---------------------------------------------------------------------- engkin · 2014-10-27 03:32 My guess: DBConnection.DatabaseName needs UTF8 string. You did not mention your Lazarus/FPC version. On the trunk, GetEnvironmentVariable has two variations: Code: [Select] Function GetEnvironmentVariable(Const EnvVar : AnsiString) : AnsiString;   Function GetEnvironmentVariable(Const EnvVar : UnicodeString) : UnicodeString; I would suggest using the second one and converting the result to UTF8 using UTF16ToUTF8 from LazUTF8. If your Laz/FPC version does not include the second function and you don't want to update, you can use GetEnvironmentStringsW and parse the result yourself. ---------------------------------------------------------------------- minesadorada · 2014-10-27 06:07 In the FileUtil unit is GetAppConfigDirUTF8 which might be a more elegant solution than using the Environment Var http://lazarus- ccr.sourceforge.net/docs/lcl/fileutil/getappconfigdirutf8.html ---------------------------------------------------------------------- Zoran · 2014-10-27 10:53 Quote from: minesadorada on October 27, 2014, 07:07:30 amIn the FileUtil unit is GetAppConfigDirUTF8 which might be a more elegant solution than using the Environment Var http://lazarus- ccr.sourceforge.net/docs/lcl/fileutil/getappconfigdirutf8.html Yes, I agree, it is the proper way, as described here: http://wiki.fre epascal.org/Multiplatform_Programming_Guide#Configuration_files Only, as minesdorada says, instead of GetAppConfigDir and GetAppConfigFile, you should use the UTF8 versions of these functions, defined in LCL's FileUtil unit: GetAppConfigDirUTF8 and GetAppConfigFileUTF8. ---------------------------------------------------------------------- minesadorada · 2014-10-27 12:35 The DatabaseName property also might need the UTF8ToSys() function (also in fileutil) in order to cope with the result of GetAppConfigDirUTF8 depending on whether it is UTF8-aware. ---------------------------------------------------------------------- Zoran · 2014-10-27 16:40 Quote from: minesadorada on October 27, 2014, 01:35:31 pmThe DatabaseName property also might need the UTF8ToSys() function (also in fileutil) in order to cope with the result of GetAppConfigDirUTF8 depending on whether it is UTF8-aware. Hm... Then UTF8 from GetAppConfigDirUTF8 would be neutralized, wouldn't it? ---------------------------------------------------------------------- minesadorada · 2014-10-27 16:48 The original problem was an error. GetAppConfigDirUTF8 gets the UTF8 correct string = No error If an error is thrown because the DB code is not UTF8 enabled, then UTF8ToSys localizes it to the system default = No error I was trying to think ahead.. ---------------------------------------------------------------------- wizbowes · 2014-10-27 20:39 Thanks all - will give that a whirl.  I really hate unicode.