diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2007-05-16 20:58:53 +0000 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2007-05-16 20:58:53 +0000 |
commit | cecb985bee3bdd252e1b8dc0bd500b37cd52be01 (patch) | |
tree | 17266aa237742640aabee7856f0202317a45d540 /maintenance/sql.php | |
parent | 0bac06c301f2a83edb0236e4c2434da16848d549 (diff) |
Aktualisierung auf MediaWiki 1.10.0
Plugins angepasst und verbessert
kleine Korrekturen am Design
Diffstat (limited to 'maintenance/sql.php')
-rw-r--r-- | maintenance/sql.php | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/maintenance/sql.php b/maintenance/sql.php new file mode 100644 index 00000000..a536705e --- /dev/null +++ b/maintenance/sql.php @@ -0,0 +1,67 @@ +<?php + +/** + * Send SQL queries from the specified file to the database, performing + * variable replacement along the way. + */ + +require_once( dirname(__FILE__) . '/' . 'commandLine.inc' ); + +if ( isset( $options['help'] ) ) { + echo "Send SQL queries to a MediaWiki database.\nUsage: php sql.php [<file>]\n"; + exit( 1 ); +} + +if ( isset( $args[0] ) ) { + $fileName = $args[0]; + $file = fopen( $fileName, 'r' ); + $promptCallback = false; +} else { + $file = STDIN; + $promptObject = new SqlPromptPrinter( "> " ); + $promptCallback = $promptObject->cb(); +} + +if ( !$file ) { + echo "Unable to open input file\n"; + exit( 1 ); +} + +$dbw =& wfGetDB( DB_MASTER ); +$error = $dbw->sourceStream( $file, $promptCallback, 'sqlPrintResult' ); +if ( $error !== true ) { + echo $error; + exit( 1 ); +} else { + exit( 0 ); +} + +//----------------------------------------------------------------------------- +class SqlPromptPrinter { + function __construct( $prompt ) { + $this->prompt = $prompt; + } + + function cb() { + return array( $this, 'printPrompt' ); + } + + function printPrompt() { + echo $this->prompt; + } +} + +function sqlPrintResult( $res ) { + if ( !$res ) { + // Do nothing + } elseif ( $res->numRows() ) { + while ( $row = $res->fetchObject() ) { + print_r( $row ); + } + } else { + $affected = $res->db->affectedRows(); + echo "Query OK, $affected row(s) affected\n"; + } +} + +?> |