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

The Archive Base Latest Questions

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

I’m currently implementing some functionality relying on an SQLite database. While doing so, I’m

  • 0

I’m currently implementing some functionality relying on an SQLite database. While doing so, I’m being confronted with a limitation that I did not anticipate. It made me wonder whether I’m tackling my problem the right way. I’m hoping someone can suggest a different approach that takes into account the requirements.

Goal

The goal is to store a large collection of objects into a database as fast as possible. However, if at any point, it is determined that the storage of these objects should not take place, the operation should not have any effect on the database. The exact storage queries (the ‘inserts’) depend on previous inserts.

Use Case

Consider a very large collection of ‘instance information packages’, each package represents part of the knowledge of some corresponding abstract instance. The total collection thus represents the complete knowledge of one or more abstract instances. The information of each package consists of:

  1. an instance_id; used to uniquely identify the abstract instance to which this information relates.
  2. an attributes map; (attribute_uri, attribute_value)-pairs where attribute_uri uniquely identifies an attribute and attribute_value is a corresponding text value.

Both instance_id and attribute_id are found in a table, respectively TBL_INSTANCES and TBL_ATTRIBUTES. The database model used here is an EAV-model.

After insertion, a table TBL_ENTRIES should contain entries in the form:

[ entry_id | instance_id | attribute_id | attribute_value ]

Issue

The implementation seemed to be straightforward:

  1. Set a savepoint
  2. Begin the transaction
  3. Prepare statement for many inserts in TBL_ENTRIES
  4. For each instance in the collection:
    • 4.1. Lookup instance_id in TBL_INSTANCES. If not present, add it to TBL_INSTANCES
    • 4.2. For each attribute in the instance’s attribute map:
      • 4.2.1. Lookup attribute_id in TBL_ATTRIBUTES. If not present, add it to TBL_ATTRIBUTES.
      • 4.2.2. Add entry to TBL_ENTRIES
  5. If at any point an error occured, rollback to the savepoint, otherwise commit.

Unfortunately, in the lookup steps (4.1 and 4.2.1), SQLite reports a “cannot start a transaction within a transaction” error. Reading the documentation, it seems to lie in the fact the lookups call the sqlite3_exec routines, which (unless I am mistaken) seems to setup a transaction internally.

Question

If nested transactions are not allowed, how am I supposed to perform the lookup steps (which are basically “INSERT OR REPLACE” expressions followed by a “SELECT” query)? Is there some way to avoid them or to use sqlite3_exec within the current transaction? If not, am I approaching my problem the wrong way? Perhaps I should not use separate integer as keys, e.g. use attribute_uri directly as key instead of looking up the corresponding attribute_id.

In any case, I still need to do something equivalent during the transaction as the real speed gain lies in preparing the statements over the collection of instances, not the collection of attributes: an instance might have just one or two attributes whereas the number of instances in the instance collection will always be very large.

I’m using C/C++, SQLite 3.7.

Any suggestions or remarks on my approach are much 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-17T14:45:03+00:00Added an answer on June 17, 2026 at 2:45 pm

    From SQLite documentation on BEGIN TRANSACTION:

    Transactions created using BEGIN…COMMIT do not nest. For nested
    transactions, use the SAVEPOINT and RELEASE commands

    I seem to recall that nested transaction should be already there for any SQLite 3.7.*.

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

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported

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.