Win-1251 codepage and QIBASE driver
-
I work with FireBird database, who contain text strings in Win-1251 codepage. I use QT4.6 and QIBASE driver. QSqlQuery returned square instead cyrillic simbols.
The string
@db.setConnectOptions("ISC_DPB_LC_CTYPE=WIN-1251");@
don't work. Who can help me? -
Hi,
googling about your connection option, it seems that is WIN1251, and not WIN-1251. Is this correct?
T.
-
WIN1251 do not work to(
are both not return error are both not working!http://hin.dp.ua/files/down/QIBASE_fig1.png(See picture)!
-
You should try "windows-1251" (the value for the connection parameter must be a valid codec for "QTextCodec":http://doc.qt.nokia.com/4.7/qtextcodec.html)
-
windows-1251 and Windows-1251 are do not work
In this case wrote that character set is not defined. See below"errors text":http://hin.dp.ua/files/down/QIBASE_fig2.png
-
I don't know what's going on. It's weird that you get an error message about missing sqlite support when you are working with an ibase database.
Maybe "CP1251" works for the encoding. That's a known alias for windows-1251 in QTextCodec.
-
It’s really weird, but using “CP1251” such as "Windows-1251" returned error, the same error.
Using "WIN1251" do not returned error, but not returned correct symbols. -
According to "QIBASE Unicode Support and Text Encoding":http://doc.qt.nokia.com/4.7/sql-driver.html#qibase-unicode-support-and-text-encoding it falls back to Unicode when the encoding you request is not available (not availabel in QTextCodec, according to a quick look to the source code of the qsql_ibase plugin).
CP1251 and Windows-1251 are valid in QTextCodec but may not be correct for IBase; on the other hand WIN1251 and WIN-1251 may be correct for IBase but are not valid for QTextCodec. So this seems to be a loose-loose situation.
One solution might be to create your own QTextCodec according to the "API docs":http://doc.qt.nokia.com/4.7/qtextcodec.html#creating-your-own-codec-class. I'd leave all the functionality to a codec you get with codecForName(), saved as a class-private pointer to your new codec and delegate all methods to the respective methods of the worker codec (except the name/aliases of course).
Or you add another alias to src/corelib/codecs/qsimplecodec.cpp and compile your Qt libs manually (i.e. not use the precompiled ones).
-
thanks to all
-
You mean it?
in file src/corelib/codecs/qsimplecodec.cpp
@
...
{ "windows-1251", { "CP1251", "WIN1251", "WIN-1251", 0 }, 2251,
{ 0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021,
0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F,
...
@And in this case, along with my program I will must to distribute own, modified library? Isn't it?
-
Yes, that's right. Or you go with a custom text codec plugin. In that case you only need to distribute this one, without modifying the base Qt libs.
-
Did the above qsimplecodec.cpp change fix your problem?
-
I was not able to compile: (
Too many errors and time less to complete the task.
Apparently there have been failures in setting up paths.
I'm using ODBC driver now.
Unfortunately. -
Seems to be reported as bug "QTBUG-15608":http://bugreports.qt.nokia.com/browse/QTBUG-15608
-
in the file C:\Qt\Qt5.7.0\5.7\Src\qtbase\src\sql\drivers\ibase\qsql_ibase.cpp
find the code:
// Use UNICODE_FSS when no ISC_DPB_LC_CTYPE is provided
if (encString.isEmpty())
encString = QLatin1String("UNICODE_FSS");
else {
d->tc = QTextCodec::codecForName(encString.toLocal8Bit());
if (!d->tc) {
qWarning("Unsupported encoding: %s. Using UNICODE_FFS for ISC_DPB_LC_CTYPE.", encString.toLocal8Bit().constData());
encString = QLatin1String("UNICODE_FSS"); // Fallback to UNICODE_FSS
}
}
to redo:
// Use UNICODE_FSS when no ISC_DPB_LC_CTYPE is provided
if (encString.isEmpty())
encString = QLatin1String("UNICODE_FSS");
else
{
QString temp = QLatin1String("WIN1251");
if(encString == temp)
{
qDebug()<<"win1251 detected";
temp = QLatin1String("windows-1251");
d->tc = QTextCodec::codecForName(temp.toLocal8Bit());
}
else
{
d->tc = QTextCodec::codecForName(encString.toLocal8Bit());
if (!d->tc)
{
qWarning("Unsupported encoding: %s. Using UNICODE_FFS for ISC_DPB_LC_CTYPE.", encString.toLocal8Bit().constData());
encString = QLatin1String("UNICODE_FSS"); // Fallback to UNICODE_FSS
}
}
}compile your driver as shown in the documentation:
cd $QTDIR/qtbase/src/plugins/sqldrivers/ibase
qmake "INCLUDEPATH+=/opt/interbase/include" "LIBS+=-L/opt/interbase/lib" ibase.pro
make
move dll from C:\Qt\Qt5.7.0\5.7\Src\qtbase\plugins\sqldrivers to C:\Qt\Qt5.7.0\5.7\mingw53_32\plugins\sqldrivers
enjoy it