- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 185
Adjust binary escaping #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            vistart
  wants to merge
  26
  commits into
  yiisoft:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
vistart:master
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            26 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      6b494d1
              
                try Binary for pk.
              
              
                vistart ecd78eb
              
                Update ActiveRecordTest.php
              
              
                vistart de332f0
              
                try CustomerBinary test data active record.
              
              
                vistart e253216
              
                fix typo.
              
              
                vistart 8219cef
              
                try CustomerBinaryQuery.
              
              
                vistart 1e73316
              
                use three binary fks.
              
              
                vistart f0a58e4
              
                fix illegal syntax.
              
              
                vistart af65266
              
                fix illegal syntax.
              
              
                vistart 699bc2e
              
                try new primaryKey guid.
              
              
                vistart 0f4b935
              
                fix illegal usage for primaryKey().
              
              
                vistart d8068fe
              
                switch to use guid.
              
              
                vistart a0bb87d
              
                only test binary.
              
              
                vistart 953abe4
              
                change bad case guid.
              
              
                vistart de1fa47
              
                try findOne().
              
              
                vistart 91aae56
              
                show quoteValue detail.
              
              
                vistart 11fb264
              
                show quoteValue detail.
              
              
                vistart a919fb6
              
                try find()->andWhere().
              
              
                vistart 44bdb5c
              
                Update LuaScriptBuilder.php
              
              
                vistart 0c26145
              
                try show executeScript().
              
              
                vistart a1e2b15
              
                show bad case.
              
              
                vistart 2974951
              
                try to solve #291.
              
              
                vistart e577c2a
              
                try to solve #251 and fix typo.
              
              
                vistart e8c73ad
              
                Improve annotations and attributes.
              
              
                vistart 9429ecc
              
                Merge branch 'master' into master
              
              
                samdark 6c68afb
              
                add  a line for CHANGELOG.
              
              
                vistart 1b49e8e
              
                Merge branch 'master' into master
              
              
                samdark File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -6,6 +6,7 @@ | |
