Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Location
    Norway
    Posts
    7

    Unanswered: "Including" files

    Hello!

    I would like to have a set of defined constants available to a set of procedures, somewhat like #include in C.

    I have for example a procedure with 6 sub-procedures, all of which require a number of constant values. How can i share these values and datatypes between procedures without using parameters?

    Global values for our whole application would also be useful.

    I have found no way to do this using ASE functionality - any ideas?

    regards,
    Olav Karlsen

  2. #2
    Join Date
    Aug 2004
    Posts
    1

    I guess the answer is "no"

    I also wanted to have a set of constants (at least global to a database).
    I don't see a way to do it. From the fact that you posted in February (I just joined this forum), it looks like noone else found a solution.
    I guess the best we can do is to cut and paste a section like:
    DECLARE @OneConstant varchar(10)
    DELCARE @AnotherConstant int
    SELECT @OneConstant = "A string"
    SELECT @AnotherConstant = 10

    But you have to paste it into every routine, and if it changes, you have to change it for every routine. Not at all what we want.
    If you hear of any way to do it, please post a reply.
    Thanks.

  3. #3
    Join Date
    Jun 2004
    Location
    Paris, France
    Posts
    43
    where i work, we usually use a table which contains all the parameters you want...

    indeed you have to call these parameters in every single procedure which needs them, but they are global to your application, you can modify them once for all the users, ...

  4. #4
    Join Date
    Feb 2004
    Location
    Norway
    Posts
    7

    A different solution

    Hi!

    We thought about storing constants in a database table, but decided against that. It would definitely improve maintainability, but increase code size and maybe complexity.

    We rather solved our problem by making a small Perl-script that preprocesses the SQL source code. The line
    Code:
    --#include <filename>
    in the SQL-code would be replaced by the contents of the named file.

    All our procedures are version controlled and we use good old fashioned makefiles, so I just call my little preprocessor like in C when making:
    Code:
    sqlpre.pl file.sql > destcat/file.sql
    It is not ideal:
    - not very efficient, you will probably be declaring a lot more variables than you'll be using in each procedure
    - the line numbers in the error messages won't be correct compared to the source file
    - if you include multiple files where the same constant is declared twice (which of course shouldn't happen, but...) - ASE barfs.

    But it works pretty well!

  5. #5
    Join Date
    Mar 2001
    Location
    Lexington, KY
    Posts
    606
    Couldn't you do dynamic SQL? Say store the "DECLARE @foo" text in a separate text column in a table.

    Select it into a varchar variable, then EXEC( @result )?
    Thanks,

    Matt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •