Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Streda, 25. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Need help with SQL expression

phpMyEdit General     Need help with SQL expression
Odoslať novú tému   Odpovedať na tému    
 
plemieux     Založený: 11.05.2005   Príspevky: 20  
Príspevok Zaslal: 2005-09-12 15:23
Návrat hore  Odpovedať s citátom     

I am dealing with a table with a large number of records (a list of course) in which there is a parent/child relationship. I don't want to reference the table to build a select menu because of the large number of records. Since each course has an arbitrary number used to identify it, I would like to make the user write this number as a reference and then convert it to the id when recording (in order to maintain referential integrity if the course number happens to change). Of course, I also need to convert it back to course number on read.

I tried:

Kód:
$opts['fdd']['parent'] = array(
  'name'     => 'Parent',
  'select'   => 'T',
  'maxlen'   => 10,
  'sort'     => true,
  'help'     => 'XXX-XXX-XX',
  'sql'      => '(select numero from cours where id = $val)',
  'sqlw'     => 'if($val!="",(select id from cours where numero = "$val"),$val)'
);


but neither read or write work...

 
plemieux     Založený: 11.05.2005   Príspevky: 20  
Príspevok Zaslal: 2005-09-12 16:58
Návrat hore  Odpovedať s citátom     

Ok. Done half the trip. The read subquery now work:

Kód:
$opts['fdd']['parent'] = array(
  'name'     => 'Cours parent (numéro)',
  'select'   => 'T',
  'maxlen'   => 10,
  'default'  => '0',
  'sort'     => true,
  'help'     => 'XXX-XXX-XX',
  'sql'      => 'parent as parentid, if(parent != 0, (select numero from cours where id = parentid), parent)',
  'sqlw'     => 'if($val != 0,(select id from cours where numero = "$val"),$val)'
);


The query needed a reference in order to work.

Now for the write, error message is:
Citácia:
You can't specify target table 'cours' for update in FROM clause


Any hints?

 
plemieux     Založený: 11.05.2005   Príspevky: 20  
Príspevok Zaslal: 2005-09-12 20:48
Návrat hore  Odpovedať s citátom     

Finally, I have found it cannot be done because:

Citácia:
Currently, you cannot update a table and select from the same table in a subquery.
http://dev.mysql.com/doc/mysql/en/update.html

Use a trigger instead.

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov