home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / phpMyAdmin / libraries / db_routines.inc.php < prev    next >
Encoding:
PHP Script  |  2007-12-20  |  4.2 KB  |  89 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  *
  5.  * @version $Id: db_routines.inc.php 10562 2007-08-18 12:06:51Z lem9 $
  6.  */
  7.  
  8. /**
  9.  * @todo Support seeing the "results" of the called procedure or
  10.  *       function. This needs further reseach because a procedure
  11.  *       does not necessarily contain a SELECT statement that
  12.  *       produces something to see. But it seems we could at least
  13.  *       get the number of rows affected. We would have to
  14.  *       use the CLIENT_MULTI_RESULTS flag to get the result set
  15.  *       and also the call status. All this does not fit well with
  16.  *       our current sql.php.
  17.  *       Of course the interface would need a way to pass calling parameters.
  18.  *       Also, support DEFINER (like we do in export).
  19.  */
  20. if (PMA_MYSQL_INT_VERSION >= 50002) {
  21.     $url_query .= '&goto=db_structure.php';
  22.  
  23.     $routines = PMA_DBI_fetch_result('SELECT SPECIFIC_NAME,ROUTINE_NAME,ROUTINE_TYPE,DTD_IDENTIFIER FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA= \'' . PMA_sqlAddslashes($db,true) . '\';');
  24.  
  25.     if ($routines) {
  26.         echo '<fieldset>' . "\n";
  27.         echo ' <legend>' . $strRoutines . '</legend>' . "\n";
  28.         echo '<table border="0">';
  29.         echo sprintf('<tr>
  30.                           <th>%s</th>
  31.                           <th> </th>
  32.                           <th> </th>
  33.                           <th>%s</th>
  34.                           <th>%s</th>
  35.                     </tr>',
  36.               $strName,
  37.               $strType,
  38.               $strRoutineReturnType);
  39.         $ct=0;
  40.         $delimiter = '//';
  41.         foreach ($routines as $routine) {
  42.  
  43.             // information_schema (at least in MySQL 5.0.45)
  44.             // does not return the routine parameters
  45.             // so we rely on PMA_DBI_get_procedure_or_function_def() which
  46.             // uses SHOW CREATE
  47.  
  48.             $definition = 'DROP ' . $routine['ROUTINE_TYPE'] . ' ' . PMA_backquote($routine['SPECIFIC_NAME']) . $delimiter . "\n"
  49.                 .  PMA_DBI_get_procedure_or_function_def($db, $routine['ROUTINE_TYPE'], $routine['SPECIFIC_NAME'])
  50.                 . "\n";
  51.  
  52.             //if ($routine['ROUTINE_TYPE'] == 'PROCEDURE') {
  53.             //    $sqlUseProc  = 'CALL ' . $routine['SPECIFIC_NAME'] . '()';
  54.             //} else {
  55.             //    $sqlUseProc = 'SELECT ' . $routine['SPECIFIC_NAME'] . '()';
  56.                 /* this won't get us far: to really use the function
  57.                    i'd need to know how many parameters the function needs and then create
  58.                    something to ask for them. As i don't see this directly in
  59.                    the table i am afraid that requires parsing the ROUTINE_DEFINITION
  60.                    and i don't really need that now so i simply don't offer
  61.                    a method for running the function*/
  62.             //}
  63.             if ($routine['ROUTINE_TYPE'] == 'PROCEDURE') {
  64.                 $sqlDropProc = 'DROP PROCEDURE ' . PMA_backquote($routine['SPECIFIC_NAME']);
  65.             } else {
  66.                 $sqlDropProc = 'DROP FUNCTION ' . PMA_backquote($routine['SPECIFIC_NAME']);
  67.             }
  68.             echo sprintf('<tr class="%s">
  69.                               <td><b>%s</b></td>
  70.                               <td>%s</td>
  71.                               <td>%s</td>
  72.                               <td>%s</td>
  73.                               <td>%s</td>
  74.                          </tr>',
  75.                          ($ct%2 == 0) ? 'even' : 'odd',
  76.                          $routine['ROUTINE_NAME'],
  77.                          ! empty($definition) ? PMA_linkOrButton('db_sql.php?' . $url_query . '&sql_query=' . urlencode($definition) . '&show_query=1&delimiter=' . urlencode($delimiter), $titles['Structure']) : ' ',
  78.                          //$routine['ROUTINE_TYPE'] == 'PROCEDURE' ? '<a href="sql.php?' . $url_query . '&sql_query=' . urlencode($sqlUseProc) . '">' . $titles['Browse'] . '</a>' : ' ',
  79.                          '<a href="sql.php?' . $url_query . '&sql_query=' . urlencode($sqlDropProc) . '" onclick="return confirmLink(this, \'' . PMA_jsFormat($sqlDropProc, false) . '\')">' . $titles['Drop'] . '</a>',
  80.                          $routine['ROUTINE_TYPE'],
  81.                          $routine['DTD_IDENTIFIER']);
  82.             $ct++;
  83.         }
  84.         echo '</table>';
  85.         echo '</fieldset>' . "\n";
  86.     }
  87. }
  88. ?>
  89.