NAME
DBIO::DB2::Diff::View - Diff operations for DB2 views
VERSION
version 0.900007
DESCRIPTION
Represents a view-level diff operation: CREATE VIEW or DROP VIEW.
DBIO::DB2::Introspect::Tables lists a view under tables with kind => 'view' and its view_definition. A view is created as a view and removed as a view, and no table, column or index operation is ever written for one -- DBIO::DB2::Diff::Table and DBIO::DB2::Diff::Column leave every entry of kind view alone (ADR 0011).
What counts as a changed view
The view_definition is what the catalog holds of the CREATE VIEW statement after the view's name (SYSCAT.VIEWS.TEXT, the text as it was written): normally AS SELECT ..., with the column list in front when the view was made with one. The name is cut off with the schema in front of it, so the view of the live schema and the one of the compare schema (DBIO_TEST_<pid>, ADR 0006) compare by what they read, not by where they sit. Whitespace is set aside; everything else has to be the same, letter for letter. A model that holds no definition on either side has nothing to compare and the view counts as unchanged.
Db2 has CREATE OR REPLACE VIEW, but the pair every driver of the family writes is a drop followed by a create, and so a changed definition is.
The order of the views
A view can read another view, and the server refuses CREATE VIEW for one that reads a view that does not exist (SQL0204N). So (as in dbio-mysql):
the
createops are in the order "order_views" in DBIO::DB2::DDL gives for the views being created, read from the definitions of the target: a view after the views it reads, otherwise by name. It is the function "install_ddl" in DBIO::DB2::DDL orders itsCREATE VIEWstatements with, so install and upgrade write one order.the
dropops are the reverse of that order for the views being dropped, read from the definitions of the source: a view before the views it reads.a view that reads a view being replaced (a
dropand acreateof a changed definition), directly or through other views, is replaced with it, although its own definition did not change. Db2 would otherwise refuse theDROP VIEWof the base or leave the reader inoperative (SQL0204N on its next use). The reader is dropped before the view it reads and created after it, so the server checks it against the new definition when the diff is applied: a reader that no longer fits fails there, loudly. Itsdropis marked "replaced". A view that reads only views that stay as they are is not touched.views that read each other in a cycle are refused with a DBIO::Exception that names them, before any operation is returned.
How a definition is read for what it reads, and what is not recognised, is in "view_reads" in DBIO::DB2::DDL. Two things there decide an order: the name of a common table expression is no view, and a read qualified with a schema is a view of the set only when the qualifier is the live schema -- the schema the entries of the source model carry, which is where the operations run (ADR 0006). A model with no entry gives none, and a qualified read of a view of the set is then refused with a DBIO::Exception, like a cycle, before any operation is returned.
ATTRIBUTES
view_name
The name of the view.
view_info
The view's entry in the tables section of the model it comes from: the target's for a create, the source's for a drop. A create needs its view_definition.
replaced
True on the drop of a changed view: the view is not removed, the create that follows puts it back with its new definition. "classify" in DBIO::Diff::Base counts such a drop as changing, not destructive.
METHODS
is_view
DBIO::DB2::Diff::View::is_view($table_info)
True for a table entry of kind view.
diff
my @ops = DBIO::DB2::Diff::View->diff($source_tables, $target_tables);
my @ops = DBIO::DB2::Diff::View->diff($source_tables, $target_tables, $schema);
Compares the tables sections of two models, looking at the entries of kind view only. Returns a drop op for a view only the source has, a create op for a view only the target has, and both, drop first and marked "replaced", for a view whose definition has changed. All drops come first, then all creates, each in dependency order ("The order of the views"). An optional third argument names the live schema when the source model cannot ("view_dependencies" in DBIO::DB2::DDL). DBIO::DB2::Diff puts every drop at the head of the diff and every create at its end, and keeps the order within each.
as_sql
DROP VIEW "name"; or CREATE VIEW "name" AS definition;, the name quoted. A create whose "view_info" holds no view_definition throws, naming the view: a view cannot be written from its columns.
summary
+ view: name or - view: name. It never throws, for an op "as_sql" refuses.
AUTHOR
DBIO & DBIx::Class Authors
COPYRIGHT AND LICENSE
Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.