Smalltalk FFI 调用 OpenDBX 中的 unicode 字符

发布于 2024-10-20 07:38:04 字数 684 浏览 8 评论 0 原文

我需要将一些包含非 ASCII 字符的字符串插入数据库(Postgress)。这是最小的例子。我在 上收到“无法强制参数”。据我了解,这是一个 FFI 错误,调用甚至没有到达数据库后端,但我不确定。

| conn settings sql |
settings :=     DBXConnectionSettings
                host: 'host.com'
                port: '5432'
                database: 'grss'
                userName: 'username'
                userPassword: 'password'.
conn := DBXConnection platform: DBXPostgresPlatform new settings: settings.
conn connectAndOpen.
sql := 'select ''', (WideString fromPacked: 269), ''' from dual'.
conn execute: sql.
conn close.
conn disconnect.

I need to insert some strings containing non ASCII characters into the database (Postgress). Here is the minimal example. I get the "Could not coerce arguments" on <cdecl: long 'odbx_query' (ulong char* ulong) module: 'opendbx'>. From what I understand it is a FFI error and the call didn't even make it to the database backend, but I'm not sure.

| conn settings sql |
settings :=     DBXConnectionSettings
                host: 'host.com'
                port: '5432'
                database: 'grss'
                userName: 'username'
                userPassword: 'password'.
conn := DBXConnection platform: DBXPostgresPlatform new settings: settings.
conn connectAndOpen.
sql := 'select ''', (WideString fromPacked: 269), ''' from dual'.
conn execute: sql.
conn close.
conn disconnect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

只是偏爱你 2024-10-27 07:38:04

我想我也有同样的问题。人们应该使用与服务器相同的编码对数据进行编码。目前,您应该能够通过以下方式指定编码:

settings :=     DBXConnectionSettings
                host: 'host.com'
                port: '5432'
                database: 'grss'
                userName: 'username'
                userPassword: 'password';
                encodingStrategy: (DBXStaticEncoding newForEncoding: #utf8).

如果编码未知,可以使用 DBXAutomaticEncoding 而不是 DBXStaticEncoding。
这应该适用于 postgresql 数据库。

I think I had the same problem. One should encode data using same encoding than the server. Currently you should be able to specify encoding in following way:

settings :=     DBXConnectionSettings
                host: 'host.com'
                port: '5432'
                database: 'grss'
                userName: 'username'
                userPassword: 'password';
                encodingStrategy: (DBXStaticEncoding newForEncoding: #utf8).

If encoding is not known one could use DBXAutomaticEncoding instead of DBXStaticEncoding.
This should work on postgresql database.

つ低調成傷 2024-10-27 07:38:04

问题似乎出在 WideString 上。看来 FFI 无法从 WideString 实例转换为 C char*

您可以使用普通的 ByteString 而不是 Wide 吗?也许可以修复 FFI 以便它能够做到这一点?

THe problem seems to be the WideString. It seems that FFI cannot convert from WideString instances to C char*

Can you use normal ByteString instead of the wide? maybe FFI could be fixed so that it can do it?

梦巷 2024-10-27 07:38:04

我仍然不知道如何回答 stackoverflow 上的某人。不管怎样,Panu 所说的应该可行:

settings :=     DBXConnectionSettings
                host: 'host.com'
                port: '5432'
                database: 'grss'
                userName: 'username'
                userPassword: 'password';
                encodingStrategy: (DBXStaticEncoding newForEncoding: #utf8).

不需要直接使用 UTF8TextConverter。这就是使用 SqueakDBX 的方法。它与 GlorpDBX 无关,它只是普通的 SqueakDBX。如果最新的ConfigurationOfSqueakDBX没有更新,只需使用Monticello Browser更新到最新版本即可。

I still don't know how to answer to someone here in stackoverflow. Anyway, what Panu says should work:

settings :=     DBXConnectionSettings
                host: 'host.com'
                port: '5432'
                database: 'grss'
                userName: 'username'
                userPassword: 'password';
                encodingStrategy: (DBXStaticEncoding newForEncoding: #utf8).

without needing to needing to direclty use UTF8TextConverter. That's the way to do it with SqueakDBX. And it has nothing to do with GlorpDBX, it is just plain SqueakDBX. If the latest ConfigurationOfSqueakDBX is not updated, just update to the latest versions using Monticello Browser.

若水般的淡然安静女子 2024-10-27 07:38:04

FFI 的 char* 想要一个 ByteString。也许postgres可以直接使用UTF-8?如果是这样,您只需说squeakToUtf8即可。

FFI's char* wants a ByteString. Maybe postgres can use UTF-8 directly? If so, you just would have to say squeakToUtf8.

一抹微笑 2024-10-27 07:38:04

通过使用

UTF8TextConverter >> 修复ConvertToSystemString

UTF8TextConverter>>从系统字符串转换

Fixed by using

UTF8TextConverter >> convertToSystemString

and

UTF8TextConverter >> convertFromSystemString

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文