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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:23:18+00:00 2026-05-30T07:23:18+00:00

I created a C++ application that updates a SQLite database. The application reads a

  • 0

I created a C++ application that updates a SQLite database. The application reads a row, does an action with the values in the row, then updates the “modified” column with the current time. I believe that I am only using SELECT, INSERT, CREATE commands.

The application runs correctly for the first few days before problems start to occur. When I checked the database settings with sqlite-administrator I found that there was a table that has a row with a duplicate key values.

I created the table with this command

CREATE TABLE 'XXXX_tasks' ( 'id' INTEGER PRIMARY KEY ,  'data_length' INTEGER,  'data_offset' INTEGER,  'data_table' TEXT,  'device_id' INTEGER,  'modified' INTEGER,  'name' TEXT,  'object_id' INTEGER,  'object_type' TEXT,  'object_units' INTEGER,  'property' INTEGER,  'scan' INTEGER,  'type' TEXT )

The data in the table looks like this (reduced for readability)

ID | Name  | Object ID 
 5 | AV_33 | 33         <===  
 2 | AV_34 | 34 
 3 | AV_35 | 35 
 4 | AV_36 | 36 
 5 | AV_33 | 33         <=== 

It appears that the there are two rows with a duplicate KEY field. At first I thought that it was a corrupted database file, A fluke. I deleted the database file and restarted the application. After a week the same problem occurred. Its repeatable.

You can download/view the database file yourself here http://www.abluestar.com/files/uploads/database_jan312012.db

My question is:

I can’t think of any reason that you could create a create or update a row to have a duplicate primary key value. Any ideas how this could have happen?

  • 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-30T07:23:20+00:00Added an answer on May 30, 2026 at 7:23 am
    sqlite> select distinct id from BACnetIP_tasks order by id;
    5
    2
    3
    4
    5
    

    The two 5s are distinct, and one 5 is less than 2. Sounds like a corrupt file.

    sqlite> pragma integrity_check;
    *** in database main ***
    On tree page 4 cell 1: Rowid 2 out of order (previous was 5)
    Fragmentation of 15 bytes reported as 12 on page 4
    

    Yep. So, the good news is that SQLite sees essentially the same problem you do. Row 2 is, indeed, out of order, since the previous row was 5. Corrupt file.

    Any ideas how this could have happen?

    Not off the top of my head, but the odds are good that the problem is in your code. Almost every time something like this has happened to me, it’s been my problem, not the database’s. (Although I do recall discovering a couple of bugs in Access 2000 a long time ago.)

    SQLite3 supports RENAME TABLE and ADD COLUMN, but it doesn’t support any other parts of the ALTER TABLE syntax. So I don’t think what you’re seeing could be caused by ALTER TABLE statements. Besides, SQL statements are supposed to fail rather than result in an inconsistent database. (That would seem to rule out triggers, too, at least under normal circumstances.)

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

Sidebar

Related Questions

I have created an application that records a series of longitude and latitude values
I have created the application which is based on Sqlite database. So in my
i am creating an app that needs a database. i created it using sqlite
Say my application has a ListView that displays information from a Sqlite database, using
I already have an application that uses the SQLite database and a listadapter. I
I'm creating a application that will fetch data from an SQLite database and display
I need to create a plug-in that updates an application. Look, I have a
I created an application that parses content of secured areas of one webpage after
I have created an application that writes some data to the root folder of
I have created an application that runs in the taskbar. When a user clicks

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.