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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:08:39+00:00 2026-06-18T14:08:39+00:00

I have stripped down my application and database context to the simplest bits. I

  • 0

I have stripped down my application and database context to the simplest bits. I have two tables, Maps and Markers. Many Markers exist for each map. With an existing Map, I can’t seem to insert new Markers; I am getting the default error callback.

Tracing through the jaydata.js, I am getting an error in the SqLiteProvider.js file, in the exec function. It is an SQL failure, and is attempting to insert the Map (with the primary key set) into the table, which fails. What am I doing wrong?

My Context:

$data.Entity.extend("$org.types.Marker", {
    Id: { type: "int", key: true, computed: true },
    Left: { type: "int", required: true },
    Top: { type: "int", required: true },
    Color: { type: "string", required: true },
    Name: { type: "string", required: true },
    Map: { type: "$org.types.Map", inverseProperty: "Markers" }
});


$data.Entity.extend("$org.types.Map", {
    Id: { type: "int", key: true, computed: true },
    Title: { type: "string", required: true },
    Src: { type: "string", required: true },
    Height: { type: "int", required: true },
    Width: { type: "int", required: true },
    Markers: { type: "Array", elementType: "$org.types.Marker", inverseProperty: "Map" }
});

$data.EntityContext.extend("$org.types.OrgContext", {
    Maps: { type: $data.EntitySet, elementType: $org.types.Map },
    Markers: { type: $data.EntitySet, elementType: $org.types.Marker },
 });

var DB = new $org.types.OrgContext({ name: "webSql", databaseName: "Testing"});

My test code:

DB.Maps.single( function (map) { return map.Id == 1; }, {}, function(map) {
        var marker = new $org.types.Marker({
            Left: 250,
            Top: 350,
            Color: 'green',
            Name: 'Example',
            Map: map});

        DB.Markers.add(marker);
        DB.saveChanges(function() {
            alert(marker.Id);
        });

    });
  • 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-18T14:08:40+00:00Added an answer on June 18, 2026 at 2:08 pm

    The example doesn’t insert the map object. This is not a problem if you already have it.

    There is a general problem, which is forgotten many times: the context.onReady() should be used before accessing data with the provider.

    This won’t solve the problem per se, there is one line should be added before saving the ne marker object:

    DB.Maps.attach(map);
    

    This is necessary to move the object to the scope of the context and set the entityState property of the map to $data.EntityState.Unchanged. If you read an entity from the DB, the entityState will be unknown, and the provider tries to save it as a new record. Trying to saving the map entity as a new record caused an SQL error, because there was an existing record with ID=1.

    The updated code looks like bellow:

    var DB = new $org.types.OrgContext({ name: "webSql", databaseName: "Testing" });
    
            DB.onReady(function () {
                DB.Maps.single(function (map) { return map.Id == 1; }, {}, function (map) {
                    DB.Maps.attach(map); //this sets map.entityState = $data.EntityState.Unchanged;
                    var marker = new $org.types.Marker({
                        Left: 250,
                        Top: 350,
                        Color: 'green',
                        Name: 'Example',
                        Map: map
                    });
                    DB.Markers.add(marker);
                    DB.saveChanges(function () {
                        alert(marker.Id)
                    });
                });
            });
    

    UPDATE: if you save a new Maker with a new Map entity, there is no need to attach, and your code needs only the DB.onReady()

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

Sidebar

Related Questions

Say I have 3 tables in a Tennis Application (stripped down removing irrelevant info):
When I execute the follow two queries (I have stripped them down to absolutely
I have a stripped down shopping cart application, currently with one model cart, the
I have a simple ANTLR grammar, which I have stripped down to its bare
This is part of a bigger selection, but I have stripped it down to
Currently i have some interfaces (stripped down for here): public interface IJobGroup { string
I'm writing a web application using a <canvas> element. For simplicity, I have stripped
I have a custom class (to simplify stuff, I have stripped down the codes):
I have stripped my problem down to the most minimal form, as seen here:
I have the following (stripped down) class interfaces: @interface ScriptEvent : NSObject { ...

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.