简体   繁体   English

修剪字符字段

[英]Trim Char fields

We are currently using Delphi with Borland database.我们目前正在使用 Delphi 和 Borland 数据库。 We are planning to move from borland to Firebird libraries, (borland lib has mem leaks).我们计划从 borland 迁移到 Firebird 库,(borland lib 有内存泄漏)。

The problem that we are having now is, Firebird library returns a char with trailing spaces, which was somehow handled borland library.我们现在遇到的问题是,Firebird 库返回一个带有尾随空格的字符,这是 borland 库以某种方式处理的。 We have huge code written without any trimming.我们编写了大量代码,无需任何修整。

So now if 'abc' is stored in char(10) field, it returns 'abc '.所以现在如果 'abc' 存储在 char(10) 字段中,它返回 'abc'。 and our code fails.我们的代码失败了。 I was wondering if there is some configuration that I can do on the DB or firebird library to automatically trim char fields.我想知道是否可以在 DB 或 firebird 库上进行一些配置来自动修剪字符字段。

This is per the requirements laid down in the SQL standards: CHAR fields should be returned padded with spaces to the maximum defined length.这是根据 SQL 标准中规定的要求:返回的 CHAR 字段应填充空格以达到定义的最大长度。 If you don't want that behaviour, you need to use VARCHAR instead of CHAR.如果您不想要这种行为,则需要使用 VARCHAR 而不是 CHAR。

Update: Not sure if it is helpful, but according to this message you could create a workaround if you are using IBX.更新:不确定它是否有帮助,但根据此消息,如果您使用的是 IBX,您可以创建一个解决方法。

  1. Why don't you just change fields types in a database from CHAR to VARCHAR?为什么不将数据库中的字段类型从 CHAR 更改为 VARCHAR?
  2. You can use TRIM() function in SELECT statement.您可以在 SELECT 语句中使用 TRIM() 函数。
  3. You can put a couple of changes into IBX source codes in order to right trim CHAR strings.您可以对 IBX 源代码进行一些更改,以便正确修剪 CHAR 字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM