in

CodeSmith Community

Your Code. Your Way. Faster!

The "Unofficial" Oracle Schema Provider For CodeSmith

Last post 09-26-2006 1:51 PM by onderorgun. 39 replies.
Page 1 of 3 (40 items) 1 2 3 Next >
Sort Posts: Previous Next
  • 02-27-2004 7:24 AM

    • gmcelhanon
    • Top 75 Contributor
    • Joined on 05-19-2003
    • Austin, TX
    • Posts 62
    • Points 137,250

    The "Unofficial" Oracle Schema Provider For CodeSmith

    This is the location of the most up-to-date version of the unofficial Oracle Schema Provider for CodeSmith.  Thanks goes out to Michael Toscano (aka VikingCoder) for starting a new Oracle provider based solely on the System.Data.OracleClient namespace.
     
    To "install" the provider, just copy the following files to your C:\Program Files\CodeSmith\v2.5 (or equivalent) folder:
    • SchemaExplorer.OracleNativeSchemaProvider.dll
    • SchemaExplorer.OracleNativeSchemaProvider.dll.config
    The DLL is built against the final release of CodeSmith 2.5.  You shouldn't have to rebuild it.
     
    RANDOM NOTES:
    The CommandSchema objects returned from the provider will now have the following properties:
    • CS_ObjectType (i.e "PACKAGE")
    • CS_Status (i.e. "VALID", "INVALID")
    • CS_ObjectId (OBJECT_ID of PACKAGE where command resides)
    • CS_OverloadNumber (will be -1 if no overload exists, or a number > 0 if overloads are present)
    • CS_FullName (will contain the original "raw" command name prefixed with the owner).
    • CS_Name (will contain the original "raw" command name)
    To support overloads in Oracle, the provider reports the Command.Name property as CUSTOMER.MODIFY[1], CUSTOMER.MODIFY[2], and so on.  What this means is that in order for you to write templates that will handle overloaded Oracle procedures correctly, you'll need to use the CS_Name extended property value of the CommandSchema object instead of the Name property.
     
    I have added support for SQL Server-like extended properties through creation of a CODESMITH_EXTENDED_PROPERTIES table (which is automatically excluded from the list returned by GetTables, by the way).  This is a very powerful feature and I have already started putting it to great use for allowing fine grained control of certain aspects of my PL/SQL generation process (i.e. defining lookup tables and columns, being able to exclude certain columns from all procedure signatures, like CREATEDATE and MODIFIEDDATE, and to provide defaults for those values when they're excluded).  The possibilities are endless.
     
    I have also added support for a custom configuration file for use with the DLL to configure the behavior of the most critical parts of the provider.  By default it takes the most conservative approach (no extended properties support).  This is what it looks like:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <appSettings>
            <!-- Indicates the schema in which the CODESMITH_EXTENDED_PROPERTIES table should reside.
                    Comment out this entry to always use current user's schema -->
            <!--
            <add key="ExtendedPropertiesTableOwner" value="SYSTEM" />
            -->
       
            <!-- Indicates whether or not the provider should automatically create the extended properties table.
                    Setting this to true creates the table in the schema specified by the 'ExtendedPropertiesTableOwner'
                    value above, or the current user's schema if value isn't present -->
            <add key="AutoCreateExtendedPropertiesTable" value="false" />
       
            <!-- Specifies whether to show user owned objects only. -->
            <add key="ShowMySchemaOnly" value="true" />
           
            <!-- Specifies whether to allow schema provider to execute procedures that return REF CURSORs to determine
                    the column schema information. Allowing this can result in a change in the state of the database due to
                    things like explicit transaction handling in PL/SQL or usage of a sequence's 'nextval' property. -->
            <add key="AllowGetCommandResultSchemas" value="false" />
        </appSettings>
    </configuration>
    You can enable extended property support by allowing the schema provider to go ahead and create the CODESMITH_EXTENDED_PROPERTIES table if it is not present, and yet still control where it gets created and used from.  It also allows you to easily filter the "visible" schema objects to just the ones you own directly.  And of course, it allows you to decide whether or not to allow the provider to execute procedures (wrapped in transactions that get rolled back) to derive the command results.  By default this behavior is disabled.
     
    Revision History:
    2/2/2004 - First release.
    2/3/2004 - Fixed a bug in GetCommandParameters related to procedure overload handling
    2/27/2004 - Added the user name (if present in the connect string) to the value return by the GetDatabaseName method.
    10/2/2004 - Attached a version of this provider compiled for CodeSmith 2.6 (OracleNativeSchemaProvider_26.zip).
     
     

    Post Edited By Moderator (ejsmith) : 6/13/2005 7:13:07 PM GMT

    • Post Points: 680
  • 03-08-2004 7:41 AM In reply to

    • herrpiet
    • Not Ranked
    • Joined on 03-08-2004
    • Posts 3
    • Points 15

    RE: The "Unofficial" Oracle Schema Provider For CodeSmith

    Hi,
    i'm new to codesmith and using oracle. Now i'm trying to generate code for my tables, but i can't get the connection to oracle working.  I get this error: Unable to populate tables.  Please check your data source properties and try again.
    Maybe it's the connection string. I am using this.
    Data Source=GGEPD1; User ID=bla; Password=bla;
    Where GGEPD1 is defined in my tnsnames.ora like
    GGEPD1.GRB.AMSTERDAM.NL =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = servername)(PORT = 1521))
        )
        (CONNECT_DATA =
          (SID = ggepd1)
        )
      )
    Is there anything else i should do or is the connectionstring wrong?










    • Post Points: 5
  • 03-10-2004 9:05 AM In reply to

    • gmcelhanon
    • Top 75 Contributor
    • Joined on 05-19-2003
    • Austin, TX
    • Posts 62
    • Points 137,250

    RE: The "Unofficial" Oracle Schema Provider For CodeSmith

    That's pretty much the correct connect string.  My service name is oracle.mylastname, and that's what I use for the "Data Source" parameter.  I'd fiddle with that a bit to see if you need the fully qualified name or something like that.
     
    Other than that, you can always try debugging with the source that's included...
    • Post Points: 5
  • 03-11-2004 9:52 AM In reply to

    • herrpiet
    • Not Ranked
    • Joined on 03-08-2004
    • Posts 3
    • Points 15

    RE: The "Unofficial" Oracle Schema Provider For CodeSmith

    Hi,
    I know the problem now. It has to do with a reference to the System.Data.OracleClient.dll.
    I tried the previous version of the oracle schema provider, cause it had the sourcecode included. I adjusted the reference to System.Data.OracleClient.dll and compiled it and then it worked. Only now i just use the old version, so maybe you could post the sourcecode to the new version as well?
     
    Anyway thanks for the provider. It 's excellent, i really enjoy using Sourcesmith. It's great.\
     
    Peter
    • Post Points: 5
  • 03-11-2004 1:41 PM In reply to

    • gmcelhanon
    • Top 75 Contributor
    • Joined on 05-19-2003
    • Austin, TX
    • Posts 62
    • Points 137,250

    RE: The "Unofficial" Oracle Schema Provider For CodeSmith

    The source for the provider is included in the zip file attached at the top of this thread... I just double checked.
    • Post Points: 5
  • 03-17-2004 6:52 AM In reply to

    • herrpiet
    • Not Ranked
    • Joined on 03-08-2004
    • Posts 3
    • Points 15

    RE: The "Unofficial" Oracle Schema Provider For CodeSmith

    OK, my mistake. Sorry. It's there. I allready recompiled it and now it's working fine. Thanx.
    • Post Points: 5
  • 04-01-2004 9:29 PM In reply to

    • danlogan9
    • Not Ranked
    • Joined on 04-01-2004
    • Posts 3
    • Points 15

    RE: The "Unofficial" Oracle Schema Provider For CodeSmith

    Hey Geoff, I needed some sort of SQL returned by GetCommandText so I dumped in the following: 
        public string GetCommandText(string connectionString, CommandSchema command)
        {
          int period = command.Name.IndexOf(".");
          string name = command.Name;
          string procName = command.Name;
          string type = command.ExtendedProperties["CS_ObjectType"].Value.ToString();
         
          if (type == "PACKAGE") {
            type = "PACKAGE BODY";
            name = command.Name.Substring(0, period );
            procName = command.Name.Substring(period + 1, command.Name.Length - period - 1);
          }
         
            string sql = string.Format(
              @"SELECT
                  TEXT
                FROM
                  DBA_SOURCE
                  , (
                    SELECT
                      LINE
                    FROM
                      DBA_SOURCE
                    WHERE (TRIM(REPLACE(UPPER(TEXT), ' ', '')) LIKE ('PROCEDURE{1}%') OR TRIM(REPLACE(UPPER(TEXT), ' ', '')) LIKE ('FUNCTION{1}%'))
                      AND NAME = '{0}'
                      AND TYPE = '{2}') BEGINLINE
                  , (
                      SELECT
                        LINE
                      FROM
                        DBA_SOURCE
                      WHERE (TRIM(REPLACE(UPPER(TEXT), ' ', '')) LIKE ('END{1};%') OR TRIM(REPLACE(UPPER(TEXT), ' ', '')) LIKE ('END;%'))
                        AND NAME = '{0}'
                        AND TYPE = '{2}'
                    ) ENDLINE
                WHERE NAME = '{0}'
                  AND TYPE = '{2}'
                  AND DBA_SOURCE.LINE BETWEEN BEGINLINE.LINE AND ENDLINE.LINE
              "
            , name
            , procName
            , type
            );
           
            using (OracleConnection conn = new OracleConnection(connectionString)) {
              conn.Open();
              using (OracleCommand cmd = new OracleCommand(sql, conn)) {
                using (OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)) {
                  StringBuilder source = new StringBuilder();
                  try{
                    while (reader.Read()) {
                      source.Append(reader["TEXT"].ToString().Trim() + Environment.NewLine);
                    }
                  }catch (Exception e){
                    return e.Message + Environment.NewLine + sql;
                  }
                  return source.ToString();
                }
              }
            }
          //throw new NotImplementedException("Retrieval of command text has not yet been implemented.");
        }
    It can pull back most well formatted procedures and functions, both standalone and in a package.  It does not handle overloaded procs yet, but it is a start.
     
    I have a few questions and comments but I am going to wait until I can check it out in the code first.
     
    Nice job, thanks.
    • Post Points: 5
  • 04-03-2004 7:41 PM In reply to

    • gmcelhanon
    • Top 75 Contributor
    • Joined on 05-19-2003
    • Austin, TX
    • Posts 62
    • Points 137,250

    RE: The "Unofficial" Oracle Schema Provider For CodeSmith

    I also have a fix related to extended properties on ParameterSchema objects. I will review your code above and include in an update sometime soon (I'm in the middle of configuring a new box, and so this is a little low on my priority list at the moment)
    • Post Points: 5
  • 04-03-2004 11:19 PM In reply to

    • danlogan9
    • Not Ranked
    • Joined on 04-01-2004
    • Posts 3
    • Points 15

    RE: The "Unofficial" Oracle Schema Provider For CodeSmith

    Hold off on adding it in. I found a few issues I am working through.  I want to propose some changes to input and output params when they are a PL/SQL Record type.  When I get to work on Monday, I will detail out what I am proposing.
    • Post Points: 5
  • 04-09-2004 4:53 PM In reply to

    • danlogan9
    • Not Ranked
    • Joined on 04-01-2004
    • Posts 3
    • Points 15

    RE: The "Unofficial" Oracle Schema Provider For CodeSmith

    I have attached a copy of my OracleNativeSchemaProvider.  I made some changes in GetCommandParameters and GetCommandText.  As for GetCommandParameters, I changed the SQL a little and added some code that adds field information about a PLSQL Record as ExtendedProperties about the record.  This should not be a long term solution because I believe that a PLSQL Record could contain PLSQL Records and that should be handled.  GetCommandText has an updated SQL statement in it from what I originally posted that is more accurate.  This at some point should be augmented to handle overloaded procedures.
    • Post Points: 5
  • 05-13-2004 6:25 PM In reply to

    • gbeltrao
    • Top 500 Contributor
    • Joined on 03-17-2004
    • Raleigh, NC
    • Posts 12
    • Points 295

    RE: The "Unofficial" Oracle Schema Provider For CodeSmith

    Anybody has a Oracle template (like BusinessObjectGenerator.cst and StoredProcedures.cst) that could share?

    Thanks!

    The Lord is my Rock and my salvation
    • Post Points: 5
  • 06-26-2004 10:33 PM In reply to

    • mkamoski
    • Top 150 Contributor
    • Joined on 06-25-2004
    • GMT-0500
    • Posts 25
    • Points 590

    RE: The "Unofficial" Oracle Schema Provider For CodeSmith

     

    Dan--

    WRT to your post below, I unzipped that file and there seems to be just one *.CS file in it.

    Did I dod something wrong?

    The reason that I ask is because at the beginning of this thread, it says there are 2 files involved, namely...

    "

    SchemaExplorer.OracleNativeSchemaProvider.dll

    SchemaExplorer.OracleNativeSchemaProvider.dll.config

    "

    ...but I don't see either of those in this latest ZIP attachment.

    Can you help with this?

    Please advise.

    Thank you.

    --Mark

    DanTheDrywallMan said...
    I have attached a copy of my OracleNativeSchemaProvider.  I made some changes in GetCommandParameters and GetCommandText.  As for GetCommandParameters, I changed the SQL a little and added some code that adds field information about a PLSQL Record as ExtendedProperties about the record.  This should not be a long term solution because I believe that a PLSQL Record could contain PLSQL Records and that should be handled.  GetCommandText has an updated SQL statement in it from what I originally posted that is more accurate.  This at some point should be augmented to handle overloaded procedures.
    • Post Points: 5
  • 09-22-2004 3:48 PM In reply to

    • fgardel
    • Not Ranked
    • Joined on 09-22-2004
    • Posts 1
    • Points 5

    RE: The "Unofficial" Oracle Schema Provider For CodeSmith

    I'm also looking for a ".cst" sample like the "StoredProcedures.cst" or similar, that works in oracle....

    ... can anyone help me? (i have see in the thread the same question, but or I am wrong, or the response points to the OracleSchemaProvider.dll and not to a .cst sample....)

    Thanks in advance

    Felix Gardel

    • Post Points: 5
  • 10-01-2004 9:24 AM In reply to

    • sergeVM
    • Not Ranked
    • Joined on 10-01-2004
    • Posts 3
    • Points 15

    RE: The "Unofficial" Oracle Schema Provider For CodeSmith

    Hi,
     
    The provider is not showing up when defining a connection to the Oracle database (in the dropdown box). I did copy the .config and dll to the CodeSmith/v2.6 folder. Anyone who has an idea how I should fix this?
    • Post Points: 5
  • 10-02-2004 7:41 PM In reply to

    • fhijazi
    • Not Ranked
    • Joined on 10-02-2004
    • Posts 1
    • Points 85

    RE: The "Unofficial" Oracle Schema Provider For CodeSmith

    Hi all
    i am having the same problem as sergeVM the oracle provider works in 2.5 version but not with 2.6.
    does anyone have a solution??
    • Post Points: 85
Page 1 of 3 (40 items) 1 2 3 Next >
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems