Editing versioned data in Oracle using multiversioned views and SQL

You can edit versioned data in a geodatabase by editing a multiversioned view created on the data.

There are several stored procedures installed with ArcSDE that help you work with multiversioned views. These components and their descriptions are as follows:

Stored procedure

Purpose

Syntax and description

sde.version_user_ddl.create_version

Create a new geodatabase version.

Always edit your own, separate version; multiple editors cannot edit the same version using multiversioned views.

EXEC sde.version_user_ddl.create_version

('<parent_version>', :<child_version_variable>, <name_rule>, <access>, '<description>')

<parent_version> is the version from which your version is created.

<child_version> is the name for the version you are creating.

<access> is the permission level for the version; either 0 for Private, 1 for Public, or 2 for Protected.

<description> is a text description of the child version.

sde.version_util.set_current_version

Set which geodatabase version you will access.

EXEC sde.version_util.set_current_version('<version_name>')

The <version_name> is the name of the geodatabase version to which you want to connect.

sde.version_user_ddl.edit_version

Start and end an edit session.

EXEC sde.version_user_ddl.edit_version('<version_name>',<1 or 2>)

Specify 1 to start the edit session. Specify 2 to end it.

sde.version_user_ddl.delete_version

Delete a geodatabase version.

EXEC sde.version_user_ddl.delete_version('<version_name>')

When you edit versioned tables through multiversioned views, changes are made to the delta tables, and row ID (object ID) values for new records are automatically generated. However, unlike editing versioned data in an ArcGIS edit session, no internal version reconciliation is done with these edits.

Additionally, an exclusive lock is placed on the state that the version references when you start an edit session on a multiversioned view. Therefore, it is strongly recommended that multiversioned views not be used to edit the DEFAULT version or any version that may be subject to simultaneous editing or reconciliation by other users because conflicts will not be detected and locks will block other users. Instead, create your own version specifically for your multiversioned view edit session.

CautionCaution:
  • Version management operations, such as reconciling, resolving conflicts, and posting, must be done using the ArcGIS software. Improper version management can lead to geodatabase corruption when working with views.
  • Never use database management system (DBMS) tools to update any row ID (object ID) field maintained by ArcSDE in the database. These object ID fields are allocated and managed by the geodatabase and, therefore, should not be altered using SQL.
  • Never edit the DEFAULT version of the geodatabase using SQL. Starting an edit session on a version obtains an exclusive lock on the state that the version references. If you lock the DEFAULT version, you prevent ArcGIS users from connecting to the geodatabase.

The following steps guide you through creating a multiversioned view, creating a version in which to perform edits, setting the version to edit, starting an edit session, performing some edits through the multiversioned view, stopping the edit session, committing your edits to the database, and deleting the version created for the edits. In the examples, the multiversioned view created to perform the edits on the table is code_mv, and the version created and used for editing is mvedits.

TipTip:

Remember that the dataset you edit through a multiversioned view must already have been registered as versioned.

Steps:
  1. At an MS-DOS (Windows) or shell (UNIX or Linux) command prompt, execute the sdetable utility to create a multiversioned view.
    sdetable –o create_mv_view –T code_mv –t code_enf 
    –i sde:oracle11g –u sarja –p not4U@orasvc
  2. Open a SQL client and declare a variable to store the version you will create in the next step.
    VARIABLE mv_version NVARCHAR2(10); 
    EXEC :mv_version := 'mvedits';

    In this example, mv_version is the variable name, NVARCHAR2(10) is the data type of the variable, and mvedits is the version name.

  3. Create a new version in which to perform your edits.
    EXEC sde.version_user_ddl.create_version 
    ('sde.DEFAULT', :mv_version, sde.version_util.C_take_name_as_given, sde.version_util.C_version_private, 'multiversioned view edit version');
  4. Set the version for the edit session to the child version you just created.
    EXEC sde.version_util.set_current_version('mvedits');
  5. Start an edit session by executing the version_user_ddl.edit_version stored procedure and specifying 1. The 1 indicates an edit session should be started.
    EXEC sde.version_user_ddl.edit_version('mvedits',1);
  6. Perform the first edit to the multiversioned view using SQL.

    In this example, an existing record is updated.

    UPDATE code_mv 
    SET propowner = 'C. Industry' 
    WHERE vid = 2233
  7. Perform the next edit to the multiversioned view using SQL.

    In this example, a new record is inserted to the table.

    INSERT INTO code_mv (codenum,propowner,shape) 
    VALUES 
    (567, 'Anjo Badsu', sde.ST_PointFromText('point (40 40)', 12));
    TipTip:

    In the INSERT statement, no object ID value is specified; the multiversioned view automatically gets the next available object ID and inserts it for the row.

    Although it is possible to version a table that has only been registered with ArcSDE and has a user-maintained object ID column, this is not recommended. If you do this anyway, though, you must provide an object ID with the INSERT statements; the multiversioned view cannot generate a value for you.

  8. Execute a COMMIT or ROLLBACK statement.
  9. Stop the edit session by executing the version_user_ddl.edit_version stored procedure, but this time, specify 2.

    The 2 indicates the edit session should be closed.

    EXEC sde.version_user_ddl.edit_version('mvedits',2);
  10. When all editing is done, reconcile and post edits through ArcGIS Desktop, then you can edit the geodatabase version you created in step 3. Or if you decide you do not want the changes, you can delete the version you created in step 3 without reconciling and posting the edits.
    EXEC sde.version_user_ddl.delete_version('mv_version');

Related Topics


11/18/2013