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 8461995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:02:28+00:00 2026-06-10T14:02:28+00:00

I am converting a stored procedure from MS-SQL to MySQL. It is based around

  • 0

I am converting a stored procedure from MS-SQL to MySQL. It is based around Directed Acyclic Graphs.

The original MS-SQL script is in Listing 2 on the following page: http://www.codeproject.com/Articles/22824/A-Model-to-Represent-Directed-Acyclic-Graphs-DAG-o

The stored procedure saves fine but is not removing any rows from the database.
I have tried running through Debugger for MySQL and it will pass the first time and seems to update the table I am using for the temporary data, but doesn’t update the “edges” table. It also doesn’t drop the table at the end.

Second run through, if I remove the purgelist table manually, it will run through to the REPEAT statement and then I get Error Code: 1137 SQLState: HY000, Message: Can’t reopen table: ‘purgelist’.
Originally I wanted to use a temporary table but I understand I cannot reference the temporary table multiple times in the way my SELECT does, however, I am surprised this error is occurring on a non-temporary table. Also, I recognise in a multi session environment I will need purgelist to be dynamically named.

Here is the MySQL code:

DELIMITER //
CREATE PROCEDURE RemoveEdge(
IN iId int(11)
)

MAIN_BLOCK: BEGIN

DECLARE counter int default 0;
DECLARE rcount int default 0;
SET counter = ( SELECT id FROM edges WHERE id = iId AND hops = 0 );
IF counter = 0 THEN
   BEGIN
      LEAVE MAIN_BLOCK;
   END;
END IF;

CREATE TABLE purgeList (id int);

-- step 1: rows that were originally inserted with the first
-- AddEdge call for this direct edge
INSERT INTO purgeList
    SELECT id
      FROM edges
      WHERE directEdgeId = iId;

-- step 2: scan and find all dependent rows that are inserted afterwards
REPEAT
    INSERT INTO purgeList
        SELECT id    
            FROM edges
            WHERE hops > 0
                AND ( entryEdgeId IN ( SELECT id FROM purgeList ) 
                    OR exitEdgeId IN ( SELECT id FROM purgeList ) )
            AND id NOT IN (SELECT id FROM purgeList );
    SET rcount = ROW_COUNT();
UNTIL rcount = 0
END REPEAT;

DELETE FROM edges
   WHERE id IN ( SELECT id FROM purgeList);
DROP TABLE purgeList;
END //
DELIMITER ;

I’ve double checked my syntax but I assume there is an error in there somewhere. Any help greatly appreciated.

  • 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-06-10T14:02:29+00:00Added an answer on June 10, 2026 at 2:02 pm

    There may be a cleaner approach but I think you need to create a temporary table inside the Repeat that is populated with

    SELECT id FROM purgeList
    

    and then reference the temp table rather than than purgeList, something like this:

    REPEAT
    
        CREATE TABLE innerPurgeList (id int);
    
        INSERT INTO innerPurgeList
           SELECT id
                FROM purgeList;
    
        INSERT INTO purgeList
           SELECT id    
                FROM edges
                WHERE hops > 0
                    AND ( entryEdgeId IN ( innerPurgeList ) 
                        OR exitEdgeId IN ( innerPurgeList ) )
                AND id NOT IN ( innerPurgeList );
        SET rcount = ROW_COUNT();
    
        DROP TABLE innerPurgeList;
    
    UNTIL rcount = 0
    END REPEAT;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am converting a stored procedure from MS-SQL to MySQL. It is based around
I'm working on converting a stored procedure from SQL server to Oracle. This stored
I'm converting a stored procedure in some software I'm maintaining from SQL Server SQL
Converting a couple stored procedures from MySQL to Microsoft SQL server. Everything is going
I'm trying to call a stored procedure (on a SQL 2005 server) from C#,
I'm having a never-ending problem with trying to call a stored procedure from a
I am converting a stored procedure which I had previously written as a string
Is there a way to write SQL Server Stored Procedure which to be strongly
I am trying to make one stored procedure only in SQL Server that lets
We are in the process of converting SQL / Stored Procedures to LINQ to

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.