| use yii\redis\LuaScriptBuilder; | ||
| use yiiunit\extensions\redis\data\ar\ActiveRecord; | ||
| use yiiunit\extensions\redis\data\ar\Customer; | ||
| use yiiunit\extensions\redis\data\ar\CustomerBinary; | ||
| use yiiunit\extensions\redis\data\ar\OrderItem; | ||
| use yiiunit\extensions\redis\data\ar\Order; | ||
| use yiiunit\extensions\redis\data\ar\Item; | ||
|  | @@ -19,6 +20,11 @@ | |
| class ActiveRecordTest extends TestCase | ||
| { | ||
| use ActiveRecordTestTrait; | ||
| public $fkBinary1; | ||
| public $fkBinary2; | ||
| public $fkBinary3; | ||
| public $userBinary; | ||
| public $fkBinaryNonExist; | ||
|  | ||
| /** | ||
| * @return string | ||
|  | @@ -28,6 +34,11 @@ public function getCustomerClass() | |
| return Customer::className(); | ||
| } | ||
|  | ||
| public function getCustomerBinaryClass() | ||
| { | ||
| return CustomerBinary::className(); | ||
| } | ||
|  | ||
| /** | ||
| * @return string | ||
| */ | ||
|  | @@ -164,6 +175,21 @@ public function setUp() | |
| $orderItem->setAttributes(['order_id' => 3, 'item_id' => 2, 'quantity' => 1, 'subtotal' => 40.0], false); | ||
| $orderItem->save(false); | ||
|  | ||
| $this->fkBinary1 = hex2bin(str_replace([' ', '-'], '', '51a4e62e-1b1a-56c9-e9e5-9efe21f55276')); | ||
| $this->fkBinary2 = hex2bin(str_replace([' ', '-'], '', '51a4e62e-1b1a-56c9-e9e6-9efe21f55276')); | ||
| $this->fkBinary3 = hex2bin(str_replace([' ', '-'], '', '51a4e62e-1b1a-56c9-e9e7-9efe21f55276')); | ||
| $this->userBinary = hex2bin(str_replace([' ', '-'], '', '51a4e62e-1b1a-56c9-e9e5-9efe21f55277')); | ||
| $this->fkBinaryNonExist = hex2bin(str_replace([' ', '-'], '', '51a4e62e-1b1a-56c9-e9e5-9efe21f55278')); | ||
| $customer = new CustomerBinary(); | ||
| $customer->setAttributes(['guid' => $this->fkBinary1, 'user_guid' => $this->userBinary, 'email' => '[email protected]', 'name' => 'user1', 'address' => 'address1', 'status' => 1, 'profile_id' => 1], false); | ||
| $customer->save(false); | ||
| $customer = new CustomerBinary(); | ||
| $customer->setAttributes(['guid' => $this->fkBinary2, 'user_guid' => $this->userBinary, 'email' => '[email protected]', 'name' => 'user2', 'address' => 'address2', 'status' => 1, 'profile_id' => null], false); | ||
| $customer->save(false); | ||
| $customer = new CustomerBinary(); | ||
| $customer->setAttributes(['guid' => $this->fkBinary3, 'user_guid' => $this->userBinary, 'email' => '[email protected]', 'name' => 'user3', 'address' => 'address3', 'status' => 2, 'profile_id' => 2], false); | ||
| $customer->save(false); | ||
|  | ||
| } | ||
|  | ||
| /** | ||
|  | @@ -705,4 +731,64 @@ public function testFind() | |
| $this->assertCount(2, $customerClass::find()->active()->all()); | ||
| $this->assertEquals(2, $customerClass::find()->active()->count()); | ||
| } | ||
|  | ||
| /** | ||
| * @group binary | ||
| */ | ||
| public function testFindBinaryPk() | ||
| { | ||
| /* @var $customerClass \yii\db\ActiveRecordInterface */ | ||
| $customerClass = $this->getCustomerBinaryClass(); | ||
|  | ||
| // find one | ||
| /* @var $this TestCase|ActiveRecordTestTrait */ | ||
| $result = $customerClass::find(); | ||
| $this->assertInstanceOf('\\yii\\db\\ActiveQueryInterface', $result); | ||
| $customer = $result->one(); | ||
| $this->assertInstanceOf($customerClass, $customer); | ||
|  | ||
| // find all | ||
| $customers = $customerClass::find()->all(); | ||
| $this->assertCount(3, $customers); | ||
| $this->assertInstanceOf($customerClass, $customers[0]); | ||
| $this->assertInstanceOf($customerClass, $customers[1]); | ||
| $this->assertInstanceOf($customerClass, $customers[2]); | ||
|  | ||
| // find by a single primary key | ||
| $customer = $customerClass::findOne($this->fkBinary1); | ||
| $this->assertInstanceOf($customerClass, $customer); | ||
| $this->assertEquals('user1', $customer->name); | ||
| $customer = $customerClass::findOne($this->fkBinaryNonExist); | ||
| $this->assertNull($customer); | ||
| $customer = $customerClass::findOne(['guid' => [$this->fkBinary1, $this->fkBinaryNonExist]]); | ||
| $this->assertInstanceOf($customerClass, $customer); | ||
| $customer = $customerClass::find()->where(['guid' => [$this->fkBinary1, $this->fkBinaryNonExist]])->one(); | ||
| $this->assertNotNull($customer); | ||
|  | ||
| // find by column values | ||
| $customer = $customerClass::findOne(['guid' => $this->fkBinary2, 'name' => 'user2']); | ||
| $this->assertInstanceOf($customerClass, $customer); | ||
| $this->assertEquals('user2', $customer->name); | ||
| $customer = $customerClass::findOne(['guid' => $this->fkBinary2, 'name' => 'user1']); | ||
| $this->assertNull($customer); | ||
| $customer = $customerClass::findOne(['guid' => $this->fkBinaryNonExist]); | ||
| $this->assertNull($customer); | ||
| $customer = $customerClass::findOne(['name' => 'user5']); | ||
| $this->assertNull($customer); | ||
| $customer = $customerClass::findOne(['user_guid' => $this->userBinary]); | ||
| $this->assertInstanceOf($customerClass, $customer); | ||
|  | ||
| // find by attributes | ||
| $customer = $customerClass::find()->where(['name' => 'user2'])->one(); | ||
| $this->assertInstanceOf($customerClass, $customer); | ||
| $this->assertEquals($this->fkBinary2, $customer->guid); | ||
| $customer = $customerClass::find()->where(['user_guid' => $this->userBinary])->one(); | ||
| $this->assertInstanceOf($customerClass, $customer); | ||
|  | ||
| // scope | ||
| $this->assertCount(2, $customerClass::find()->active()->all()); | ||
| $this->assertEquals(2, $customerClass::find()->active()->count()); | ||
| $this->assertCount(3, $customerClass::find()->where(['user_guid' => $this->userBinary])->all()); | ||
| $this->assertEquals(3, $customerClass::find()->where(['user_guid' => $this->userBinary])->count()); | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php | ||
|  | ||
| namespace yiiunit\extensions\redis\data\ar; | ||
|  | ||
| use yiiunit\extensions\redis\ActiveRecordTest; | ||
|  | ||
| /** | ||
| * CustomerBinary | ||
| * | ||
| * @property string $guid | ||
| * @property string $user_guid | ||
| * @property string $email | ||
| * @property string $name | ||
| * @property string $address | ||
| * @property int $status | ||
| * | ||
| * @method CustomerBinaryQuery findBySql($sql, $params = []) static | ||
| */ | ||
| class CustomerBinary extends ActiveRecord | ||
| { | ||
| const STATUS_ACTIVE = 1; | ||
| const STATUS_INACTIVE = 2; | ||
|  | ||
| public $status2; | ||
|  | ||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public function attributes() | ||
| { | ||
| return ['guid', 'user_guid', 'email', 'name', 'address', 'status']; | ||
| } | ||
|  | ||
| public static function primaryKey() | ||
| { | ||
| return ['guid']; | ||
| } | ||
|  | ||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public function afterSave($insert, $changedAttributes) | ||
| { | ||
| ActiveRecordTest::$afterSaveInsert = $insert; | ||
| ActiveRecordTest::$afterSaveNewRecord = $this->isNewRecord; | ||
| parent::afterSave($insert, $changedAttributes); | ||
| } | ||
|  | ||
| /** | ||
| * @inheritdoc | ||
| * @return CustomerBinaryQuery | ||
| */ | ||
| public static function find() | ||
| { | ||
| return new CustomerBinaryQuery(get_called_class()); | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?php | ||
|  | ||
| namespace yiiunit\extensions\redis\data\ar; | ||
|  | ||
| use yii\redis\ActiveQuery; | ||
|  | ||
| /** | ||
| * CustomerBinaryQuery | ||
| */ | ||
| class CustomerBinaryQuery extends ActiveQuery | ||
| { | ||
| /** | ||
| * @return $this | ||
| */ | ||
| public function active() | ||
| { | ||
| $this->andWhere(['status' => 1]); | ||
|  | ||
| return $this; | ||
| } | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\032octal is a substitute character. It's not a simple one so this needs to be checked if there's any threat in not escaping it.