Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7514873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:37:42+00:00 2026-05-30T00:37:42+00:00

I have a script that I use to construct both the tables and stored

  • 0

I have a script that I use to construct both the tables and stored procedures. For example I have a column of type varchar. varchar requires a size parameter, that size I also use as parameters in stored procedures and within those procedures.

is it possible to have thequivalentnt of a #define for its size, so I can easily adjust the size without the necessity of having to change ithroughht the whole of the script?

I am using MySql workbench.

EDIT

I have tried SET and DECLARE

I have a script – this is (abridged)

CREATE TABLE `locations`
(
   `location`  VARCHAR(25)        NOT NULL
);

...
CREATE PROCEDURE AddLocation (IN  location VARCHAR(25)
BEGIN
...
END$$

What I am trying to achieve is replace the values 25 in the script with a constant – similar to a #define at the top of the script that creates the table and stored procedures, so I am able to easily change the 25 to another number.

Anybody has found a solution to this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:37:44+00:00Added an answer on May 30, 2026 at 12:37 am

    The C Pre Processor (cpp) is historically associated with C (hence the name), but it really is a generic text processor that can be used (or abused) for something else.

    Consider this file, named location.src (more on that later).

    // C++ style comments works here
    /* C style works also */
    -- plain old SQL comments also work,
    -- but you should avoid using '#' style of comments,
    -- this will confuse the C pre-processor ...
    
    #define LOCATION_LEN 25
    
    /* Debug helper macro */
    #include "debug.src"
    
    DROP TABLE IF EXISTS test.locations;
    CREATE TABLE test.locations
    (
       `location` VARCHAR(LOCATION_LEN) NOT NULL
    );
    
    DROP PROCEDURE IF EXISTS test.AddLocation;
    delimiter $$
    CREATE PROCEDURE test.AddLocation (IN location VARCHAR(LOCATION_LEN))
    BEGIN
      -- example of macro
      ASSERT(length(location) > 0, "lost or something ?");
    
      -- do something
      select "Hi there.";
    END
    $$
    
    delimiter ;
    

    and file debug.src, which is included:

    #ifdef HAVE_DEBUG
    #define ASSERT(C, T)                                          \
      begin                                                       \
        if (not (C)) then                                         \
          begin                                                   \
            declare my_msg varchar(1000);                         \
            set my_msg = concat("Assert failed, file:", __FILE__, \
                                ", line: ", __LINE__,             \
                                ", condition ", #C,               \
                                ", text: ", T);                   \
            signal sqlstate "HY000" set message_text = my_msg;    \
         end;                                                     \
        end if;                                                   \
      end
    #else
    #define ASSERT(C, T) begin end
    #endif
    

    When compiled with:

    cpp -E location.src -o location.sql
    

    you get the code you are looking for, with cpp expanding #define values.

    When compiled with:

    cpp -E -DHAVE_DEBUG location.src -o location.sql
    

    you get the same, plus the ASSERT macro (posted as a bonus, to show what could be done).

    Assuming a build with HAVE_DEBUG deployed in a testing environment (in 5.5 or later since SIGNAL is used), the result looks like this:

    mysql> call AddLocation("Here");
    +-----------+
    | Hi there. |
    +-----------+
    | Hi there. |
    +-----------+
    1 row in set (0.00 sec)
    
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> call AddLocation("");
    ERROR 1644 (HY000): Assert failed, file:location.src, line: 24, condition length(location) > 0, text: lost or something ?
    

    Note how the file name, line number, and condition points right at the place in the source code in location.src where the assert is raised, thanks again to the C pre processor.

    Now, about the “.src” file extension:

    • you can use anything.
    • Having a different file extension helps with makefiles, etc, and prevents confusion.

    EDIT: Originally posted as .xql, renamed to .src for clarity. Nothing related to xml queries here.

    As with any tools, using cpp can lead to good things, and the use case for maintaining LOCATION_LEN in a portable way looks very reasonable.
    It can also lead to bad things, with too many #include, nested #ifdef hell, macros, etc that at the end obfuscate the code, so your mileage may vary.

    With this answer, you get the whole thing (#define, #include, #ifdef, __FILE__, __LINE__, #C, command line options to build), so I hope it should cover it all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that makes use of a package (PKG_MY_PACKAGE). I will change
I have a script like that genhash --use-ssl -s $IP -p 443 --url $URL
I have a script that uses $(document).ready , but it doesn't use anything else
I have a Ruby script in my Rails app that I use to load
I have a Perl script I wrote for my own personal use that fetches
I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example),
I currently have a script that I am trying to use to access an
I have some awk scripts that use gawk from cygwin. Now I need to
In a couple of scripts that I use I have problem that is intermittent.
I have a small helper app that I use to inject scripts into html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.