From 31f951e49813543e91e8f33a8c6b8bacb5d40ad0 Mon Sep 17 00:00:00 2001 From: Martin Kamerbeek Date: Wed, 6 Sep 2006 14:11:06 +0000 Subject: [PATCH] some sqlform fixes --- docs/changelog/7.x.x.txt | 5 +++-- lib/WebGUI/Asset/Wobject/SQLForm.pm | 31 +++++++++++++++++------------ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 32ee0c13f..bc265bda4 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,8 +1,9 @@ 7.0.7 - fix: sqlform trunctate search results doesn't work (Martin Kamerbeek / Procolix) - - fixed some of bugs in the sqlform concerning file uploads and cross table - constraints (Martin Kamerbeek / Procolix) + - fixed some of bugs in the sqlform concerning file uploads, cross table + constraints and the join selector on non-key/value pair fields (Martin + Kamerbeek / Procolix) - fix: Add event does not work WebGUI 7.0.5 in combination with Proxy Caching turned off (Wouter van Oijen / ProcoliX) - When going to an image by it's webgui url in admin mode, you are now shown the image instead of being taken to the edit screen for the image. diff --git a/lib/WebGUI/Asset/Wobject/SQLForm.pm b/lib/WebGUI/Asset/Wobject/SQLForm.pm index 812a87896..fdf7434e1 100644 --- a/lib/WebGUI/Asset/Wobject/SQLForm.pm +++ b/lib/WebGUI/Asset/Wobject/SQLForm.pm @@ -1863,8 +1863,21 @@ sub www_editFieldSave { $processed->{joinConstraintColumn} = $self->session->form->process("joinConstraintColumn"); $processed->{joinConstraintField} = $self->session->form->process("joinConstraintField"); + # Process fieldType ---------------------------------------------------------------------------- +my ($dbFieldType, $formFieldType) = $self->session->db->quickArray('select dbFieldType, formFieldType from SQLForm_fieldTypes '. + ' where fieldTypeId='.$self->session->db->quote($self->session->form->process("fieldType"))); + if ($dbFieldType && $formFieldType) { + $processed->{dbFieldType} = $dbFieldType; + $processed->{formFieldType} = $formFieldType; + $processed->{fieldType} = $self->session->form->process("fieldType"); + } else { + push(@error, $i18n->get('efs field type error')); + } + # Process the join stuff ----------------------------------------------------------------------- - if ($self->session->form->process("table1") && !($self->session->form->process("selectField1") && $self->session->form->process("selectField2"))) { + if ($allowedFormFieldTypes->{$processed->{formFieldType}}->{hasOptions} && + $self->session->form->process("table1") && + !($self->session->form->process("selectField1") && $self->session->form->process("selectField2"))) { push(@error, $i18n->get('efs join populate error')); } if ($self->session->form->process("table1")) { @@ -1961,17 +1974,6 @@ my $subSelect = "select $joinAColumnName from $joinADatabaseName.$joinATa $processed->{sqlQueryAllOptions} .= " where ".join(' and ', @joinConstraints) if (@joinConstraints); } - # Process fieldType ---------------------------------------------------------------------------- -my ($dbFieldType, $formFieldType) = $self->session->db->quickArray('select dbFieldType, formFieldType from SQLForm_fieldTypes '. - ' where fieldTypeId='.$self->session->db->quote($self->session->form->process("fieldType"))); - if ($dbFieldType && $formFieldType) { - $processed->{dbFieldType} = $dbFieldType; - $processed->{formFieldType} = $formFieldType; - $processed->{fieldType} = $self->session->form->process("fieldType"); - } else { - push(@error, $i18n->get('efs field type error')); - } - # Check if fulltext search is allowed ---------------------------------------------------------- if ($self->session->form->process("useFulltext") && $allowedDbFieldTypes->{$processed->{dbFieldType}}->{supportsFulltext}) { $processed->{useFulltext} = 1; @@ -2515,7 +2517,9 @@ my $fieldConstraint = undef; if ($field->{fieldConstraintType} && $field->{fieldConstraintTarget} ne 'value') { my $sql = $field->{sqlQuery}; if ($field->{joinConstraintColumn}) { - $sql =~ s/^select/select $field->{fieldConstraintTarget},/; + #### This will still fail if a column is called 'from'. It's better to seperate the join construction + #### from the column selection. Even better would be giving the contraint settings their own join selector. + $sql =~ s/^select .+? from/select $field->{fieldConstraintTarget} from/; if ($sql =~ / where /) { $sql .= ' and '; } else { @@ -2524,6 +2528,7 @@ my $sql = $field->{sqlQuery}; $sql .= $field->{joinConstraintColumn} . ' = ' . $self->session->db->quote($self->session->form->process($self->_getFieldProperties($field->{joinConstraintField})->{fieldName})); } + my @results = $self->session->db->quickArray($sql); $fieldConstraint = $results[0]; }