Topic
  • 6 replies
  • Latest Post - ‏2013-03-15T18:24:59Z by vinod.cmenon
JonathanAllan
JonathanAllan
5 Posts

Pinned topic Pogramatic schema upgrade fails

‏2012-02-22T19:36:03Z |
Greetings all!

Please tell me I'm doing something simple wrong. I want to write a perl script which will apply a new schema to a DB. So, after this and that, I ended up with the script below. No matter what I do, the $databaseObj->Upgrade($schemaRevObj); line always fails with:

"This operation cannot proceed until the metadata has been loaded."

Yet, if I apply the exact same change to the DB manually, it works just fine.

I thought it was a result of using the new designer on a Win7 box, but I get the same results if I checkout/change/checkin the schema on an older XP machine with the 7.0.1 designer installed.

I've tested all the error paths and all the functional paths, up to the referenced failing line, appear to working just fine. I can watch the code loop through the schemas, find the proper revs, etc.

Thanks for any insight!
Jonathan Allan

Relevant Script Fragments:
$adminSession = CQAdminSession::Build; # open up an admin session
$adminSession->Logon($dest_login,$dest_passwd,$dest_dbset); # Login as admin user
$databaseObj = $adminSession->GetDatabase($dest_db); # Try to find the database
$schemaRevObj = $databaseObj->GetSchemaRev; # currently used schema version
$in_use_rev = -1; # invalid value in case next conversion fails
$in_use_rev = int($schemaRevObj->GetRevID); # Get the number for later work

if ( $in_use_rev < $end_ver ) {
print "Upgrading ($dest_db) to version ($end_ver) from version ($in_use_rev)...\n";

$schemasObj = $adminSession->GetSchemas;
$found_schema = 0;
for ( $x = 0; $x < $schemasObj->Count; $x++ ) {
$schemaObj = $schemasObj->Item($x);
$schemaName = $schemaObj->GetName;
if ( $preview ) { print "Schema $x is named $schemaName.\n"; }
if ( $schemaName eq $schema_name ) { # Found the schema we want to update?
$schemaRevsObj = $schemaObj->GetSchemaRevs;
$nrevs = $schemaRevsObj->Count; # number of revs for this schema, 0 offset
if ( $preview ) { print "nrevs=$nrevs.\n"; }
if ( $end_ver > $nrevs ) {
print "ERROR: The schema repository ($dest_dbset) only has ($nrevs) revisions for the ($schema_name) schema. Cannot upgrade ($dest_db) database to version ($end_ver).\n";
goto FINISH;
}
$schemaRevObj = $schemaRevsObj->Item($end_ver - 1);
$found_schema = 1;
last;
}
}

  1. Push the changes.
if ( $found_schema ) {
if ( ! $preview ) {
$databaseObj->Upgrade($schemaRevObj);
print "Did the update.\n";
} else {
print "Database ($dest_db) not upgraded in preview mode.\n";
}
} else {
print "ERROR: Unable to find a schema named ($schema_name) in the destination schema repository ($dest_dbset).\n";
}
} else {
print "Destination db ($dest_db) version is up to date, in use schema rev was: $in_use_rev.\n";
}

FINISH:
  1. Clean up from the session
