SubSonic Forums
All Your Database Are Belong To Us

Oracle Provider Not Generating Views

Latest post 09-10-2008 11:52 AM by DiverKas. 7 replies.
  • 04-18-2008 11:34 AM

    Oracle Provider Not Generating Views

    I wamt to generate a class object for just 1 database object which happens to be a view.  A PK should not be preventing this from working.  When I run SubCommander, nothing is generated.

     <connectionStrings>
          <add name="AppConnection" providerName="System.Data.OracleClient" connectionString="Data Source=x;User ID=x;Password=x" />
      </connectionStrings>

    <SubSonicService defaultProvider="OracleDataProvider">
        <providers>
          <clear />
          <add name="OracleDataProvider" type="SubSonic.OracleDataProvider, SubSonic" connectionStringName="AppConnection" generatedNamespace="xxx" appendWith="_" includeTableList="MyView" />
        </providers>
      </SubSonicService>

     

    Setting ConfigPath: 'web.config'
    Building configuration from web.config
    Adding connection to OracleDataProvider
    Generating classes for OracleDataProvider (0 total)
    Finished
    Setting ConfigPath: 'web.config'
    Building configuration from web.config
    Adding connection to OracleDataProvider
    Generating ODS Controllers for OracleDataProvider (0 total)
    Finished
    Setting ConfigPath: 'web.config'
    Building configuration from web\web.config
    Adding connection to OracleDataProvider
    Setting ConfigPath: 'web.config'
    Building configuration from web.config
    Adding connection to OracleDataProvider
    Generating SPs to Generated\StoredProcedures.vb
    Finished
    Setting ConfigPath: 'web.config'
    Building configuration from web.config
    Adding connection to OracleDataProvider
    Generating Structs to Generated\AllStructs.vb
    Finished
    Running Compiler...
    Writing Files...
    Done!
    Execution Time: 1090ms
     

    Filed under:
  • 04-18-2008 11:58 AM In reply to

    Re: Oracle Provider Not Generating Views

    I also trimmed this down and changed my generate routine to use the generateviews command.  

     

    Setting ConfigPath: 'web.config'
    Building configuration from web.config
    Adding connection to OracleProvider
    Execution Time: 531ms
     

    Same thing as above. 

  • 04-21-2008 2:57 PM In reply to

    Re: Oracle Provider Not Generating Views

     Can someone please help me with this?

  • 04-21-2008 5:27 PM In reply to

    Re: Oracle Provider Not Generating Views

     After digging and digging and digging, I found that this had to do with my schema ownership in the database.

    SubCommander uses the following SQL to get the schema:

     "SELECT a.table_name AS Name FROM user_tables a";

    and for views:

    "SELECT a.view_name AS Name FROM user_views a";

     

     Since the schema is owned by a different user and I will not be given that user's account information, I needed to alter the code as follows:

     In the OracleProvider class, change the code within the Schema Bits region (it is near 3/4 of the way down the file:

     

    private const string MANY_TO_MANY_LIST = "SELECT b.table_name FROM all_constraints a, all_cons_columns b " +
                                                      "WHERE a.table_name = :tableName " +
                                                      "AND a.constraint_type = 'R' " +
                                                      "AND a.r_constraint_name = b.constraint_name " +
                                                      "AND b.table_name like '%' + :mapSuffix";

            const string TABLE_COLUMN_SQL = "SELECT user, a.table_name, a.column_name, a.column_id, a.data_default, " +
                                            "       a.nullable, a.data_type, a.char_length, a.data_precision, a.data_scale " +
                                            "  FROM all_tab_columns a " +
                                            " WHERE a.table_name = :tableName";


            const string SP_PARAM_SQL = @"SELECT a.object_name, a.object_type, b.position, b.in_out,
                                        b.argument_name, b.data_type, b.char_length, b.data_precision, b.data_scale
                                        FROM all_objects a, all_arguments b
                                        WHERE a.object_type IN ('PROCEDURE', 'FUNCTION', 'PACKAGE')
                                        AND a.object_id = b.object_id
                                        AND a.object_name = :objectName";


            const string SP_SQL = @"SELECT a.object_name, a.object_type, a.created, a.last_ddl_time
        `                           FROM all_objects a
                                    WHERE a.object_type IN ('PROCEDURE', 'FUNCTION', 'PACKAGE') ";


            const string TABLE_SQL = "SELECT a.table_name AS Name FROM all_tables a";

            const string VIEW_SQL = "SELECT a.view_name AS Name FROM all_views a";

            const string INDEX_SQL =    "SELECT b.table_name, b.column_name, " +
                                        "       DECODE (a.constraint_type, " +
                                        "               'R', 'FOREIGN KEY', " +
                                        "               'P', 'PRIMARY KEY', " +
                                        "               'UNKNOWN' " +
                                        "              ) constraint_type " +
                                        "  FROM all_constraints a, all_cons_columns b " +
                                        " WHERE a.constraint_name = b.constraint_name " +
                                        "   AND a.constraint_type IN ('R', 'P') " +
                                        "   AND b.table_name = :tableName ";

            const string GET_TABLE_SQL =    "SELECT b.table_name " +
                                            "  FROM all_constraints a, all_cons_columns b " +
                                            " WHERE a.constraint_name = b.constraint_name " +
                                            "   AND a.constraint_type IN ('R', 'P') " +
                                            "   AND b.column_name = :columnName " +
                                            "   AND a.constraint_type = 'P' ";

            const string GET_FOREIGN_KEY_SQL =  "SELECT d.table_name " +
                                                "  FROM all_cons_columns c, all_cons_columns d, all_constraints e " +
                                                " WHERE d.constraint_name = e.r_constraint_name " +
                                                "   AND c.constraint_name = e.constraint_name " +
                                                "   AND d.column_name = :columnName " +
                                                "   AND e.table_name = :tableName ";
           
            const string GET_PRIMARY_KEY_SQL =  "SELECT e.table_name AS TableName, c.column_name AS ColumnName " +
                                                "  FROM all_cons_columns c, all_cons_columns d, all_constraints e " +
                                                " WHERE d.constraint_name = e.r_constraint_name " +
                                                "   AND c.constraint_name = e.constraint_name " +
                                                "   AND d.table_name = :tableName ";

     

    Your database account will need elevated privs. to do this but it will allow your DBA's to help you with that rather than having to know the schema owner. 

  • 04-22-2008 1:04 AM In reply to

    • ranomore
    • Top 10 Contributor
    • Joined on 11-05-2007
    • Salt Lake City
    • Posts 322

    Re: Oracle Provider Not Generating Views

     Sorry no one was helpful on this, haven't seen a lot of vocal Oracle supporters in the forums of late..

    What parts specifically need eleveated privs? Is it just to get DAL generation for a schema you don't own?

  • 04-22-2008 8:19 AM In reply to

    Re: Oracle Provider Not Generating Views

    Sorry I should have been more clear.  When I say elevated privs, I mean access to the sys.all_* tables for that catalog.  Not all users always have that.  It really just depends on how you implement your databases. 

  • 09-10-2008 11:41 AM In reply to

    Re: Oracle Provider Not Generating Views

     Hi davids,

    i did as you instructed... I changed the constants mentioned in the OracleDataProvider class under #region Schema Bits but got no views generated. If I login to Oracle SQL*Plus with the User Id and Password of the SubCommander connection string as listed in the .config file and enter the select string at the SQL> prompt for the VIEW_SQL constant I see alot of views... if I can see the views from SQL*Plus using the same account details that Subsonic uses then i'm thinking that my problem isn't due to a privilege issue? Any ideas?

  • 09-10-2008 11:52 AM In reply to

    Re: Oracle Provider Not Generating Views

    Netrebbek:

     Hi davids,

    i did as you instructed... I changed the constants mentioned in the OracleDataProvider class under #region Schema Bits but got no views generated. If I login to Oracle SQL*Plus with the User Id and Password of the SubCommander connection string as listed in the .config file and enter the select string at the SQL> prompt for the VIEW_SQL constant I see alot of views... if I can see the views from SQL*Plus using the same account details that Subsonic uses then i'm thinking that my problem isn't due to a privilege issue? Any ideas?

     

    Its not whether you can see the view, its whether you can see the system tables that SubSonic queries that give it the metadata about the view.  Thats really the crux of the problem.  At least as far as what I can determine from the thread. 

    SubSonic really needs pretty elevated priviliges to determine what needs about table, view, SP details.  I usually create an elevated account for SubSonic to use to generate the DAL, and others for normal use by the application.

    Software Is Like Cathedrals: First we build 'em, then we pray.
Page 1 of 1 (8 items) | RSS