Documentation TYPO3 par Ameos

test-datadict.php

00001 <?php
00002 /*
00003 
00004   V4.81 3 May 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
00005   Released under both BSD license and Lesser GPL library license. 
00006   Whenever there is any discrepancy between the two licenses, 
00007   the BSD license will take precedence.
00008         
00009   Set tabs to 4 for best viewing.
00010 
00011 */
00012 
00013 error_reporting(E_ALL);
00014 include_once('../adodb.inc.php');
00015 
00016 foreach(array('sapdb','sybase','mysql','access','oci8po','postgres','odbc_mssql','odbc','db2','firebird','informix') as $dbType) {
00017         echo "<h3>$dbType</h3><p>";
00018         $db = NewADOConnection($dbType);
00019         $dict = NewDataDictionary($db);
00020 
00021         if (!$dict) continue;
00022         $dict->debug = 1;
00023         
00024         $opts = array('REPLACE','mysql' => 'ENGINE=INNODB', 'oci8' => 'TABLESPACE USERS');
00025         
00026 /*      $flds = array(
00027                 array('id',     'I',                                                            
00028                                                         'AUTO','KEY'),
00029                                                         
00030                 array('name' => 'firstname', 'type' => 'varchar','size' => 30,
00031                                                         'DEFAULT'=>'Joan'),
00032                                                         
00033                 array('lastname','varchar',28,
00034                                                         'DEFAULT'=>'Chen','key'),
00035                                                         
00036                 array('averylonglongfieldname','X',1024,
00037                                                         'NOTNULL','default' => 'test'),
00038                                                         
00039                 array('price','N','7.2',
00040                                                         'NOTNULL','default' => '0.00'),
00041                                                         
00042                 array('MYDATE', 'D', 
00043                                                         'DEFDATE'),
00044                 array('TS','T',
00045                                                         'DEFTIMESTAMP')
00046         );*/
00047         
00048         $flds = "
00049 ID            I           AUTO KEY,
00050 FIRSTNAME     VARCHAR(30) DEFAULT 'Joan',
00051 LASTNAME      VARCHAR(28) DEFAULT 'Chen' key,
00052 averylonglongfieldname X(1024) DEFAULT 'test',
00053 price         N(7.2)  DEFAULT '0.00',
00054 MYDATE        D      DEFDATE,
00055 BIGFELLOW     X      NOTNULL,
00056 TS            T      DEFTIMESTAMP";
00057 
00058 
00059         $sqla = $dict->CreateDatabase('KUTU',array('postgres'=>"LOCATION='/u01/postdata'"));
00060         $dict->SetSchema('KUTU');
00061         
00062         $sqli = ($dict->CreateTableSQL('testtable',$flds, $opts));
00063         $sqla = array_merge($sqla,$sqli);
00064         
00065         $sqli = $dict->CreateIndexSQL('idx','testtable','firstname,lastname',array('BITMAP','FULLTEXT','CLUSTERED','HASH'));
00066         $sqla = array_merge($sqla,$sqli);
00067         $sqli = $dict->CreateIndexSQL('idx2','testtable','price,lastname');//,array('BITMAP','FULLTEXT','CLUSTERED'));
00068         $sqla = array_merge($sqla,$sqli);
00069         
00070         $addflds = array(array('height', 'F'),array('weight','F'));
00071         $sqli = $dict->AddColumnSQL('testtable',$addflds);
00072         $sqla = array_merge($sqla,$sqli);
00073         $addflds = array(array('height', 'F','NOTNULL'),array('weight','F','NOTNULL'));
00074         $sqli = $dict->AlterColumnSQL('testtable',$addflds);
00075         $sqla = array_merge($sqla,$sqli);
00076         
00077         
00078         printsqla($dbType,$sqla);
00079         
00080         if (file_exists('d:\inetpub\wwwroot\php\phplens\adodb\adodb.inc.php'))
00081         if ($dbType == 'mysqlt') {
00082                 $db->Connect('localhost', "root", "", "test");
00083                 $dict->SetSchema('');
00084                 $sqla2 = $dict->ChangeTableSQL('adoxyz',$flds);
00085                 if ($sqla2) printsqla($dbType,$sqla2);
00086         }
00087         if ($dbType == 'postgres') {
00088                 if (@$db->Connect('localhost', "tester", "test", "test"));
00089                 $dict->SetSchema('');
00090                 $sqla2 = $dict->ChangeTableSQL('adoxyz',$flds);
00091                 if ($sqla2) printsqla($dbType,$sqla2);
00092         }
00093         
00094         if ($dbType == 'odbc_mssql') {
00095                 $dsn = $dsn = "PROVIDER=MSDASQL;Driver={SQL Server};Server=localhost;Database=northwind;";
00096                 if (@$db->Connect($dsn, "sa", "natsoft", "test"));
00097                 $dict->SetSchema('');
00098                 $sqla2 = $dict->ChangeTableSQL('adoxyz',$flds);
00099                 if ($sqla2) printsqla($dbType,$sqla2);
00100         }
00101         
00102         
00103         
00104         adodb_pr($dict->databaseType);
00105         printsqla($dbType, $dict->DropColumnSQL('table',array('my col','`col2_with_Quotes`','A_col3','col3(10)')));
00106         printsqla($dbType, $dict->ChangeTableSQL('adoxyz','LASTNAME varchar(32)'));
00107         
00108 }
00109 
00110 function printsqla($dbType,$sqla)
00111 {
00112         print "<pre>";
00113         //print_r($dict->MetaTables());
00114         foreach($sqla as $s) {
00115                 $s = htmlspecialchars($s);
00116                 print "$s;\n";
00117                 if ($dbType == 'oci8') print "/\n";
00118         }
00119         print "</pre><hr />";
00120 }
00121 
00122 /***
00123 
00124 Generated SQL:
00125 
00126 mysql
00127 
00128 CREATE DATABASE KUTU;
00129 DROP TABLE KUTU.testtable;
00130 CREATE TABLE KUTU.testtable (
00131 id               INTEGER NOT NULL AUTO_INCREMENT,
00132 firstname        VARCHAR(30) DEFAULT 'Joan',
00133 lastname         VARCHAR(28) NOT NULL DEFAULT 'Chen',
00134 averylonglongfieldname LONGTEXT NOT NULL,
00135 price            NUMERIC(7,2) NOT NULL DEFAULT 0.00,
00136 MYDATE           DATE DEFAULT CURDATE(),
00137                  PRIMARY KEY (id, lastname)
00138 )TYPE=ISAM;
00139 CREATE FULLTEXT INDEX idx ON KUTU.testtable (firstname,lastname);
00140 CREATE INDEX idx2 ON KUTU.testtable (price,lastname);
00141 ALTER TABLE KUTU.testtable  ADD height           DOUBLE;
00142 ALTER TABLE KUTU.testtable  ADD weight           DOUBLE;
00143 ALTER TABLE KUTU.testtable  MODIFY COLUMN height           DOUBLE NOT NULL;
00144 ALTER TABLE KUTU.testtable  MODIFY COLUMN weight           DOUBLE NOT NULL;
00145 
00146 
00147 --------------------------------------------------------------------------------
00148 
00149 oci8
00150 
00151 CREATE USER KUTU IDENTIFIED BY tiger;
00152 /
00153 GRANT CREATE SESSION, CREATE TABLE,UNLIMITED TABLESPACE,CREATE SEQUENCE TO KUTU;
00154 /
00155 DROP TABLE KUTU.testtable CASCADE CONSTRAINTS;
00156 /
00157 CREATE TABLE KUTU.testtable (
00158 id               NUMBER(16) NOT NULL,
00159 firstname        VARCHAR(30) DEFAULT 'Joan',
00160 lastname         VARCHAR(28) DEFAULT 'Chen' NOT NULL,
00161 averylonglongfieldname CLOB NOT NULL,
00162 price            NUMBER(7,2) DEFAULT 0.00 NOT NULL,
00163 MYDATE           DATE DEFAULT TRUNC(SYSDATE),
00164                  PRIMARY KEY (id, lastname)
00165 )TABLESPACE USERS;
00166 /
00167 DROP SEQUENCE KUTU.SEQ_testtable;
00168 /
00169 CREATE SEQUENCE KUTU.SEQ_testtable;
00170 /
00171 CREATE OR REPLACE TRIGGER KUTU.TRIG_SEQ_testtable BEFORE insert ON KUTU.testtable 
00172                 FOR EACH ROW
00173                 BEGIN
00174                   select KUTU.SEQ_testtable.nextval into :new.id from dual;
00175                 END;
00176 /
00177 CREATE BITMAP INDEX idx ON KUTU.testtable (firstname,lastname);
00178 /
00179 CREATE INDEX idx2 ON KUTU.testtable (price,lastname);
00180 /
00181 ALTER TABLE testtable ADD (
00182  height           NUMBER,
00183  weight           NUMBER);
00184 /
00185 ALTER TABLE testtable MODIFY(
00186  height           NUMBER NOT NULL,
00187  weight           NUMBER NOT NULL);
00188 /
00189 
00190 
00191 --------------------------------------------------------------------------------
00192 
00193 postgres
00194 AlterColumnSQL not supported for PostgreSQL
00195 
00196 
00197 CREATE DATABASE KUTU LOCATION='/u01/postdata';
00198 DROP TABLE KUTU.testtable;
00199 CREATE TABLE KUTU.testtable (
00200 id               SERIAL,
00201 firstname        VARCHAR(30) DEFAULT 'Joan',
00202 lastname         VARCHAR(28) DEFAULT 'Chen' NOT NULL,
00203 averylonglongfieldname TEXT NOT NULL,
00204 price            NUMERIC(7,2) DEFAULT 0.00 NOT NULL,
00205 MYDATE           DATE DEFAULT CURRENT_DATE,
00206                  PRIMARY KEY (id, lastname)
00207 );
00208 CREATE INDEX idx ON KUTU.testtable USING HASH (firstname,lastname);
00209 CREATE INDEX idx2 ON KUTU.testtable (price,lastname);
00210 ALTER TABLE KUTU.testtable  ADD height           FLOAT8;
00211 ALTER TABLE KUTU.testtable  ADD weight           FLOAT8;
00212 
00213 
00214 --------------------------------------------------------------------------------
00215 
00216 odbc_mssql
00217 
00218 CREATE DATABASE KUTU;
00219 DROP TABLE KUTU.testtable;
00220 CREATE TABLE KUTU.testtable (
00221 id               INT IDENTITY(1,1) NOT NULL,
00222 firstname        VARCHAR(30) DEFAULT 'Joan',
00223 lastname         VARCHAR(28) DEFAULT 'Chen' NOT NULL,
00224 averylonglongfieldname TEXT NOT NULL,
00225 price            NUMERIC(7,2) DEFAULT 0.00 NOT NULL,
00226 MYDATE           DATETIME DEFAULT GetDate(),
00227                  PRIMARY KEY (id, lastname)
00228 );
00229 CREATE CLUSTERED INDEX idx ON KUTU.testtable (firstname,lastname);
00230 CREATE INDEX idx2 ON KUTU.testtable (price,lastname);
00231 ALTER TABLE KUTU.testtable  ADD
00232  height           REAL,
00233  weight           REAL;
00234 ALTER TABLE KUTU.testtable  ALTER COLUMN height           REAL NOT NULL;
00235 ALTER TABLE KUTU.testtable  ALTER COLUMN weight           REAL NOT NULL;
00236 
00237 
00238 --------------------------------------------------------------------------------
00239 */
00240 
00241 
00242 echo "<h1>Test XML Schema</h1>";
00243 $ff = file('xmlschema.xml');
00244 echo "<pre>";
00245 foreach($ff as $xml) echo htmlspecialchars($xml);
00246 echo "</pre>";
00247 include_once('test-xmlschema.php');
00248 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6