MediaWiki REL1_31
sqlite.inc
Go to the documentation of this file.
1<?php
26
32class Sqlite {
33
38 public static function isPresent() {
39 return extension_loaded( 'pdo_sqlite' );
40 }
41
50 public static function checkSqlSyntax( $files ) {
51 if ( !self::isPresent() ) {
52 throw new MWException( "Can't check SQL syntax: SQLite not found" );
53 }
54 if ( !is_array( $files ) ) {
55 $files = [ $files ];
56 }
57
58 $allowedTypes = array_flip( [
59 'integer',
60 'real',
61 'text',
62 'blob', // NULL type is omitted intentionally
63 ] );
64
65 $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
66 try {
67 foreach ( $files as $file ) {
68 $err = $db->sourceFile( $file );
69 if ( $err != true ) {
70 return $err;
71 }
72 }
73
74 $tables = $db->query( "SELECT name FROM sqlite_master WHERE type='table'", __METHOD__ );
75 foreach ( $tables as $table ) {
76 if ( strpos( $table->name, 'sqlite_' ) === 0 ) {
77 continue;
78 }
79
80 $columns = $db->query( "PRAGMA table_info({$table->name})", __METHOD__ );
81 foreach ( $columns as $col ) {
82 if ( !isset( $allowedTypes[strtolower( $col->type )] ) ) {
83 $db->close();
84
85 return "Table {$table->name} has column {$col->name} with non-native type '{$col->type}'";
86 }
87 }
88 }
89 } catch ( DBError $e ) {
90 return $e->getMessage();
91 }
92 $db->close();
93
94 return true;
95 }
96}
MediaWiki exception.
This class contains code common to different SQLite-related maintenance scripts.
Definition sqlite.inc:32
static isPresent()
Checks whether PHP has SQLite support.
Definition sqlite.inc:38
static checkSqlSyntax( $files)
Checks given files for correctness of SQL syntax.
Definition sqlite.inc:50
Database error base class.
Definition DBError.php:30
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition hooks.txt:1015
returning false will NOT prevent logging $e
Definition hooks.txt:2176