[ Index ]
 

Code source de PHP PEAR 1.4.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/tests/DB/tests/driver/ -> mktable.inc (source)

   1  <?php
   2  
   3  /**
   4   * Creates the <kbd>phptest</kbd> table
   5   *
   6   * Tries to drop the table first, in case it already exists.
   7   *
   8   * <pre>
   9   * CREATE TABLE phptest (
  10   *   a INTEGER NULL,
  11   *   b CHAR(40) DEFAULT 'def' NOT NULL,
  12   *   cc VARCHAR(255) NULL,
  13   *   d VARCHAR(20) NULL)
  14   * </pre>
  15   *
  16   * Need <kbd>NOT NULL</kbd> on <kbd>b</kbd> to test
  17   * <kbd>DB_PORTABILITY_RTRIM</kbd>.  MS SQL and Sybase trim output from
  18   * <kbd>VARCHAR</kbd>, but not on <kbd>CHAR</kbd>.
  19   *
  20   * Need <kbd>DEFAULT</kbd> value on <kbd>b</kbd> because Oracle considers
  21   * an empty string to be <kbd>NULL</kbd>.
  22   *
  23   * In Oracle, when using placeholders in <kbd>WHERE</kbd> clauses on 
  24   * <kbd>CHAR</kbd> columns, the column must have <kbd>RTRIM()</kbd> run on
  25   * the column:
  26   * <samp>
  27   *    SELECT * FROM phptest WHERE RTRIM(b) = ?
  28   * </samp>
  29   *
  30   * PHP versions 4 and 5
  31   *
  32   * LICENSE: This source file is subject to version 3.0 of the PHP license
  33   * that is available through the world-wide-web at the following URI:
  34   * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  35   * the PHP License and are unable to obtain it through the web, please
  36   * send a note to license@php.net so we can mail you a copy immediately.
  37   *
  38   * @category   Database
  39   * @package    DB
  40   * @author     Daniel Convissor <danielc@php.net>
  41   * @copyright  1997-2005 The PHP Group
  42   * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  43   * @version    $Id: mktable.inc,v 1.20 2007/01/05 15:12:56 danielc Exp $
  44   * @link       http://pear.php.net/package/DB
  45   */
  46  
  47  /**
  48   * Establishes the DB object and connects to the database
  49   */
  50  require_once  './connect.inc';
  51  
  52  /**
  53   * Get the drop_table() function
  54   */
  55  require_once './droptable.inc';
  56  
  57  /**
  58   * The error handler for the drop table procedure
  59   *
  60   * Prints out an error message and dies.
  61   */
  62  function debug_die($o){
  63      die($o->toString());
  64  }
  65  
  66  
  67  $dbh->setErrorHandling(PEAR_ERROR_RETURN);
  68  drop_table($dbh, 'phptest');
  69  
  70  //$dbh->setErrorHandling(PEAR_ERROR_TRIGGER);
  71  $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'debug_die');
  72  
  73  if ($dbh->phptype == 'odbc') {
  74      if ($dbh->dbsyntax == 'odbc') {
  75          $type = $dbh->phptype;
  76      } else {
  77          $type = $dbh->dbsyntax;
  78      }
  79  } else {
  80      $type = $dbh->phptype;
  81  }
  82  
  83  
  84  switch ($type) {
  85      case 'access':
  86          $null = 'NULL';
  87          $chrc = 'VARCHAR(255)';
  88          $chrd = 'VARCHAR(20)';
  89          $default = '';
  90          $tabletype = '';
  91          break;
  92      case 'db2':
  93      case 'ibase':
  94          $null = '';
  95          $chrc = 'VARCHAR(255)';
  96          $chrd = 'VARCHAR(20)';
  97          $default = "DEFAULT 'def' NOT NULL";
  98          $tabletype = '';
  99          break;
 100      case 'fbsql':
 101          $null = '';
 102          $chrc = 'CHAR(255)';
 103          $chrd = 'CHAR(20)';
 104          $default = "DEFAULT 'def' NOT NULL";
 105          $date_literal = ' DATE ';
 106          $tabletype = '';
 107          break;
 108      case 'ifx':
 109          // doing this for ifx to keep certain versions happy
 110          $null = '';
 111          $chrc = 'CHAR(255)';
 112          $chrd = 'CHAR(20)';
 113          $default = "DEFAULT 'def' NOT NULL";
 114          $tabletype = '';
 115          break;
 116      case 'msql':
 117          $null = '';
 118          $chrc = 'CHAR(255)';
 119          $chrd = 'CHAR(20)';
 120          $default = '';
 121          $tabletype = '';
 122          break;
 123      case 'mysql':
 124      case 'mysqli':
 125          $null = 'NULL';
 126          $chrc = 'VARCHAR(255)';
 127          $chrd = 'VARCHAR(20)';
 128          $default = "DEFAULT 'def' NOT NULL";
 129          if (!empty($needinnodb)) {
 130              $tabletype = 'TYPE=INNODB';
 131          } else {
 132              $tabletype = '';
 133          }
 134          break;
 135      default:
 136          $null = 'NULL';
 137          $chrc = 'VARCHAR(255)';
 138          $chrd = 'VARCHAR(20)';
 139          $default = "DEFAULT 'def' NOT NULL";
 140          $tabletype = '';
 141  }
 142  
 143  switch ($dbh->phptype) {
 144      case 'dbase':
 145          // file exists or was created in DB_dbase::connect()
 146          break;
 147      default:
 148          $test_mktable_query = "
 149              CREATE TABLE phptest (
 150                a INTEGER $null,
 151                b CHAR(40) $default,
 152                cc $chrc $null,
 153                d $chrd $null) $tabletype
 154          ";
 155  }
 156  
 157  
 158  $dbh->query($test_mktable_query);
 159  $dbh->query("INSERT INTO phptest VALUES(42, 'bing', 'This is a test', '1999-11-21')");
 160  
 161  $dbh->setErrorHandling(PEAR_ERROR_RETURN);


Généré le : Sun Feb 25 14:08:00 2007 par Balluche grâce à PHPXref 0.7