Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlQuery (sqlite engine), how to bind chinese code field?
Qt 6.11 is out! See what's new in the release blog

QSqlQuery (sqlite engine), how to bind chinese code field?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    changtj
    wrote on last edited by changtj
    #1

    os: windows 10
    compiler: vs 2017
    code: utf8 with bom

    sql:

    SELECT material_t.*,( SELECT material_attr_t.mtavalue FROM material_attr_t ,material_type_attr_t WHERE material_attr_t.mtaid = material_type_attr_t.mtaid AND mtaname = '阻值' AND material_attr_t.mid = material_t.mid ) AS '阻值', WHERE material_t.mtid = 1 AND 阻值=:阻值

    prepare:
    sqlQuery.prepare( QString::fromLocal8Bit( prepare.c_str() )

    bind:

    sqlQuery.bindValue( ":" + QString::fromLocal8Bit(it->col.c_str()), it->d);

    it is actual bind :
    sqlQuery.bindValue( ":" + QString::fromLocal8Bit("阻值"), 100);

    QMap<QString, QVariant> bound = sqlQuery.boundValues();

    i find bound's size is 0. so ,bind failture?

    then ,how can i to bind chinese charactor field?

    jsulmJ 1 Reply Last reply
    0
    • C changtj

      os: windows 10
      compiler: vs 2017
      code: utf8 with bom

      sql:

      SELECT material_t.*,( SELECT material_attr_t.mtavalue FROM material_attr_t ,material_type_attr_t WHERE material_attr_t.mtaid = material_type_attr_t.mtaid AND mtaname = '阻值' AND material_attr_t.mid = material_t.mid ) AS '阻值', WHERE material_t.mtid = 1 AND 阻值=:阻值

      prepare:
      sqlQuery.prepare( QString::fromLocal8Bit( prepare.c_str() )

      bind:

      sqlQuery.bindValue( ":" + QString::fromLocal8Bit(it->col.c_str()), it->d);

      it is actual bind :
      sqlQuery.bindValue( ":" + QString::fromLocal8Bit("阻值"), 100);

      QMap<QString, QVariant> bound = sqlQuery.boundValues();

      i find bound's size is 0. so ,bind failture?

      then ,how can i to bind chinese charactor field?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @changtj said in QSqlQuery (sqlite engine), how to bind chinese code field?:

      QString::fromLocal8Bit

      Why do you call this with a string containing Chinese characters?!
      Chenese can't be represented with 8bit encodings.
      Use fromUtf8() instead.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply
      2
      • C Offline
        C Offline
        changtj
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • jsulmJ jsulm

          @changtj said in QSqlQuery (sqlite engine), how to bind chinese code field?:

          QString::fromLocal8Bit

          Why do you call this with a string containing Chinese characters?!
          Chenese can't be represented with 8bit encodings.
          Use fromUtf8() instead.

          C Offline
          C Offline
          changtj
          wrote on last edited by changtj
          #4

          @jsulm

          it is not ok, i changed code as follow.
          prepare:
          sqlQuery.prepare( QString::fromUtf8( prepare.c_str() ) )

          qDebug output:
          SELECT material_t.*,( SELECT material_attr_t.mtavalue FROM material_attr_t ,material_type_attr_t WHERE material_attr_t.mtaid = material_type_attr_t.mtaid AND mtaname = '阻值' AND mtashow = 1 AND material_attr_t.mid = material_t.mid ) AS '阻值' WHERE material_t.mtid = 1 AND 阻值=:阻值

          bind:
          QString placeholder = ":" + QString::fromUtf8(it->col.c_str());
          qDebug() << placeholder << "," << it->d << "; ";
          sqlQuery.bindValue( placeholder, it->d);

          qDebug output:
          ":阻值" , QVariant(int, 100) ;

          sqlQuery exec error: " Parameter count mismatch"

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved