Re: What is the equivalent code lines to interbase jdbc url?
Hello,
I am new in the forum, and now met an issue when using the database connection for interbase regarding chracter set and encoding in qt.
Previously I have a java project which also connects to interbase database via below code:
Code:
// JDBC driver name and database URL
public static String jdbcDriver = "org.firebirdsql.jdbc.FBDriver";
public static String jdbcUrl = "jdbc:firebirdsql://localhost/c:/FOODBEV.GDB?charSet=GBK&encoding=NONE";
Class.forName(jdbcDriver);
if (conn == null) {
conn = DriverManager.getConnection(jdbcUrl, dbUser, dbPassword);
}
JSONObject updateObject = new JSONObject();
updateObject.put("cmd", "updatecloudmenu");
JSONArray categoryObjectArray = new JSONArray();
updateObject.put("data", categoryObjectArray);
num = 0;
if (stmt == null) {
stmt = conn.createStatement();
}
sql = "SELECT ID, CODE, NAME, CATEGORY, PRICE, PRICE2, PRICE3, UNIT, UNIT2, UNIT3, OPERATION FROM XC_ITEM";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
num++;
......
......
It can get the rows successfully when having Chinese characters.
And now I want to achieve the same in qt with this same database, my qt code (source code file is UTF-8, and using QTCreator 5.5.1 mingw version) is as below:
Code:
db.setHostName("127.0.0.1");
db.setDatabaseName("C:/FOODBEV.GDB");//"C:/TEST.GDB"
db.setUserName("SYSDBA");
db.setPassword("masterkey");
db.setConnectOptions("ISC_DPB_LC_CTYPE=gb2312"); // 对ä¸*文的支æŒ
bool bopen = false;
bopen = db.open();
LOG(TRACE) << "bopen=" << bopen;
tableModel.setTable("XC_ITEM");
tableModel.select();
for (int i = 0; i < tableModel.rowCount(); i++) {
LOG(TRACE) << "tableModel.row=" << i << ", item=" << tableModel.record(i).value("ITEM").toString() << ", des=" << tableModel.record(i).value("DES").toString();
}
......
......
When there is no Chinese characters, it works well, but if there is any Chinese characters, then just can not return the rows with Chinese characters.
Anything I did wrong? How to resolve this problem?
Any help is highly appreciated!
Another strange thing is: I found using above code, I can successfully insert into tables with rows having Chinese characters without any garbage characters, but just could not query with the correct result with regard to those rows having Chinese characters.
Re: What is the equivalent code lines to interbase jdbc url?
Does the program emit a warning at runtime about the encoding?
Quote:
When there is no Chinese characters, it works well, but if there is any Chinese characters, then just can not return the rows with Chinese characters.
You get the row without recognisable Chinese characters or the row is completely missing?
Inside the loop add a line :
Code:
QString temp
= tableModel.
record(i
).
value("ITEM").
toString();
Single step the program in the debugger and inspect the value in temp. Is it correct?
Is whatever LOG() writes to Unicode capable?
GBK is an extension of GB2312. Are the broken characters part of the extensions and therefore not understood by gb2312?
Re: What is the equivalent code lines to interbase jdbc url?
Thanks for kind help.
Quote:
You get the row without recognisable Chinese characters or the row is completely missing?
the row is completely missing when doing select sql execution.
Quote:
Single step the program in the debugger and inspect the value in temp. Is it correct?
Is whatever LOG() writes to Unicode capable?
If the table only contains rows with Chinese, tableModel.rowCount() will be 0, so the loop is not executed at all.
Regarding LOG(TRACE), I just used easyloggingpp as below, and with no problem.
https://github.com/easylogging/easyloggingpp
Actually, with above code, I can insert rows with Chinese correctly into datase...
Re: What is the equivalent code lines to interbase jdbc url?
My previous jave project, it got 2 parameters in the jdbc url:
Quote:
charSet=GBK
encoding=NONE
But in the QT, there seems only ISC_DPB_LC_CTYPE parameter for Character set, how about the encoding in QT?