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

  • Home
  • SEARCH
  • 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 6995921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:05:30+00:00 2026-05-27T20:05:30+00:00

I am trying to implement the nested-set model for a sqlite database. So far

  • 0

I am trying to implement the nested-set model for a sqlite database.
So far I have implemented getting leaf nodes, finding subordinates etc.
I am using this tutorial as a reference
However, I am stuck at inserting a new node.
Here’s the code from the site

LOCK TABLE nested_category WRITE;

SELECT @myRight := rgt FROM nested_category
WHERE name = 'TELEVISIONS';

UPDATE nested_category SET rgt = rgt + 2 WHERE rgt > @myRight;
UPDATE nested_category SET lft = lft + 2 WHERE lft > @myRight;

INSERT INTO nested_category(name, lft, rgt) VALUES('GAME CONSOLES', @myRight + 1, @myRight + 2);

UNLOCK TABLES;

I know that there’s no lock table in sqlite.. my problem here is that I need to pass the result of the first query to the next one. Here it’s done by using a user-created variable by @. I couldn’t figure out how to do it in SQLite.

Thanks in advance.

  • 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-27T20:05:30+00:00Added an answer on May 27, 2026 at 8:05 pm

    An ideea is to replace the variable myRight with the query that generated it.
    That is to move the code into pure SQL.

    UPDATE nested_category SET rgt = rgt + 2 
    WHERE rgt > (SELECT rgt 
                 FROM nested_category
                 WHERE name = 'TELEVISIONS');
    
    UPDATE nested_category SET lft = lft + 2 
    WHERE lft > (SELECT rgt 
                 FROM nested_category
                 WHERE name = 'TELEVISIONS');
    
    INSERT INTO nested_category(name, lft, rgt)
    SELECT 'GAME CONSOLES', rgt + 1, rgt + 2 
    FROM nested_category
    WHERE name = 'TELEVISIONS' ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting started with python. I am trying to implement positional index using nested dictionary.
I'm trying to implement a Rails3 nested form with has-many through association. My model
Trying to implement some nested loops that are spitting out good old nested html
I am trying to implement a nested comment in D. nestingBlockComment : '/+' (options
I'm stuck trying to implement a data model for an app to be deployed
I'm trying to implement a expression handling grammar (that deals with nested parenthesis and
I'm trying to implement Writable class, but i have no idea on how to
I've been trying to implement a dynamic multi-model form with accepts_nested_attributes_for in my rails
I am trying to wrap my mind around the best way to implement nested
All I am currently trying implement something along the lines of dim l_stuff as

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.