Results 1 to 4 of 4

Thread: What is the equivalent code lines to interbase jdbc url?

  1. #1

    Default 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:
    Qt Code:
    1. // JDBC driver name and database URL
    2. public static String jdbcDriver = "org.firebirdsql.jdbc.FBDriver";
    3. public static String jdbcUrl = "jdbc:firebirdsql://localhost/c:/FOODBEV.GDB?charSet=GBK&encoding=NONE";
    4.  
    5. Class.forName(jdbcDriver);
    6. if (conn == null) {
    7. conn = DriverManager.getConnection(jdbcUrl, dbUser, dbPassword);
    8. }
    9.  
    10. JSONObject updateObject = new JSONObject();
    11. updateObject.put("cmd", "updatecloudmenu");
    12.  
    13. JSONArray categoryObjectArray = new JSONArray();
    14. updateObject.put("data", categoryObjectArray);
    15.  
    16.  
    17. num = 0;
    18. if (stmt == null) {
    19. stmt = conn.createStatement();
    20. }
    21. sql = "SELECT ID, CODE, NAME, CATEGORY, PRICE, PRICE2, PRICE3, UNIT, UNIT2, UNIT3, OPERATION FROM XC_ITEM";
    22. ResultSet rs = stmt.executeQuery(sql);
    23. while (rs.next()) {
    24. num++;
    25. ......
    26. ......
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QIBASE", "ib");
    2. db.setHostName("127.0.0.1");
    3. db.setDatabaseName("C:/FOODBEV.GDB");//"C:/TEST.GDB"
    4. db.setUserName("SYSDBA");
    5. db.setPassword("masterkey");
    6. db.setConnectOptions("ISC_DPB_LC_CTYPE=gb2312"); // 对ä¸*文的支持
    7. bool bopen = false;
    8. bopen = db.open();
    9. LOG(TRACE) << "bopen=" << bopen;
    10.  
    11. QSqlTableModel tableModel(0, db);
    12. tableModel.setTable("XC_ITEM");
    13. tableModel.select();
    14. for (int i = 0; i < tableModel.rowCount(); i++) {
    15. LOG(TRACE) << "tableModel.row=" << i << ", item=" << tableModel.record(i).value("ITEM").toString() << ", des=" << tableModel.record(i).value("DES").toString();
    16. }
    17. ......
    18. ......
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by anda_skoa; 6th January 2017 at 11:07. Reason: changed [quote] to [code]

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: What is the equivalent code lines to interbase jdbc url?

    Does the program emit a warning at runtime about the encoding?
    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 :
    Qt Code:
    1. QString temp = tableModel.record(i).value("ITEM").toString();
    To copy to clipboard, switch view to plain text mode 
    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?
    Last edited by ChrisW67; 6th January 2017 at 08:57. Reason: updated contents

  3. #3

    Default Re: What is the equivalent code lines to interbase jdbc url?

    Thanks for kind help.

    You get the row without recognisable Chinese characters or the row is completely missing?
    the row is completely missing when doing select sql execution.

    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...

  4. #4

    Default Re: What is the equivalent code lines to interbase jdbc url?

    My previous jave project, it got 2 parameters in the jdbc url:
    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?

Similar Threads

  1. Qt Creator Can I post links to code lines in output pane using external tools?
    By mrsomeonee in forum Qt Tools
    Replies: 0
    Last Post: 25th August 2011, 14:15
  2. Qt Creator Green lines under everything suggesting all my code is wrong
    By Sydius in forum Qt Tools
    Replies: 1
    Last Post: 21st June 2010, 05:57
  3. Replies: 2
    Last Post: 3rd April 2010, 11:32
  4. QByteArray processing (seeking equivalent QT code)
    By pdoria in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2009, 10:40
  5. Replies: 1
    Last Post: 6th February 2009, 00:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.