CQAdminSession::Unbuild($adminSession);
Updated on 2013-03-15T18:24:59Z at 2013-03-15T18:24:59Z by vinod.cmenon
  • JonathanAllan
    JonathanAllan
    5 Posts

    Re: Programmatic schema upgrade fails

    ‏2012-02-22T19:49:01Z  
    Sorry about the formatting. Let's try the script again:
    
    $adminSession = CQAdminSession::Build; # open up an admin session $adminSession->Logon($dest_login,$dest_passwd,$dest_dbset); # Login as admin user $databaseObj = $adminSession->GetDatabase($dest_db); # Try to find the database $schemaRevObj = $databaseObj->GetSchemaRev; # currently used schema version $in_use_rev = -1; # invalid value in 
    
    case next conversion fails $in_use_rev = 
    
    int($schemaRevObj->GetRevID); # Get the number 
    
    for later work   
    
    if ( $in_use_rev < $end_ver ) 
    { print 
    "Upgrading ($dest_db) to version ($end_ver) from version ($in_use_rev)...\n";   $schemasObj = $adminSession->GetSchemas; $found_schema = 0; 
    
    for ( $x = 0; $x < $schemasObj->Count; $x++ ) 
    { $schemaObj = $schemasObj->Item($x); $schemaName = $schemaObj->GetName; 
    
    if ( $preview ) 
    { print 
    "Schema $x is named $schemaName.\n"; 
    } 
    
    if ( $schemaName eq $schema_name ) 
    { # Found the schema we want to update? $schemaRevsObj = $schemaObj->GetSchemaRevs; $nrevs = $schemaRevsObj->Count; # number of revs 
    
    for 
    
    this schema, 0 offset 
    
    if ( $preview ) 
    { print 
    "nrevs=$nrevs.\n"; 
    } 
    
    if ( $end_ver > $nrevs ) 
    { print 
    "ERROR: The schema repository ($dest_dbset) only has ($nrevs) revisions for the ($schema_name) schema.  Cannot upgrade ($dest_db) database to version ($end_ver).\n"; 
    
    goto FINISH; 
    } $schemaRevObj = $schemaRevsObj->Item($end_ver - 1); $found_schema = 1; last; 
    } 
    }   # Push the changes. 
    
    if ( $found_schema ) 
    { 
    
    if ( ! $preview ) 
    { $databaseObj->Upgrade($schemaRevObj);       <<==== Always fails print 
    "Did the update.\n"; 
    } 
    
    else 
    { print 
    "Database ($dest_db) not upgraded in preview mode.\n"; 
    } 
    } 
    
    else 
    { print 
    "ERROR: Unable to find a schema named ($schema_name) in the destination schema repository ($dest_dbset).\n"; 
    } 
    } 
    
    else 
    { print 
    "Destination db ($dest_db) version is up to date, in use schema rev was: $in_use_rev.\n"; 
    }   FINISH: # Clean up from the session CQAdminSession::Unbuild($adminSession);
    
  • JonathanAllan
    JonathanAllan
    5 Posts

    Re: Pogramatic schema upgrade fails

    ‏2012-02-23T21:28:20Z  
    I've cleaned up a few side issues, but still am getting the same message. Here's the latest version.

    Thoughts? This has my entire team stumped...

    
    $adminSession = CQAdminSession::Build; # open up an admin session $adminSession->Logon($dest_login,$dest_passwd,$dest_dbset); # Login as admin user $databaseObj = $adminSession->GetDatabase($dest_db); # Try to find the database   $schemasObj = $adminSession->GetSchemas;  # Get collection of schemas in 
    
    this repo $found_schema = 0; # Should we proceed with updating the DB? 
    
    for ( $x = 0; $x < $schemasObj->Count; $x++ ) 
    { # Get the name of a schema to see 
    
    if it
    's the one we want $schemaObj = $schemasObj->Item($x); $schemaName = $schemaObj->GetName; 
    
    if ( $preview ) 
    { print 
    "Schema $x is named $schemaName.\n"; 
    } 
    
    if ( $schemaName eq $schema_name ) 
    { # Found the schema we want to update? $schemaRevsObj = $schemaObj->GetSchemaRevs; $nrevs = $schemaRevsObj->Count; # number of revs 
    
    for 
    
    this schema, 1 offset 
    
    if ( $end_ver > $nrevs ) 
    { print 
    "ERROR: The schema repository ($dest_dbset) only has ($nrevs) revisions for the ($schema_name) schema.  Cannot upgrade ($dest_db) database to version ($end_ver).\n"; 
    
    goto FINISH; 
    } $schemaRevObj = $schemaRevsObj->Item($end_ver - 1); # Get schemarev to apply to database $found_schema = 1; last; 
    } 
    }   # Push the changes. 
    
    if ( $found_schema ) 
    { 
    
    if ( ! $preview ) 
    { # $databaseObj->ApplyPropertyChanges(FALSE);  # Didn
    't hurt, but didn't fix error either # Next line fails with 
    "This operation cannot proceed until the metadata has been loaded." $databaseObj->Upgrade($schemaRevObj); print 
    "Did the update.\n"; 
    } 
    
    else 
    { print 
    "Database ($dest_db) not upgraded in preview mode.\n"; 
    } 
    } 
    
    else 
    { print 
    "ERROR: Unable to find a schema named ($schema_name) in the destination schema repository ($dest_dbset).\n"; 
    }
    
  • Lumart
    Lumart
    87 Posts

    Re: Pogramatic schema upgrade fails

    ‏2012-03-01T09:34:05Z  
    I've cleaned up a few side issues, but still am getting the same message. Here's the latest version.

    Thoughts? This has my entire team stumped...

    <pre class="jive-pre"> $adminSession = CQAdminSession::Build; # open up an admin session $adminSession->Logon($dest_login,$dest_passwd,$dest_dbset); # Login as admin user $databaseObj = $adminSession->GetDatabase($dest_db); # Try to find the database $schemasObj = $adminSession->GetSchemas; # Get collection of schemas in this repo $found_schema = 0; # Should we proceed with updating the DB? for ( $x = 0; $x < $schemasObj->Count; $x++ ) { # Get the name of a schema to see if it 's the one we want $schemaObj = $schemasObj->Item($x); $schemaName = $schemaObj->GetName; if ( $preview ) { print "Schema $x is named $schemaName.\n"; } if ( $schemaName eq $schema_name ) { # Found the schema we want to update? $schemaRevsObj = $schemaObj->GetSchemaRevs; $nrevs = $schemaRevsObj->Count; # number of revs for this schema, 1 offset if ( $end_ver > $nrevs ) { print "ERROR: The schema repository ($dest_dbset) only has ($nrevs) revisions for the ($schema_name) schema. Cannot upgrade ($dest_db) database to version ($end_ver).\n"; goto FINISH; } $schemaRevObj = $schemaRevsObj->Item($end_ver - 1); # Get schemarev to apply to database $found_schema = 1; last; } } # Push the changes. if ( $found_schema ) { if ( ! $preview ) { # $databaseObj->ApplyPropertyChanges(FALSE); # Didn 't hurt, but didn't fix error either # Next line fails with "This operation cannot proceed until the metadata has been loaded." $databaseObj->Upgrade($schemaRevObj); print "Did the update.\n"; } else { print "Database ($dest_db) not upgraded in preview mode.\n"; } } else { print "ERROR: Unable to find a schema named ($schema_name) in the destination schema repository ($dest_dbset).\n"; } </pre>
    Jonathan, is this error systematic or not?
    I mean, does it occur with all schemas and all databases (you could perform some tests in a separate environment)?
    Also, if you perform the upgrade operation manually, do you get the same error?
    Your issue can be related to either code page or package validation.
    Look at these technotes:

    http://www-01.ibm.com/support/docview.wss?uid=swg21421674
    http://www-01.ibm.com/support/docview.wss?uid=swg21147182
  • JonathanAllan
    JonathanAllan
    5 Posts

    Re: Pogramatic schema upgrade fails

    ‏2012-03-13T19:55:54Z  
    Thanks for the reply; I've gotten pulled off in other directions of late.

    The problem exists when I try to run the script on my local machine and when I try to run it under BuildForge (actually executing on another machine). If I do an update manually using the 7.1.1 designer on my local machine, it works just fine and I can see the change after I update the DB.

    I haven't messed with any of the packages in the change I'm trying to apply: updating a field size just to see something visible.

    I'm digging into the possible codepage issue. I'm not sure why the designer would work where the CQPERL interface wouldn't in that regard. If you know of something else I should review, please let me know.
  • JonathanAllan
    JonathanAllan
    5 Posts

    Re: Pogramatic schema upgrade fails

    ‏2012-03-14T18:18:21Z  
    It turns out the DB2 backend is CP=1208 (UTF-8). So I set the windows 7 machines dos window (where I'm running my script from) codepage to 65001 (per this page: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx, 437 is the default), and that didn't work. I also tried cp=1252 with the same result:

    "This operation cannot proceed until the metadata has been loaded." at this line of my script: $databaseObj->Upgrade($schemaRevObj);

    Urk. Any other ideas anyone?
  • vinod.cmenon
    vinod.cmenon
    3 Posts

    Re: Pogramatic schema upgrade fails

    ‏2013-03-15T18:24:59Z  
    It turns out the DB2 backend is CP=1208 (UTF-8). So I set the windows 7 machines dos window (where I'm running my script from) codepage to 65001 (per this page: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx, 437 is the default), and that didn't work. I also tried cp=1252 with the same result:

    "This operation cannot proceed until the metadata has been loaded." at this line of my script: $databaseObj->Upgrade($schemaRevObj);

    Urk. Any other ideas anyone?
    Am getting the same error.
    Did anyone ever find an answer to this issue?

    Please help