コード例 #1
0
ファイル: RecordTest.php プロジェクト: Zunair/xataface
 function test_init()
 {
     $record = new Dataface_Record('Profiles', array('id' => 3));
     $this->assertEquals(array('id' => 3), $record->vals(array('id')));
     $this->assertEquals(array('id' => 3), $record->values(array('id')));
     $this->assertEquals(array('id' => 3), $record->getValues(array('id')));
     $table =& $record->table();
     $keys = array_keys($table->fields());
     $expected = array();
     foreach ($keys as $key) {
         $expected[$key] = null;
     }
     $expected['id'] = 3;
     $this->assertEquals($expected, $record->vals());
 }
コード例 #2
0
ファイル: QueryBuilder.php プロジェクト: minger11/Pipeline
 function addExistingRelatedRecord(&$relatedRecord)
 {
     $record =& $relatedRecord->_record;
     $relationshipName =& $relatedRecord->_relationshipName;
     $values = $relatedRecord->getAbsoluteValues(true);
     if (!is_a($record, 'Dataface_Record')) {
         throw new Exception("In Dataface_QueryBuilder::addExistingRelatedRecord() expected first argument to be of type 'Dataface_Record' but received '" . get_class($record) . "'.\n<br>", E_USER_ERROR);
     }
     if (!is_array($values)) {
         throw new Exception("In Dataface_QueryBuilder::addExistingRelatedRecord() expected third argument to be an array but received a scalar.", E_USER_ERROR);
     }
     $relationship =& $record->_table->getRelationship($relationshipName);
     $foreignKeys = $relationship->getForeignKeyValues();
     $foreignKeys_withValues = $relatedRecord->getForeignKeyValues();
     if (count($this->errors) > 0) {
         $error = array_pop($this->errors);
         $error->addUserInfo("Error getting foreign key values for relationship '{$relationship_name}'");
         throw new Exception($error->toString());
     }
     $sql = array();
     foreach ($foreignKeys as $table => $cols) {
         $skip = true;
         foreach ($cols as $field_name => $field_value) {
             if ($field_value != "__" . $table . "__auto_increment__") {
                 $skip = false;
                 break;
             }
         }
         if ($skip) {
             continue;
         }
         $cols = $foreignKeys_withValues[$table];
         if (isset($recordObj)) {
             unset($recordObj);
         }
         $recordObj = new Dataface_Record($table, $cols);
         $recordVals =& $recordObj->vals();
         if (isset($recordVals[$recordObj->_table->getAutoIncrementField()])) {
             // We don't want the auto-increment field to be inserted - though it may
             // have a placeholder value.
             $recordObj->setValue($recordObj->_table->getAutoIncrementField(), null);
         }
         $qb = new Dataface_QueryBuilder($table);
         $sql[$table] = $qb->insert($recordObj);
         /*
         $skip = true;
         	// indicator to say whether or not to skip this table
         	// we skip the table if it contains an unresolved autoincrement value
         	
         foreach ($cols as $field_name=>$field_value){
         	if ( $field_value != "__".$table."__auto_increment__" ) {
         		$skip = false;
         		break;
         	}
         }
         
         if ( $skip == true ) continue;
         	
         
         $cols = $foreignKeys_withValues[$table];
         
         
         $query = "INSERT INTO `$table`";
         $colnames = "";
         $colvals = "";
         
         foreach ( $cols as $colname=>$colval){
         	$colnames .= $colname.',';
         	$colvals .= "'".addslashes($colval)."',";
         }
         
         $colnames = substr($colnames, 0, strlen($colnames)-1);
         $colvals = substr($colvals, 0, strlen($colvals)-1);
         
         $query .= " ($colnames) VALUES ($colvals)";
         
         $sql[$table] = $query;
         */
     }
     return $sql;
 }