/
mssql10_diff_views.php
65 lines (60 loc) · 1.81 KB
/
mssql10_diff_views.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Diffs views.
*
* @package DBSteward
* @subpackage mssql10
* @license http://www.opensource.org/licenses/bsd-license.php Simplified BSD License
* @author Nicholas J Kiraly <kiraly.nicholas@gmail.com>
*/
class mssql10_diff_views {
/**
* Outputs commands for creation of views.
*
* @param fp output file pointer
* @param old_schema original schema
* @param new_schema new schema
*/
public static function create_views($fp, $old_schema, $new_schema) {
foreach (dbx::get_views($new_schema) as $new_view) {
if ($old_schema == NULL
|| !mssql10_schema::contains_view($old_schema, $new_view['name'])
|| self::is_view_modified(dbx::get_view($old_schema, $new_view['name']), $new_view)) {
fwrite($fp, mssql10_view::get_creation_sql($new_schema, $new_view));
}
}
}
/**
* Outputs commands for dropping views.
*
* @param fp output file pointer
* @param old_schema original schema
* @param new_schema new schema
*/
public static function drop_views($fp, $old_schema, $new_schema) {
if ($old_schema != NULL) {
foreach (dbx::get_views($old_schema) as $old_view) {
$new_view = dbx::get_view($new_schema, $old_view['name']);
if ($new_view == NULL || self::is_view_modified($old_view, $new_view)) {
fwrite($fp, mssql10_view::get_drop_sql($old_schema, $old_view) . "\n");
}
}
}
}
/**
* is old_view different than new_view?
*
* @param object $old_view
* @param object $new_view
*
* @return boolean
*/
public static function is_view_modified($old_view, $new_view) {
if ( dbsteward::$always_recreate_views ) {
return TRUE;
}
$different = strcasecmp(mssql10_view::get_view_query($old_view), mssql10_view::get_view_query($new_view)) != 0;
return $different;
}
}
?>