cvs: pear /MDB2_Schema/docs/examples example.php

From: Date: Fri, 06 Oct 2006 03:13:02 +0000
Subject: cvs: pear /MDB2_Schema/docs/examples example.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-42428@lists.php.net to get a copy of this message
ifeghali Fri Oct 6 03:13:02 2006 UTC Modified files: /pear/MDB2_Schema/docs/examples example.php Log: - Dump SQL => Do not modify database - Added action Initialize. not implemented yet http://cvs.php.net/viewvc.cgi/pear/MDB2_Schema/docs/examples/example.php?r1=1.22&r2=1.23&diff_format=u Index: pear/MDB2_Schema/docs/examples/example.php diff -u pear/MDB2_Schema/docs/examples/example.php:1.22 pear/MDB2_Schema/docs/examples/example.php:1.23 --- pear/MDB2_Schema/docs/examples/example.php:1.22 Sun Oct 1 04:14:13 2006 +++ pear/MDB2_Schema/docs/examples/example.php Fri Oct 6 03:13:01 2006 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: example.php,v 1.22 2006/10/01 04:14:13 ifeghali Exp $ +// $Id: example.php,v 1.23 2006/10/06 03:13:01 ifeghali Exp $ // /** @@ -107,6 +107,12 @@ } } + if (isset($_REQUEST['disable_query']) && $_REQUEST['disable_query']) { + $disable_query = true; + } else { + $disable_query = false; + } + $dsn = $_REQUEST['type'].'://'.$_REQUEST['user'].':'.$_REQUEST['pass'].'@'.$_REQUEST['host'].'/'.$_REQUEST['name']; $schema =& MDB2_Schema::factory($dsn, $options); @@ -132,6 +138,7 @@ 'output_mode' => 'file', 'output' => $_REQUEST['file'] ); + $definition = $schema->getDefinitionFromDatabase(); if (PEAR::isError($definition)) { $error = $definition->getMessage() . ' ' . $definition->getUserInfo(); @@ -142,13 +149,11 @@ /* UPDATE DATABASE */ } elseif ($_REQUEST['action'] == 'update') { - $disable_query = false; - if (isset($_REQUEST['dumpsql']) && $_REQUEST['dumpsql']) { + if ($disable_query) { $debug_tmp = $schema->db->getOption('debug'); $schema->db->setOption('debug', true); $debug_handler_tmp = $schema->db->getOption('debug_handler'); $schema->db->setOption('debug_handler', 'printQueries'); - $disable_query = true; } $dump_config = array( @@ -160,13 +165,17 @@ $error = $definition->getMessage() . ' ' . $definition->getUserInfo(); } else { $operation = $schema->dumpDatabase($definition, $dump_config, MDB2_SCHEMA_DUMP_ALL); - call_user_func($var_dump, $operation); + if (PEAR::isError($operation)) { + echo $operation->getMessage() . ' ' . $operation->getUserInfo(); + } else { + call_user_func($var_dump, $operation); + } } $operation = $schema->updateDatabase($_REQUEST['file'] , $_REQUEST['file'].'.old', array(), $disable_query ); - if (isset($_REQUEST['dumpsql']) && $_REQUEST['dumpsql']) { + if ($disable_query) { $schema->db->setOption('debug', $debug_tmp); $schema->db->setOption('debug_handler', $debug_handler_tmp); } @@ -178,13 +187,25 @@ /* CREATE DATABASE */ } elseif ($_REQUEST['action'] == 'create') { - $disable_query = false; + if ($disable_query) { + $debug_tmp = $schema->db->getOption('debug'); + $schema->db->setOption('debug', true); + $debug_handler_tmp = $schema->db->getOption('debug_handler'); + $schema->db->setOption('debug_handler', 'printQueries'); + } $definition = $schema->parseDatabaseDefinition( $_REQUEST['file'], false, array(), $schema->options['fail_on_invalid_names'] ); + + $schema->db->setOption('disable_query', $disable_query); $operation = $schema->createDatabase($definition); + $schema->db->setOption('disable_query', false); + if ($disable_query) { + $schema->db->setOption('debug', $debug_tmp); + $schema->db->setOption('debug_handler', $debug_handler_tmp); + } if (PEAR::isError($operation)) { echo $operation->getMessage() . ' ' . $operation->getUserInfo(); } else { @@ -277,8 +298,8 @@ <td><input type="radio" name="action" id="update" value="update" <?php if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'update') { echo 'checked="checked"';} ?> /></td> </tr> <tr> - <td><label for="dumpsql">Only Dump SQL:</label></td> - <td><input type="checkbox" name="dumpsql" id="dumpsql" value="1" /></td> + <td><label for="update">Initialize:</label></td> + <td><input type="radio" name="action" id="initialize" value="initialize" <?php if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'initialize') { echo 'checked="checked"';} ?> /></td> </tr> </table> </fieldset> @@ -310,6 +331,10 @@ <td><label for="portability">Portability:</label></td> <td><input type="checkbox" name="portability" id="portability" value="1" <?php if ((isset($options['portability'])) && ($options['portability'])) {echo (' checked="checked"');} ?> /></td> </tr> + <tr> + <td><label for="disable_query">Do not modify database:</label></td> + <td><input type="checkbox" name="disable_query" id="disable_query" value="1" <?php if ((isset($disable_query)) && ($disable_query)) {echo (' checked="checked"');} ?> /></td> + </tr> </table> </fieldset>

« previous php.pear.cvs (#42428) next »