Problems querying tables in federated database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • imusion
    New Member
    • Sep 2009
    • 1

    Problems querying tables in federated database

    Hi,

    I have 2 servers each running AIX and both have a DB2 database setup on them. I'm building a news management application and in our setup we need to have a staging and production setup. So the staging database gets the changes performed and then once we're satisfied with how it looks, we push the changes through SQL queries which perform the (deletions, updating, and inserting of articles) onto the production database by comparing it to the staging database.

    The problem is the database is federated and the nicknames are created on the staging database but I'm getting errors while running certain queries.

    Below is how the databases are setup and how the wrapper was created for the federated database.

    -------------------------------------------------
    Database 1: STAGING
    - Users: NEWSADM, SWGNEWSR, NEWSFED
    Database 2: PRODUCTION
    - Users: NEWSFED

    AIX64/DB2 9.1
    -------------------------------------------------
    Code:
    CONNECT TO STAGING user NEWSADM using 'p4ssw0rd';
    
    CREATE WRAPPER MEGADBWR LIBRARY 'libdb2drda.a' OPTIONS (ADD DB2_FENCED 'N');
    
    CREATE SERVER MEGADB11 TYPE DB2/UDB VERSION '9.1' WRAPPER MEGADBWR AUTHID "NEWSFED" PASSWORD "p4ssw0rd" OPTIONS (ADD DBNAME 'PRODNEWS', PASSWORD 'Y'); 
    
    CREATE USER MAPPING FOR SWGNEWSR SERVER MEGADB11 OPTIONS (REMOTE_AUTHID 'NEWSFED', REMOTE_PASSWORD 'p4ssw0rd');
    
    CREATE NICKNAME PRODNEWS.NEWS_ARTICLES FOR MEGADB11.SWGNEWS.NEWS_ARTICLES;
    CREATE NICKNAME PRODNEWS.NEWS_CATEGORIES FOR MEGADB11.SWGNEWS.NEWS_CATEGORIES;
    CREATE NICKNAME PRODNEWS.SITES FOR MEGADB11.SWGNEWS.SITES;
    
    GRANT SELECT,INSERT,UPDATE,DELETE,CONTROL ON PRODNEWS.NEWS_ARTICLES TO USER NEWSFED;
    GRANT SELECT,INSERT,UPDATE,DELETE,CONTROL ON PRODNEWS.NEWS_CATEGORIES TO USER NEWSFED;
    GRANT SELECT,INSERT,UPDATE,DELETE,CONTROL ON PRODNEWS.SITES TO USER NEWSFED;
    
    SELECT COUNT(*) FROM PRODNEWS.NEWS_ARTICLES;
    SELECT COUNT(*) FROM PRODNEWS.NEWS_CATEGORIES;
    SELECT COUNT(*) FROM PRODNEWS.SITES;
    
    CONNECT RESET;
    =============== =============== =============== ===

    The first error that comes up is when I perform a select query on certain tables:
    Code:
    SELECT
    	*
    FROM
    	PRODNEWS.NEWS_CATEGORIES AS A
    WHERE
    	NOT EXISTS(
    		SELECT
    			CATEGORY_ID
    		FROM
    			SWGNEWS.NEWS_CATEGORIES AS B
    		WHERE
    			A.CATEGORY_ID = B.CATEGORY_ID
    	)
    Gives me this error:
    Warning: odbc_exec() [function.odbc-exec]: SQL error: [IBM][CLI Driver][DB2/AIX64] SQL30090N Operation invalid for application execution environment. Reason code = "22". SQLSTATE=25000 , SQL state 25000 in SQLExecDirect

    The funny and weird thing is that I can perform this same query except on the NEWS_ARTICLES table and the query runs without any errors.

    The second error is when I perform a DELETE:
    Code:
    DELETE FROM
    	PRODNEWS.NEWS_ARTICLES AS A
    WHERE
    	NOT EXISTS(
    		SELECT
    			NEWS_ID
    		FROM
    			SWGNEWS.NEWS_ARTICLES AS B
    		WHERE
    			A.NEWS_ID = B.NEWS_ID
    	)
    Gives me this error:
    SQL1822N Unexpected error code "-507" received from data source "MEGADB11".
    Associated text and tokens are " SQL0507N The cursor specified in the UPDATE
    or DELETE ". SQLSTATE=560BD

    SQL1822N Unexpected error code "-507" received from data source "MEGADB11". Associated text and tokens are " SQL0507N The cursor specified in the UPDATE or DELETE ".
    sqlcode: -1822

    sqlstate: 560BD

    The weird thing yet again is that this query can be performed on the NEWS_CATEGORIES table without any errors.

    If anyone can provide guidance and help on debugging this issue, I would greatly appreciate any help as I have been working endlessly trying to find a solution and what's wrong with the database with no luck.

    Thanks!
Working...