Can’t delete related record with date as primary key

Archived from the Xataface Users forum.

stephane — Tue Sep 18, 2012 3:59 pm

Hi,

I have an Exception ‘Attempt to use array in query clause’ when I try to delete a selected related record.
The (related) table is :

Code: Select all
CREATE TABLE rtable (   id_test int(11) NOT NULL,   the_date date NOT NULL,   field3 varchar(20) DEFAULT NULL,   PRIMARY KEY (id_test,the_date) )

id_test is my foreign key pointing to the field ‘id’ from the table ‘test’ :

Code: Select all
[myrelation] rtable.id_test = "$id"

I think that the date is presented as an array when building the where clause.
This exception is thrown only when I try to delete the related record from the related list, using check box and action “with selected -> remove”.
Everything goes fine if I delete the related record from its view tab.

I use Xataface 1.3.2

Best Regards


shannah — Mon Sep 24, 2012 9:28 am

Can you post the exception error readout?


stephane — Tue Sep 25, 2012 1:44 pm

Sure. Here it is :

PHP Fatal error: Uncaught exception ‘Exception’ with message ‘Attempt to use array in query clause’ in D:\dev\www\test_xataface\xataface\Dataface\QueryBuilder.php:503
Stack trace:
#0 D:\dev\www\test_xataface\xataface\Dataface\QueryBuilder.php(665): Dataface_QueryBuilder->_fieldWhereClause(Array, Array, true, ‘rtable’)
#1 D:\dev\www\test_xataface\xataface\Dataface\QueryBuilder.php(229): Dataface_QueryBuilder->_where(Array)
#2 D:\dev\www\test_xataface\xataface\Dataface\IO.php(197): Dataface_QueryBuilder->select(‘’, Array, false, ‘rtable’)
#3 D:\dev\www\test_xataface\xataface\Dataface\IO.php(1687): Dataface_IO->read(Array, Object(Dataface_Record))
#4 D:\dev\www\test_xataface\xataface\Dataface\RemoveRelatedRecordForm.php(321): Dataface_IO->removeRelatedRecord(Object(Dataface_RelatedRecord), ‘1’, true)
#5 [internal function]: Dataface_RemoveRelatedRecordForm->delete(Array)
#6 D:\dev\www\test_xataface\xataface\lib\HTML\QuickForm.php(1626): call_user_func(Array, Array)
#7 D:\dev\www\test_xataface\xataface\actions\remove_related_reco in D:\dev\www\test_xataface\xataface\Dataface\QueryBuilder.php on line 503

Do you want me to attach a zip with a small sample that brings out the issue ?


shannah — Tue Sep 25, 2012 2:25 pm

Thanks. I have fixed this in SVN. I have also posted a bug report with details of the fix at
http://bugs.weblite.ca/view.php?id=1158

Here is a diff of the 1.3.x branch if you want to just make a fix in your version.

Code: Select all
d142-58-249-174:xataface-1.3.x shannah$ svn diff -r 4104:4105 Index: Dataface/IO.php =================================================================== --- Dataface/IO.php   (revision 4104) +++ Dataface/IO.php   (revision 4105) @@ -1690,7 +1690,7 @@       $currKeyNames = array_keys($domainTable->keys());          // Names of key fields in the domain table       foreach ($currKeyNames as $keyName){ -         $query[$keyName] = $related_record->val($keyName); +         $query[$keyName] = $related_record->strval($keyName);          $absVals[$domainTable->tablename.'.'.$keyName] = $query[$keyName];       }

Notice that there is only one line changed. A val() to a strval()

_Steve


stephane — Tue Sep 25, 2012 3:01 pm

Don’t thank me… Many thanks to you ! You saved me so much hours of work.
Your work is really great and the way you handle is really professional.
In a few words: I’m a fan.