32 import(
'Dataface/Table.php');
33 import(
'Dataface/Error.php');
34 import(
'Dataface/Serializer.php');
35 import(
'Dataface/DB.php');
37 define(
'QUERYBUILDER_ERROR_EMPTY_SELECT', 1);
133 $this->_query = is_array($query) ? $query : array();
134 $this->_fields =& $this->_table->fields(
false,
true);
135 $this->_mutableFields =& $this->_table->fields();
137 $this->action = null;
140 if ( @
$app->_conf[
'metadata_enabled'] ){
141 $this->metadata =
true;
144 $keys = array_keys( $this->_query );
145 foreach (
$keys as $key){
146 if ( $this->_query[$key] ===
''){
147 unset( $this->_query[$key] );
153 $this->_security =
$GLOBALS[
'DATAFACE_QUERYBUILDER_SECURITY_CONSTRAINTS'][
$tablename];
159 function _opt($code, $isText=
true){
193 $this->action=
'search';
195 $from = trim($this->
_from($this->_table->tablename));
196 $indexOnly = ( (isset($queryParams[
'-ignoreIndex']) and $queryParams[
'-useIndex']) ?
false :
true );
197 $where =
"WHERE ".$this->_match($queryStr, $indexOnly);
198 $from = trim( $this->
_from($this->_table->tablename));
199 $order = trim($this->
_orderby($queryParams));
200 $limit = trim($this->
_limit($queryParams, $nolimit));
201 if ( strlen($from)>0 ) $ret .=
' '.$from;
202 if ( strlen($where)>0 ) $ret .=
' '.$where;
203 if ( strlen($order)>0 ) $ret .=
' '.$order;
204 if ( strlen($limit)>0 ) $ret .=
' '.$limit;
205 $this->action = null;
216 $this->action=
"select";
217 if ( !is_array($query) ){
220 $query = array_merge( $this->_query, $query);
224 $ret->addUserInfo(
"Failed to select columns in select() ");
229 $where = trim($this->
_where($query));
230 $where = $this->
_secure($where);
233 $order = trim($this->
_orderby($query));
234 $limit = trim($this->
_limit($query, $nolimit));
236 if ( strlen($from)>0 ) $ret .=
' '.$from;
237 if ( strlen($where)>0 ) $ret .=
' '.$where;
239 if ( strlen($order)>0 ) $ret .=
' '.$order;
240 if ( strlen($limit)>0 ) $ret .=
' '.$limit;
241 $this->action = null;
254 $this->action=
'select_num_rows';
255 $query = array_merge( $this->_query, $query);
256 $ret =
'SELECT COUNT(*) as num';
258 $where = $this->
_where($query);
259 $where = $this->
_secure($where);
261 if ( strlen($from)>0 ) $ret .=
' '.$from;
262 if ( strlen($where)>0 ) $ret .=
' '.$where;
263 $this->action = null;
278 $this->action=
'update';
280 if ( !is_a($record,
"Dataface_Record") ){
281 throw new Exception(
"Attempt to use QueryBuilder::update() where something other than a Dataface_Record object is defined.", E_USER_ERROR);
290 $sql[] =
"UPDATE `".$this->tablename(
$tablename).
"` SET ";
291 $fieldnames = array_keys($this->_mutableFields);
293 $keys = array_keys($this->_table->keys());
298 if ( isset($fieldArr) ) unset($fieldArr);
299 $fieldArr =& $tableObj->getField($fieldname);
300 if ( @$fieldArr[
'ignore'] )
continue;
301 if ( !$record->valueChanged($fieldname) and !(isset($fieldArr[
'timestamp']) and strtolower($fieldArr[
'timestamp']) ==
'update') ) {
308 if ( $tableObj->isVersioned() and $tableObj->getVersionField() ===
$fieldname ){
316 $sval = $this->_serializer->serialize($fieldname, $record->getValue($fieldname));
318 if ( !isset($sval) and @$fieldArr[
'timestamp'] !=
'update' ){
319 $sql[] =
"`$fieldname` = NULL, ";
320 }
else if ( $tableObj->isBlob($fieldname) and @
$app->_conf[
'multilingual_content']){
324 $blobID = $dbObj->registerBlob($sval);
325 $sql[] =
"`$fieldname` = '-=-=B".$blobID.
"=-=-', ";
326 }
else if ( $tableObj->isDate($fieldname) and
327 isset($fieldArr[
'timestamp']) and
328 strtolower($fieldArr[
'timestamp']) ==
'update'){
329 $sql[] =
"`$fieldname` = NOW(), ";
332 $sql[] =
"`$fieldname` = ".$this->prepareValue($fieldname, $sval).
", ";
335 if ( !$changed )
return '';
337 if ( $tableObj->isVersioned() ){
338 $versionField = $tableObj->getVersionField();
339 $sql[] =
"`$versionField` = ifnull(`$versionField`,0)+1, ";
342 $sql[count($sql)-1] = substr($sql[count($sql)-1], 0, strlen($sql[count($sql)-1])-2);
344 $vals = $record->snapshotExists() ? $record->snapshotKeys() : $record->getValues( array_keys($this->_table->keys()));
347 if ( $key_vals === null ){
348 $query = unserialize(serialize($vals));
349 foreach ( array_keys($query) as $qkey){
350 $query[$qkey] =
"=".$this->_serializer->serialize($qkey, $query[$qkey]);
354 foreach (array_keys($query) as $qkey){
355 $query[$qkey] =
"=".$query[$qkey];
359 $sql[] =
" ".$this->_where($query);
364 $sql = implode($sql);
366 $this->action = null;
375 $this->action =
'insert';
376 if ( !is_a($record,
"Dataface_Record") ){
377 throw new Exception(
"First argument to QueryBuilder::insert() must be of type Dataface_Record, but received ".get_class($record), E_USER_ERROR);
382 $fields = array_keys($this->_mutableFields);
383 $keys =& $this->_table->keys();
384 $insertedKeys = array();
385 $insertedValues = array();
387 foreach ($this->_mutableFields as $key=>
$field){
388 if ( @
$field[
'ignore'] )
continue;
389 if ( $tableObj->isDate($key) ){
391 if (isset($fieldArr)) unset($fieldArr);
392 $fieldArr =& $tableObj->getField($key);
393 if ( isset($fieldArr[
'timestamp']) and in_array(strtolower($fieldArr[
'timestamp']), array(
'insert',
'update')) ){
394 $insertedKeys[] =
'`'.$key.
'`';
395 $insertedValues[] =
'NOW()';
400 if ( !$record->hasValue($key) )
continue;
401 $val = $record->getValue($key);
402 if ( strtolower($this->_mutableFields[$key][
'Extra']) ==
'auto_increment' && !$val ){
407 if ( !isset($val))
continue;
408 $sval = $this->_serializer->serialize($key, $record->getValue($key) );
410 if ( $tableObj->isBlob($key) and @
$app->_conf[
'multilingual_content'] ){
411 $blobID = $dbObj->registerBlob($sval);
412 $sval2 =
"-=-=B".$blobID.
"=-=-";
417 if ( strlen(strval($sval2)) == 0 and strtolower($this->_mutableFields[$key][
'Null']) ==
'yes' ){
418 $insertedKeys[] =
'`'.$key.
'`';
419 $insertedValues[] =
'NULL';
422 $insertedKeys[] =
'`'.$key.
'`';
428 $sql =
"INSERT INTO `".$this->tablename(
$tablename).
"` (".
429 implode(
',', $insertedKeys).
') VALUES ('.
430 implode(
',', $insertedValues).
')';
431 $this->action = null;
438 if ( $serialize ) $value = $this->_serializer->serialize(
$fieldname, $value);
439 if ( in_array( strtolower($this->_table->getType(
$fieldname)), array(
'timestamp',
'datetime')) ){
440 $value =
"ifnull(convert_tz('".addslashes($value).
"','".addslashes(df_tz_or_offset()).
"','SYSTEM'),'".addslashes($value).
"')";
443 if ( $quotes ) $value =
"'".addslashes($value).
"'";
444 $value = $this->_serializer->encrypt(
$fieldname,$value);
451 function delete($query=array(), $nolimit=
false,
$tablename=null){
452 $this->action =
'delete';
456 $query = array_merge($this->_query, $query);
458 $parent =&
$table->getParent();
459 if ( isset($tsql) or isset($parent)){
461 $joinclause = array();
462 foreach ( array_keys(
$table->keys() ) as $tkey){
463 $joinclause[] =
"`$talias`.`$tkey`=`$tablename`.`$tkey`";
465 $joinclause = implode(
' AND ', $joinclause);
466 $from =
"FROM `{$talias}` USING `{$tablename}` as `{$talias}` left join ".substr($this->
_from(
$tablename), 5).
" on ($joinclause)";
472 $where = $this->
_where($query);
473 $limit = $this->
_limit($query, $nolimit);
474 $ret =
"DELETE ".$from;
476 if ( strlen($where)>0 ) $ret .=
' '.$where;
477 if ( strlen($limit)>0 ) $ret .=
' '.$limit;
478 $this->action = null;
485 if ( in_array($this->action, array(
'select',
'delete',
'select_num_rows')) ){
486 return "`{$tablename}`.`{$colname}`";
488 return "`{$colname}`";
496 $changeTable =
false;
497 if ( $this->_table->tablename !=
$table->tablename ){
500 unset($this->_table);
503 unset($this->_serializer);
506 if ( !isset($tableAlias) ) $tableAlias =
$table->tablename;
507 if ( is_array($value) ){
508 throw new Exception(
"Attempt to use array in query clause");
510 $words = explode(
' OR ', $value);
511 if ( count($words) > 1){
525 foreach ($words as $value){
526 if ( $value ===
'' )
continue;
528 if ( $value{0}==
'=' ){
530 $value = substr($value,1);
534 $factors = explode(
' AND ', $value);
535 if ( count($factors) > 1 ){
538 foreach ($factors as $value){
539 if ( !$exact and (strpos($value,
'!=')===0 or strpos($value,
'<>') === 0)){
540 $value = substr($value, 2);
543 $where .= $this->
wc($tableAlias, $key).
" NOT RLIKE CONCAT('[[:<:]]',$value,'[[:>:]]') AND ";
545 $where .= $this->
wc($tableAlias, $key).
" <> $value AND ";
550 }
else if ( !$exact and strpos($value,
'<')===0){
551 if ( strpos($value,
'=') === 1 ){
552 $value = substr($value,2);
555 $value = substr($value, 1);
559 $where .= $this->
wc($tableAlias, $key).
" $op $value AND ";
562 }
else if ( !$exact and strpos($value,
'>')===0 ) {
563 if ( strpos($value,
'=') === 1 ){
564 $value = substr($value,2);
567 $value = substr($value, 1);
571 $where .= $this->
wc($tableAlias, $key).
" $op $value AND ";
575 }
else if ( !$exact and strpos($value,
'..')> 0 ){
576 list($low,$high) = explode(
'..',$value);
577 $low = trim($low); $high = trim($high);
580 $where .= $this->
wc($tableAlias, $key).
" >= $low AND ".$this->
wc($tableAlias, $key).
" <= $high AND ";
581 }
else if ( !$exact and strpos($value,
'~') === 0 ){
582 $value = substr($value,1);
586 if ( strlen($oldval) > 0 ){
587 $where .= $this->
wc($tableAlias,$key).
" $oper $value AND ";
589 $where .=
'('.$this->wc($tableAlias,$key).
" $oper '' OR ".$this->
wc($tableAlias,$key).
" IS NULL) AND ";
593 }
else if ( $repeat ){
595 $where .= $this->
wc($tableAlias, $key).
" RLIKE CONCAT('[[:<:]]',$value,'[[:>:]]') AND ";
598 else if ( $this->_exactMatches || preg_match(
'/int/i', $field[
'Type']) || $exact ){
602 if ( strlen($oldval) > 0 ){
603 $where .= $this->
wc($tableAlias,$key).
" $oper $value AND ";
605 $where .=
'('.$this->wc($tableAlias,$key).
" $oper '' OR ".$this->
wc($tableAlias,$key).
" IS NULL) AND ";
609 $where .= $this->
wc($tableAlias, $key).
" LIKE CONCAT('%',$value,'%') AND ";
613 $where = substr($where, 0, strlen($where)-5);
614 if (count($factors) > 1){
622 $where = substr($where, 0, strlen($where)-4);
623 if ( count($words) > 1){
629 unset($this->_table);
630 $this->_table =& $oldTable;
631 unset($this->_serializer);
632 $this->_serializer =& $oldSerializer;
644 function _where($query=array(), $merge=
true){
646 $query = array_merge( $this->_query, $query);
649 foreach ($query as $key=>$value) {
650 if ( $value === null or $value ===
'' ){
655 if ( isset($query[
'__id__']) ){
656 $keys = array_keys($this->_table->keys());
658 $query[
$keys[0]] = $query[
'__id__'];
659 unset($query[
'__id__']);
666 $missing_key =
false;
672 foreach ($query as $key=>$value){
673 if ( strpos($key,
'-') !== 0 )
$fields[$key] = $value;
675 foreach (
$fields as $key=>$value){
676 if ( isset($this->_fields[$key]) ){
677 $field =& $this->_fields[$key];
678 if ( !@
$field[
'not_findable'] ){
685 $charFields = $this->_table->getCharFields(
true,
true);
686 if ( isset( $query[
'-search'] ) and strlen($query[
'-search']) and count($charFields)>0 ){
687 $status = $this->_table->getStatus();
693 $words = explode(
' ', $query[
'-search']);
694 foreach ( $words as $word ){
695 $where .=
'(`'.implode(
'` LIKE \'%'.addslashes($word).
'%\' OR `', $charFields).
'` LIKE \'%'.addslashes($word).
'%\') AND ';
702 if ( $this->metadata ){
703 $wfkeys = preg_grep(
'/^_metadata::/', array_keys($query));
705 foreach ($wfkeys as $wfkey){
706 $wf_col = substr($wfkey,11);
707 if ( !$this->_table->fieldExists($wf_col) )
continue;
708 $wf_col = $this->_tablename.
"__metadata.__{$wf_col}";
709 $clause[] =
"`{$wf_col}`='".addslashes($query[$wfkey]).
"'";
711 if ( count($clause)>0 ){
713 $where .= implode(
' AND ', $clause).
' AND ';
718 $rkeys = preg_grep(
'/^[^\-].*\/.*$/', array_keys($query));
721 foreach ($rkeys as $rkey ){
722 list($relationship, $rfield) = explode(
'/', $rkey);
723 $rquery[$relationship][] = $rfield;
727 foreach ( $rquery as $rname=>$rfields){
728 $r =& $this->_table->getRelationship($rname);
736 foreach ( $rfields as $rfield ){
737 $rfieldDef =& $r->getField($rfield);
738 $q = $query[$rname.
'/'.$rfield];
739 $ralias = $r->getTableAlias($rfieldDef[
'tablename']);
740 if ( !$ralias ) $ralias = null;
747 $subwhere =
' AND '.implode(
' AND ',$pairs);
752 $fkeys = $r->getForeignKeyValues();
753 foreach ( $fkeys as $tname=>$tfields ){
754 foreach ( $tfields as $tval ){
755 if ( !is_scalar($tval) )
continue;
756 if ( strlen($tval) > 0 ) $tval = substr($tval,1);
757 $sql = preg_replace(
'/[\'"]?\$('.preg_quote($tval).
')[\'"]?/',
'`'.str_replace(
'`',
'',$this->_table->tablename).
'`.`\1`', $sql);
760 $where .=
'EXISTS ('.$sql.$subwhere.
') AND ';
770 $where = substr($where,0, strlen($where)-5);
789 $proxyView =
$table->getProxyView();
793 $fromq =
"`".$proxyView.
"`";
794 }
else if ( isset($tsql) ){
795 $fromq =
"(".$tsql.
")";
797 $fromq =
"`".$this->tablename(
$tablename).
"`";
800 $parent =&
$table->getParent();
801 if ( isset($parent) ){
803 $pfrom = $qb2->_from();
804 $as_pos = ( ( strpos(strtolower($pfrom),
' as ') !== false ) ? (strlen($pfrom) - strpos(strrev(strtolower($pfrom)),
' sa ' )-3) :
false);
805 if ( $as_pos !==
false ){
806 $pfrom = substr($pfrom, strlen(
'FROM '), $as_pos-strlen(
'FROM '));
808 $pfrom = substr($pfrom, strlen(
'FROM '));
810 $pkeys = array_keys($parent->keys());
811 $ckeys = array_keys(
$table->keys());
813 for ($i=0; $i<count($pkeys); $i++){
814 $joinq[] =
'`t___child`.`'.$ckeys[$i].
'`=`t___parent`.`'.$pkeys[$i].
'`';
816 $joinq = implode(
' and ', $joinq);
819 $out =
"FROM (select * from ".$fromq.
" as `t___child` left join ".$pfrom.
" as `t___parent` on ($joinq)) as `".$this->
tablename(
$tablename).
"`" ;
822 }
else if ( isset($tsql) or isset($proxyView) ){
825 $out =
"FROM ".$fromq;
831 if ( $this->metadata and $this->action ==
'select') {
832 $out .=
" LEFT JOIN `{$tablename}__metadata` ON ";
834 if ( count(
$keys) == 0 )
throw new Exception(
"The table '".
$tablename.
"' has no primary key.", E_USER_ERROR);
837 foreach (
$keys as $key ){
838 $clauses[] =
"`{$tablename}`.`{$key}`=`{$tablename}__metadata`.`{$key}`";
840 $out .=
"(".implode(
' and ', $clauses).
")";
852 if ( !isset($previewLen) and defined(
'XATAFACE_DEFAULT_PREVIEW_LENGTH') and is_int(XATAFACE_DEFAULT_PREVIEW_LENGTH) ){
853 $previewLen = XATAFACE_DEFAULT_PREVIEW_LENGTH;
855 if ( !is_int($previewLen) ) $previewLen = 255;
857 $query = array_merge( $this->_query, $query);
858 foreach ($query as $key=>$value) {
859 if ( $value === null ){
865 foreach ($this->_fields as $key=>
$field){
866 if ( $this->selectMetaData ){
867 $select .=
"length(`{$this->_tablename}`.`".$key.
"`) as `__".$key.
"_length`,";
875 if ( $this->_omitBlobs and $this->_table->isBlob(
$field[
'name']) )
continue;
877 if ( $this->_omitPasswords and $this->_table->isPassword(
$field[
'name']) )
continue;
879 if ( $preview and $this->_table->isText(
$field[
'name']) and !@
$field[
'struct'] and !$this->_table->isXML(
$field[
'name']))
880 $select .=
"SUBSTRING(`{$this->_tablename}`.`$key`, 1, ".$previewLen.
") as `$key`,";
881 else if ( in_array(strtolower($this->_table->getType($key)),array(
'datetime',
'timestamp')) )
882 $select .=
"ifnull(convert_tz(`".$this->_tablename.
"`.`".$key.
"`, 'SYSTEM', '".df_tz_or_offset().
"'), `".$this->_tablename.
"`.`".$key.
"`) as `$key`,";
884 $select .=
"`{$this->_tablename}`.`$key`,";
888 if ( $this->metadata) {
890 foreach ( $this->_table->getMetadataColumns() as $mdc ){
891 $clauses[] =
"`{$this->_tablename}__metadata`.`{$mdc}`";
893 $select .= implode(
',',$clauses).
',';
897 if ( $colcount == 0 ){
898 return PEAR::raiseError(
QUERYBUILDER_ERROR_EMPTY_SELECT, null,null,null,
"No columns were selected in select statement. Make sure that _omitBlobs property is disabled in QueryBuilder object if you are only wanting to return Blob columns.");
900 $select = substr($select, 0, strlen($select) -1);
908 function _limit($query=array(), $nolimit=
false){
909 if ( $nolimit )
return '';
910 $query = array_merge( $this->_query, $query);
911 foreach ($query as $key=>$value) {
912 if ( $value === null ){
918 if ( isset( $query[
'-limit']) && isset($query[
'-skip'] ) ){
919 if ( preg_match(
'/^[0-9]+$/',$query[
'-limit']) &&
920 preg_match(
'/^[0-9]+$/',$query[
'-skip']) ){
921 $limit =
"LIMIT ".$query[
'-skip'].
",".$query[
'-limit'];
923 }
else if ( isset( $query[
'-limit'] ) ){
924 if ( preg_match(
'/^[0-9]+$/', $query[
'-limit']) ){
925 $limit =
"LIMIT ".$query[
'-limit'];
927 }
else if ( isset( $query[
'-skip']) ){
928 if ( preg_match(
'/^[0-9]+$/', $query[
'-skip']) ){
929 $limit =
"LIMIT ".$query[
'-skip'].
", 100";
940 $query = array_merge( $this->_query, $query);
941 foreach ($query as $key=>$value) {
942 if ( $value === null ){
947 if ( isset($query[
'-sort']) ){
949 return 'ORDER BY '.preg_replace_callback(
'/\b(\w+?)\b/',array(&$this,
'_mysql_quote_idents'), $query[
'-sort']);
956 if (!in_array(strtolower($matches[1]), array(
'asc',
'desc') ) ){
957 return '`'.((strpos($matches[1],
'.') ===
false) ?
"{$this->_tablename}`.`":
'').$matches[1].
'`';
981 $version = mysql_get_server_info();
983 preg_match(
'/(\d+)\.(\d)+\.(\d)+/', $version, $matches);
984 $majorVersion = intval($matches[1]);
988 $queryStr = addslashes($queryStr);
989 $queryStr = str_replace(
'\"',
'"', $queryStr);
994 $indexedFields =& $this->_table->getFullTextIndexedFields();
995 if ( count($indexedFields)>0){
999 $fields =& $this->_table->getCharFields();
1006 $out .=
"`{$this->_tablename}`.`$field`,";
1012 throw new Exception(
"Query attempted when no queryable columns are available in table '".$this->_table->tablename.
"'. Only tables with a full-text search defined on at least one column are eligiblle to be searched in this way.", E_USER_ERROR);
1017 $out .=
") AGAINST ('$queryStr'";
1018 if ( $majorVersion >= 4 ) {
1019 $out .=
" IN BOOLEAN MODE";
1030 $this->_omitBlobs =
true;
1034 $this->_omitBlobs =
false;
1040 $this->_security[$key] = $value;
1046 $this->_security = array_merge($this->_security, $constraints);
1051 unset( $this->_security[$key] );
1055 $this->_security = $constraints;
1060 $swhere = $this->
_where($this->_table->getSecurityFilter($this->_security),
false);
1062 $swhere = trim(substr($swhere, 5, strlen($swhere)-5));
1064 $where = trim($where);
1065 if ( strlen($where)>0 ){
1066 if (strlen($swhere)>0) {
1067 $where .=
" AND ".$swhere;
1069 }
else if ( strlen($swhere)>0){
1070 $where =
"WHERE $swhere";
1083 if ( !is_a($relatedRecord,
'Dataface_RelatedRecord') ){
1084 throw new Exception(
"In QueryBuilder::addRelatedRecord() expecting first argument to be type 'Dataface_RelatedRecord' but received '".get_class($relatedRecord).
"'\n<br>", E_USER_ERROR);
1086 $relationship =& $relatedRecord->_relationship;
1087 $table_cols = $relatedRecord->getForeignKeyValues( $sql);
1088 if ( count($this->errors) > 0 ){
1089 $error = array_pop($this->errors);
1090 $error->addUserInfo(
"Error getting foreign key values for relationship '$relationship_name'");
1091 throw new Exception($error->toString());
1100 foreach ( $table_cols as
$table=>$cols ){
1101 if ( isset($recordObj) ) unset($recordObj);
1103 $recordVals =& $recordObj->vals();
1104 if ( isset( $recordVals[ $recordObj->_table->getAutoIncrementField() ] ) ){
1107 $recordObj->setValue($recordObj->_table->getAutoIncrementField(), null);
1110 $sql[
$table] = $qb->insert($recordObj);
1120 $record =& $relatedRecord->_record;
1121 $relationshipName =& $relatedRecord->_relationshipName;
1122 $values = $relatedRecord->getAbsoluteValues(
true);
1123 if ( !is_a($record,
'Dataface_Record') ){
1124 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);
1126 if ( !is_array($values) ){
1127 throw new Exception(
"In Dataface_QueryBuilder::addExistingRelatedRecord() expected third argument to be an array but received a scalar.", E_USER_ERROR);
1129 $relationship =& $record->_table->getRelationship($relationshipName);
1130 $foreignKeys = $relationship->getForeignKeyValues();
1131 $foreignKeys_withValues = $relatedRecord->getForeignKeyValues();
1133 if ( count($this->errors) > 0 ){
1134 $error = array_pop($this->errors);
1135 $error->addUserInfo(
"Error getting foreign key values for relationship '$relationship_name'");
1136 throw new Exception($error->toString());
1140 foreach ($foreignKeys as
$table=>$cols){
1142 foreach ($cols as $field_name=>$field_value){
1143 if ( $field_value !=
"__".
$table.
"__auto_increment__" ) {
1148 if ( $skip )
continue;
1149 $cols = $foreignKeys_withValues[
$table];
1150 if ( isset($recordObj) ) unset($recordObj);
1152 $recordVals =& $recordObj->vals();
1153 if ( isset( $recordVals[ $recordObj->_table->getAutoIncrementField() ] ) ){
1156 $recordObj->setValue($recordObj->_table->getAutoIncrementField(), null);
1159 $sql[
$table] = $qb->insert($recordObj);