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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:54:31+00:00 2026-05-22T16:54:31+00:00

I’m having a bit of trouble with SQLite in Android. As my application supports

  • 0

I’m having a bit of trouble with SQLite in Android. As my application supports Android 1.6, I am unable to use foreign keys, so have written triggers to enforce these constraints.

My two tables are vehicle and fuel_use. vehicle and fuel_use both have a registration_number column. My trigger ensures that I cannot update registration_number in vehicle when there are entries in fuel_use referencing registration_number in vehicle:

        //on update vehicle
    db.execSQL("CREATE TRIGGER fk_update_vehicle_trigger_fuel_references_vehicles_reg_no " +
            "BEFORE UPDATE ON " + VEHICLE_TABLE_NAME +
            " FOR EACH ROW BEGIN " +
            "SELECT RAISE(ROLLBACK, 'update on table " + VEHICLE_TABLE_NAME + " violates foreign key constraint fk_update_vehicle_trigger_fuel_references_vehicles_reg_no') " +
            "WHERE (SELECT " + REGISTRATION_NO_COLUMN + " FROM " + FUEL_USE_TABLE_NAME +
            " WHERE " + REGISTRATION_NO_COLUMN + " = OLD." + REGISTRATION_NO_COLUMN + ") IS NOT NULL; " +
            "END;");

This works fine in that it stops updates which would leave fuel_use rows referencing non-existent vehicle rows. However, I have just discovered a problem – when I try to update a differnt column in vehicle – initial_mileage – this trigger disallows it and forces a rollback. I understand why this is happening but don’t know how to rewrite the trigger so only updates on the registration_number column force a rollback. I have tried:

BEFORE UPDATE ON " + VEHICLE_TABLE_NAME + "." + REGISTRATION_NO_COLUMN

but this did not work. In fact an exception was thrown.

Any help would be gratefully received.

  • 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-22T16:54:32+00:00Added an answer on May 22, 2026 at 4:54 pm

    Try:

    db.execSQL("CREATE TRIGGER fk_update_vehicle_trigger_fuel_references_vehicles_reg_no " +
            "BEFORE UPDATE OF " + REGISTRATION_NO_COLUMN + " ON " + VEHICLE_TABLE_NAME +
            " FOR EACH ROW BEGIN " +
            "SELECT RAISE(ROLLBACK, 'update on table " + VEHICLE_TABLE_NAME + " violates foreign key constraint fk_update_vehicle_trigger_fuel_references_vehicles_reg_no') " +
            "WHERE (SELECT " + REGISTRATION_NO_COLUMN + " FROM " + FUEL_USE_TABLE_NAME +
            " WHERE " + REGISTRATION_NO_COLUMN + " = OLD." + REGISTRATION_NO_COLUMN + ") IS NOT NULL; " +
            "END;");
    

    See if that works.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.