ŸT

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Man-wai Chang

    ŸT


    I create a charset=big5 collate=big5 table to store Chinese characters
    in big5 code. However, the INSERT sql failed when the character is
    0x9f54. Why? If the value needs to be escaped, what function should I use?

    --
    iTech Consulting Co., Ltd.
    Expert of ePOS solutions
    Website: http://www.itech.com.hk (IE only)
    Tel: (852)2325 3883 Fax: (852)2325 8288
  • Jerry Stuckle

    #2
    Re: 0x9f54

    Man-wai Chang wrote:
    >
    I create a charset=big5 collate=big5 table to store Chinese characters
    in big5 code. However, the INSERT sql failed when the character is
    0x9f54. Why? If the value needs to be escaped, what function should I use?
    >
    What database are you using? Different databases have different functions.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Man-wai Chang

      #3
      Re: 0x9f54

      >I create a charset=big5 collate=big5 table to store Chinese characters
      >in big5 code. However, the INSERT sql failed when the character is
      >0x9f54. Why? If the value needs to be escaped, what function should I
      >use?
      What database are you using? Different databases have different functions.
      [chang@localhost ~]$ rpm -qa | grep sql
      libdbi-dbd-mysql-0.7.1-3
      sqlite-3.1.2-3
      mysql-4.1.20-1.FC4.1
      mysqlclient10-3.23.58-6
      php-mysql-5.0.4-10.5
      python-sqlite-1.1.6-1
      postgresql-libs-8.0.8-1.FC4.1
      mysql-devel-4.1.20-1.FC4.1
      mysql-server-4.1.20-1.FC4.1
      [chang@localhost ~]$ rpm -qa | grep php
      php-ldap-5.0.4-10.5
      php-gd-5.0.4-10.5
      php-dbase-5.0.4-3.fc4
      php-pear-5.0.4-10.5
      php-mysql-5.0.4-10.5
      php-5.0.4-10.5


      --
      iTech Consulting Co., Ltd.
      Expert of ePOS solutions
      Website: http://www.itech.com.hk (IE only)
      Tel: (852)2325 3883 Fax: (852)2325 8288

      <?

      class MYSQL {
      private $fhandle;
      var $row;
      function MYSQL($host,$db ,$usr,$pwd) {
      $this->fhandle=mysqli _connect($host, $usr,$pwd,$db)
      or die(mysqli_erro r());
      $this->query("set names big5;");
      $this->query("set character_set_c lient=big5;");
      }
      function query($sql_str) {
      $this->row=mysqli_que ry($this->fhandle, $sql_str)
      or die(mysqli_erro r($this->fhandle));
      }
      function affected_rows() {
      return mysqli_affected _rows($this->row);
      }
      function num_rows() {
      return mysqli_num_rows ($this->row);
      }
      function fetch_assoc() {
      return mysqli_fetch_as soc($this->row);
      }
      function __destruct() {
      mysqli_close($t his->fhandle);
      }
      function begin_tran() {
      mysqli_autocomm it($this->fhandle, FALSE);
      }
      function commit() {
      mysqli_commit($ this->fhandle);
      mysqli_autocomm it($this->fhandle, TRUE);
      }
      function rollback() {
      mysqli_rollback ($this->fhandle);
      mysqli_autocomm it($this->fhandle, TRUE);
      }
      }

      function showcode($cChar ) {
      return "[".ord(substr($c Char,0,1)).".". ord(substr($cCh ar,1,1))."]";
      }


      $target=new MYSQL("localhos t","order_dev", "root","123456" );

      $fhandle=dbase_ open("canton.DB F",0);
      if ($fhandle) {
      $reccount=dbase _numrecords($fh andle);
      echo "input count: ".$reccount."\n ";
      # clear table
      $target->query("drop table canton");
      $target->query(
      "create table canton ("
      . " big5 char(2) collate big5_bin not null,"
      . " unicode char(20) not null,"
      . " thekey char(6) collate big5_bin ,"
      . " canton char(10) collate big5_bin ,"
      . " changjei char(10) collate big5_bin,"
      . " touched integer collate big5_bin,"
      . " primary key (big5)"
      . " ) default charset=big5 collate=big5_bi n;"
      );
      for ($ii=1; $ii<=$reccount; $ii++) {
      $row=dbase_get_ record_with_nam es($fhandle,$ii );
      $ss=$row['BIG5'];
      $tt="0x".dechex (ord(substr($ss ,0,1))).dechex( ord(substr($ss, 1,1)));
      echo $ss.$tt."\n";
      $target->query("selec t * from canton where big5=".$tt."");
      $yy = $target->num_rows();
      if ($yy>0) {
      $query="update canton set touched="
      . $row["TOUCHED"]
      . " where big5=" . $tt . "";
      }
      else {
      $query="insert into canton ("
      . " big5,"
      . " unicode,"
      . " thekey,"
      . " changjei,"
      . " canton,"
      . " touched "
      . ") values ("
      . "".$tt.","
      . "'mb_convert_en coding',"
      . "'".$row["THEKEY"]."',"
      . "'".$row["CHANGJEI"]."',"
      . "'".$row["CANTON"]."',"
      . $row["TOUCHED"]
      . ")";
      }
      $result=$target->query($query );
      }
      $result=$target->query("selec t count(*) as cnt from canton");
      $yy = $target->fetch_assoc( );
      echo "output count: ".$yy['cnt']."\n";
      dbase_close($fh andle);
      }
      ?>

      Comment

      • Man-wai Chang

        #4
        Re: 0x9f54

        I just found that it would work if I use binary(2) rather char(2) for
        the big5 column. But I found something using char(2) to store big5
        codes. Why can't my program work?

        --
        iTech Consulting Co., Ltd.
        Expert of ePOS solutions
        Website: http://www.itech.com.hk (IE only)
        Tel: (852)2325 3883 Fax: (852)2325 8288

        Comment

        • Man-wai Chang

          #5
          Re: 0x9f54

          Argh... sorry.

          I found the bug. It's in the data. Sorry. I don't know why I missed it...

          --
          iTech Consulting Co., Ltd.
          Expert of ePOS solutions
          Website: http://www.itech.com.hk (IE only)
          Tel: (852)2325 3883 Fax: (852)2325 8288

          Comment

          • Kimmo Laine

            #6
            Re: 0x9f54

            "Man-wai Chang" <toylet.toylet@ gmail.comwrote in message
            news:45f8beb9$1 @127.0.0.1...
            >
            I create a charset=big5 collate=big5 table to store Chinese characters in
            big5 code. However, the INSERT sql failed when the character is 0x9f54.
            Why? If the value needs to be escaped, what function should I use?

            I'm guessing it has something to do with the fact that 0x54 is ASCII single
            quote ' .

            --
            "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
            http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
            spam@outolempi. net | rot13(xvzzb@bhg byrzcv.arg)


            Comment

            • Man-wai Chang

              #7
              Re: 0x9f54

              I'm guessing it has something to do with the fact that 0x54 is ASCII single
              quote ' .
              Thanks. What should I do if I really need to add it into it?
              mysql_escape_st ring?

              --
              iTech Consulting Co., Ltd.
              Expert of ePOS solutions
              Website: http://www.itech.com.hk (IE only)
              Tel: (852)2325 3883 Fax: (852)2325 8288

              Comment

              • Kimmo Laine

                #8
                Re: 0x9f54

                "Man-wai Chang" <toylet.toylet@ gmail.comwrote in message
                news:45f9075c$1 @127.0.0.1...
                >I'm guessing it has something to do with the fact that 0x54 is ASCII
                >single quote ' .
                >
                Thanks. What should I do if I really need to add it into it?
                mysql_escape_st ring?

                You can try that (or mysql_real_esca pe), I don't know how it works with a
                multibyte string, I haven't got any experience on that matter. Why don't you
                try it and see if it works? If you do test it, please share your experience
                with the group and if you find a working solution.

                --
                "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
                http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
                spam@outolempi. net | rot13(xvzzb@bhg byrzcv.arg)


                Comment

                • Jerry Stuckle

                  #9
                  Re: 0x9f54

                  Kimmo Laine wrote:
                  "Man-wai Chang" <toylet.toylet@ gmail.comwrote in message
                  news:45f9075c$1 @127.0.0.1...
                  >>I'm guessing it has something to do with the fact that 0x54 is ASCII
                  >>single quote ' .
                  >Thanks. What should I do if I really need to add it into it?
                  >mysql_escape_s tring?
                  >
                  >
                  You can try that (or mysql_real_esca pe), I don't know how it works with a
                  multibyte string, I haven't got any experience on that matter. Why don't you
                  try it and see if it works? If you do test it, please share your experience
                  with the group and if you find a working solution.
                  >
                  If the table is set up with the correct charset,
                  mysql_real_esca pe_string() should work.

                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  Working...