| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 1 | |
Hi What is the best way to do Unicode aware COLLATION in sqlite. Is there a easy way which is working with qt out of the box(use Qt function for comparision)? Thanks and regards Marco
On Wednesday 05 September 2007 12:18:46 marco bubke wrote: > What is the best way to do Unicode aware COLLATION in sqlite. Is there a > easy way which is working with qt out of the box(use Qt function for > comparision)? Use QString::localeAwareCompare. See: http://doc.trolltech.com/4.3/qstring.html#localeAwareCompare -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
marco bubke wrote:
> Hi
>
> What is the best way to do Unicode aware COLLATION in sqlite. Is there
> a easy way which is working with qt out of the box(use Qt function for
> comparision)?
>
> Thanks and regards
>
> Marco
We ended up using a custom collation type in qtopia, but found that it
added a significant overhead to our performance. If you can cop that
performance hit, then the below code may help:
Otherwise, we ended up using a custom sorting column, that we repopulate
when we change language. (Note, code is not likely to compile out of the
box for you, but will give you an idea of where to travel).
void QtopiaSqlPrivate::installSorting( QSqlDatabase &db)
{
#if defined(Q_USE_SQLITE) && defined(USE_LOCALE_AWARE)
int sqliteLocaleAwareCompare(void *, int ll, const void *l, int
rl, const void *r);
QVariant v = db.driver()->handle();
if (v.isValid() && strcmp(v.typeName(), "sqlite3*") == 0) {
// v.data() returns a pointer to the handle
sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
if (handle != 0) { // check that it is not NULL
int result = sqlite3_create_collation(
handle,
"localeAwareCompare",
SQLITE_UTF16, // ANY would be nice, but we only
encode in 16 anyway.
0,
sqliteLocaleAwareCompare);
if (result != SQLITE_OK)
qLog(Sql) << "Could not add string collation
function: " << result;
} else {
qLog(Sql) << "Could not get sqlite handle";
}
} else {
qLog(Sql) << "handle variant returned typename " <<
v.typeName();
}
#endif
}
int sqliteLocaleAwareCompare(void *, int ll, const void *l, int rl,
const void *r)
{
QString left = QString::fromUtf16((const ushort *)l, ll/2);
QString right = QString::fromUtf16((const ushort *)r, rl/2);
//qLog(Sql) << "comparing:" << left << "with" << right << "result"
<< QString::localeAwareCompare(left, right);
return QString::localeAwareCompare(left, right);
}
--
[ signature omitted ]
Is anyone using QtScript in version Qt version 4.3.1 (as apposed to QSA)
If so what are you using to debug your scripts ?
I know with QSA they provided a seperate debugging utility, but i am unsure
if this would work with QtScript.
If possible i am trying to find a way of stepping through script code
Any help is appreciated ...
Regards,
Ben
-----Original Message-----
From: Bill KING [mailto:bill.king@xxxxxxxxxxxxx]
Sent: Thursday, 6 September 2007 11:23 AM
To: qt-interest@xxxxxxxxxxxxx
Cc: qt-interest@xxxxxxxxxxxxx
Subject: Re: Unicode aware COLLATION in QSQLITE
marco bubke wrote:
> Hi
>
> What is the best way to do Unicode aware COLLATION in sqlite. Is there
> a easy way which is working with qt out of the box(use Qt function for
> comparision)?
>
> Thanks and regards
>
> Marco
We ended up using a custom collation type in qtopia, but found that it
added a significant overhead to our performance. If you can cop that
performance hit, then the below code may help:
Otherwise, we ended up using a custom sorting column, that we repopulate
when we change language. (Note, code is not likely to compile out of the
box for you, but will give you an idea of where to travel).
void QtopiaSqlPrivate::installSorting( QSqlDatabase &db)
{
#if defined(Q_USE_SQLITE) && defined(USE_LOCALE_AWARE)
int sqliteLocaleAwareCompare(void *, int ll, const void *l, int
rl, const void *r);
QVariant v = db.driver()->handle();
if (v.isValid() && strcmp(v.typeName(), "sqlite3*") == 0) {
// v.data() returns a pointer to the handle
sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
if (handle != 0) { // check that it is not NULL
int result = sqlite3_create_collation(
handle,
"localeAwareCompare",
SQLITE_UTF16, // ANY would be nice, but we only
encode in 16 anyway.
0,
sqliteLocaleAwareCompare);
if (result != SQLITE_OK)
qLog(Sql) << "Could not add string collation
function: " << result;
} else {
qLog(Sql) << "Could not get sqlite handle";
}
} else {
qLog(Sql) << "handle variant returned typename " <<
v.typeName();
}
#endif
}
int sqliteLocaleAwareCompare(void *, int ll, const void *l, int rl,
const void *r)
{
QString left = QString::fromUtf16((const ushort *)l, ll/2);
QString right = QString::fromUtf16((const ushort *)r, rl/2);
//qLog(Sql) << "comparing:" << left << "with" << right << "result"
<< QString::localeAwareCompare(left, right);
return QString::localeAwareCompare(left, right);
}
--
[ signature omitted ]
Ben Shaw wrote: > Is anyone using QtScript in version Qt version 4.3.1 (as apposed to QSA) > If so what are you using to debug your scripts ? > > I know with QSA they provided a seperate debugging utility, but i am unsure > if this would work with QtScript. > If possible i am trying to find a way of stepping through script code > > Any help is appreciated ... > > Regards, > > Ben > Hi Ben, With the Qt 4.3 API, it's not possible. However, a new class called QScriptEngineAgent has recently been added to the 4.4 snapshots, which you can use to receive step notification. There's an example in examples/script/qsdbg that shows how a simple gdb-like debugger can be built on top of the API, providing breakpoints and stepping functionality. For the 4.4 release, we plan to have a GUI-based debugger that you can add to your application. Regards, Kent -- [ signature omitted ]
marco bubke wrote:
> Hi
>
> What is the best way to do Unicode aware COLLATION in sqlite. Is there
> a easy way which is working with qt out of the box(use Qt function for
> comparision)?
>
> Thanks and regards
>
> Marco
I think you should build sqlite with ICU for collation support.
1. Download sqlite (www.sqlite.org, current version is 3.4.2) and unpack it to somewhere.
2. Download ICU (International Components for Unicode). ICU is available at http://www.icu-project.org.
Please read the file named "readme.txt" in sqlite-version/ext/icu for more details (sqlite-version is sqlite root folder and version can be "3.4.2", for example).
I hope this will help.
---------------------------------
Hái, ÄÃp và kát nái vái cÆ dÃn máng trÃn Yahoo! Hái & ÄÃp