Uploaded image for project: 'CUBRID APIs'
  1. CUBRID APIs
  2. APIS-364

[PHP][Windows] the export lob file from db is not correct after import the lob fie into db successfully

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: PHP-Apricot
    • Fix Version/s: PHP 9.1.0 0004
    • Component/s: PHP Driver
    • Labels:
      None
    • Environment:

      Windows 7 32 bit

      Description

      [PHP][Windows] the export lob file from db is not correct after import the lob fie into db successfully
      1. import the lob files
      2. export the lob files to local system
      3. check whether the export files can open successfully and the size of it is equal with import files

      Test verion:

      Cubrid: CUBRID 9.0 (9.0.0.0478)
      PHP Driver: 
      CUBRID-PHP5-5.3-WIN32-VC9-TS-9.0.0.0001.bin.zip
      

      codes:

      $exportName=array("php/_15_newLob/blob/export/export00.jpg", "php/_15_newLob/blob/export/export04.jpg", "php/_15_newLob/blob/export/export05.jpg");
      for($i=0; $i<count($exportName); $i++){
          $lob= cubrid_lob2_new();
          if ($lob === FALSE) {
              printf("%d--Error:[%d] [%s]\n",__LINE__,cubrid_error_code(),cubrid_error_msg());
          }elseif(is_null($lob)){
              printf("%d--there is maybe some error\n", __LINE__);
          }else{
              printf("%d--ok\n", __LINE__);
          }
      
          $lob=$row[$i+1];
          $tmp=cubrid_lob2_export($lob, $exportName[$i]);
          if ($tmp === FALSE) {
              printf("%d--Error: [%d] [%s]\n",__LINE__,cubrid_error_code(),cubrid_error_msg());
          }elseif(is_null($tmp)){
              printf("%d--there is maybe some error\n", __LINE__);
          }else{
              printf("%d--ok\n", __LINE__);
          }
      
          $tmp=cubrid_lob2_close($lob);
          if ($tmp === FALSE) {
              printf("%d--Error:[%d] [%s]\n",__LINE__,cubrid_error_code(),cubrid_error_msg());
          } 
      }
      
      cubrid_disconnect($conn);
      
      
      //judge that the importing file size is equal to the exporting file size.
      for($i=0; $i<count($importName); $i++){
          $tmp=file_exists($exportName[$i]);
          if ($tmp === FALSE) {
              printf("%d--Error:[%d] [%s]\n",__LINE__,cubrid_error_code(),cubrid_error_msg());
          } 
          $importSize=filesize($importName[$i]);
          $exportSize=filesize($exportName[$i]);
          if( $importSize === $exportSize){
              printf("file size: %d\n", $importSize);
              printf("%d--Expect result.\n", __LINE__);
          }else{
              printf("%d--Not expect result.\n", __LINE__);
          }
      }
      {noforamt}
      
      
      Result:
      

      Warning: cubrid_lob2_export(): The file that you want to export lob object may have existed. in D:\work\Project\Cubrid_interface\environment_deploy\php_windows\php_15_newLob\blob\blob01.php on line 134
      136--Error: [0] []
      164--Not expect result.
      164--Not expect result.
      164--Not expect result.
      Finished!

      
      
      1. blob01.phpt
        6 kB
        欧明宝[Bom Owen]

        Activity

        Hide
        cn15163 杨伟为[Astro] added a comment -

        This issue is caused by function "cubrid_lob2_export".
        When exporting a file this function use "open" to open a file but does not add "O_BINARY" flag to it. So the exported file is treated as text file, and the "0x0A" in database is translated into "0x0D 0x0A", thus things go wrong. So add "O_BINARY" to it when on windows to fix it.

        Show
        cn15163 杨伟为[Astro] added a comment - This issue is caused by function "cubrid_lob2_export". When exporting a file this function use "open" to open a file but does not add "O_BINARY" flag to it. So the exported file is treated as text file, and the "0x0A" in database is translated into "0x0D 0x0A", thus things go wrong. So add "O_BINARY" to it when on windows to fix it.
        Hide
        ryin005 Ray Yin added a comment -

        Added a case for the issue

        [php@NC-PL-QA011 _14_issues]$ svn ci --username ray -m "[APIS-364] Added a case to test cubrid_lob2_export function with imported lob2 files"
        Adding         _14_issues/bug_apis_364
        Adding         _14_issues/bug_apis_364/cases
        Adding         _14_issues/bug_apis_364/cases/bug_apis_364.phpt
        Adding         _14_issues/bug_apis_364/cases/bug_apis_364.sh
        Adding         _14_issues/bug_apis_364/cases/connect.inc
        Adding  (bin)  _14_issues/bug_apis_364/cases/test.jpg
        Adding  (bin)  _14_issues/bug_apis_364/cases/test.png
        Adding         _14_issues/bug_apis_364/cases/test.txt
        Transmitting file data ......
        Committed revision 1980.
        

        Case Url: http://svn.cubrid.org/cubridapis/php/branches/RB-9.1.0_static_cci/tests2/php/_14_issues/bug_apis_364/

        Show
        ryin005 Ray Yin added a comment - Added a case for the issue [php@NC-PL-QA011 _14_issues]$ svn ci --username ray -m "[APIS-364] Added a case to test cubrid_lob2_export function with imported lob2 files" Adding _14_issues/bug_apis_364 Adding _14_issues/bug_apis_364/cases Adding _14_issues/bug_apis_364/cases/bug_apis_364.phpt Adding _14_issues/bug_apis_364/cases/bug_apis_364.sh Adding _14_issues/bug_apis_364/cases/connect.inc Adding (bin) _14_issues/bug_apis_364/cases/test.jpg Adding (bin) _14_issues/bug_apis_364/cases/test.png Adding _14_issues/bug_apis_364/cases/test.txt Transmitting file data ...... Committed revision 1980. Case Url: http://svn.cubrid.org/cubridapis/php/branches/RB-9.1.0_static_cci/tests2/php/_14_issues/bug_apis_364/
        Hide
        ryin005 Ray Yin added a comment -

        Test OS: Linux 64, Win XP 32
        CUBRID Server: CUBRID 9.1 (9.1.0.0212)
        PHP Version: PHP 5.4.15
        CUBRID-PHP: 9.1.0.0004 svn: http://svn.cubrid.org/cubridapis/php/branches/RB-9.1.0_static_cci/
        Test Tool: PHP Tester (PHPT)

        Test Result: Pass

        Show
        ryin005 Ray Yin added a comment - Test OS: Linux 64, Win XP 32 CUBRID Server: CUBRID 9.1 (9.1.0.0212) PHP Version: PHP 5.4.15 CUBRID-PHP: 9.1.0.0004 svn: http://svn.cubrid.org/cubridapis/php/branches/RB-9.1.0_static_cci/ Test Tool: PHP Tester (PHPT) Test Result: Pass

          People

          • Assignee:
            jinhu 李金虎
            Reporter:
            cn14130 欧明宝[Bom Owen]
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: