MediaWiki REL1_39
Sqlite.php
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_fill_keys( [
59 'integer',
60 'real',
61 'text',
62 'blob',
63 // NULL type is omitted intentionally
64 ], true );
65
66 $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
67 try {
68 foreach ( $files as $file ) {
69 $err = $db->sourceFile( $file );
70 if ( $err ) {
71 return $err;
72 }
73 }
74
75 $tables = $db->query( "SELECT name FROM sqlite_master WHERE type='table'", __METHOD__ );
76 foreach ( $tables as $table ) {
77 if ( strpos( $table->name, 'sqlite_' ) === 0 ) {
78 continue;
79 }
80
81 $columns = $db->query(
82 'PRAGMA table_info(' . $db->addIdentifierQuotes( $table->name ) . ')',
83 __METHOD__
84 );
85 foreach ( $columns as $col ) {
86 if ( !isset( $allowedTypes[strtolower( $col->type )] ) ) {
87 $db->close( __METHOD__ );
88
89 return "Table {$table->name} has column {$col->name} with non-native type '{$col->type}'";
90 }
91 }
92 }
93 } catch ( DBError $e ) {
94 return $e->getMessage();
95 }
96 $db->close( __METHOD__ );
97
98 return true;
99 }
100}
MediaWiki exception.
This class contains code common to different SQLite-related maintenance scripts.
Definition Sqlite.php:32
static isPresent()
Checks whether PHP has SQLite support.
Definition Sqlite.php:38
static checkSqlSyntax( $files)
Checks given files for correctness of SQL syntax.
Definition Sqlite.php:50
Database error base class.
Definition DBError.php:31
This is the SQLite database abstraction layer.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42