1

In my sqlite database for an iPhone app, I encode/compress a long array of integers (up to 5 digits) into a string using the extended ASCII character set to get it down to 2 characters. (In other words, I encode it using base150)

When getting it out of the database, sqlite3_column_text() returns the string as a "const unsigned char *". I can print this string using printf correctly (it shows even the ASCII characters over 128 properly) but when I try to iterate through it and access each character of the string individually to convert back into my integers, characters with ASCII values over 128 fail, because they're multibyte and it's only getting one byte (I think).

Example:

I have this string called encodedString which contains: svÖ)

unsigned char c = encodedString[0];
unsigned char d = encodedString[2];

printf("%c", c);  //outputs "s"
printf("%c", d);  //outputs "\303"
printf("%s", encodedString);  //outputs "svÖ)"

I've also tried wchar_t with the same results. I have gotten it to work using NSStrings, but it's very slow, and I'm doing this many thousands of times (NSMakeRange is the culprit according to the profiler), so I want it to be as fast as possible, hence C.

What's the trick to getting a single multibyte/extended ASCII character out of a string?

4

1 回答 1

1

TEXT我建议不要使用列,而是使用列,BLOB其中数据包含您想要使用的任何大小的整数数组(可能是 16 位无符号数)。

您可以使用sqlite_column_bytes()来确定列的大小,从而允许使用可变长度的列。

这将避免您当前面临的复杂性。

于 2013-06-21T07:32:01.797 回答