Sqlite错误:FOREIGN KEY约束失败

时间:2018-08-22 07:10:29

标签: sqlite

我正在尝试在sqlite中更新员工数据。员工ssn的两个数据号被错误地交换了,现在当我尝试再次使用以下代码交换数据时:

    var clusterSvgTemplate =
'<svg xmlns="http://www.w3.org/2000/svg" height="50px" width="50px"><circle cx="25px" cy="25px" r="20" fill="red" stroke-opacity="0.5" />' +
'<text x="24" y="32" font-size="14pt" font-family="arial" font-weight="bold" text-anchor="middle" fill="white">{text}</text>' +
'</svg>';
var clusteringProvider = new mapsjs.clustering.Provider(dataPoints, {
    min: 1,
    max: 15,
    clusteringOptions: {
        minWeight: 1,
        eps: 32
    },
    theme: {
        getClusterPresentation: function (markerCluster) {

            // Use cluster weight to change icon size:
            var svgString = clusterSvgTemplate.replace('{radius}', markerCluster.getWeight() * 5);
            svgString = svgString.replace('{text}', + markerCluster.getWeight());

            var w, h;
            var weight = markerCluster.getWeight();

            //Set cluster size depending on the weight
            if (weight <= 6)
            {
                w = 35;
                h = 35;
            }
            else if (weight <= 12) {
                w = 50;
                h = 50;
            }
            else {
                w = 75;
                h = 75;
            }

            var clusterIcon = new H.map.Icon(svgString, {
                size: { w: w, h: h },
                anchor: { x: (w/2), y: (h/2) }
            });

            // Create a marker for clusters:
            var clusterMarker = new H.map.Marker(markerCluster.getPosition(), {
                icon: clusterIcon,
                // Set min/max zoom with values from the cluster, otherwise
                // clusters will be shown at all zoom levels:
                min: markerCluster.getMinZoom(),
                max: markerCluster.getMaxZoom()
            });

            // Bind cluster data to the marker:
            clusterMarker.setData(markerCluster);

            clusterMarker.addEventListener("pointerenter", function (event) {

                var point = event.target.getPosition(),
                    screenPosition = map.geoToScreen(point),
                    t = event.target,
                    data = t.getData(),
                    tooltipContent = ""; 
                data.forEachEntry(
                    function(p) 
                    { 
                        tooltipContent += p.getPosition().lat + " " + p.getPosition().lng + "</br>";
                    }
                ); 
                infoBubble = new H.ui.InfoBubble(map.screenToGeo(screenPosition.x, screenPosition.y), { content: tooltipContent });
                ui.addBubble(infoBubble);
            });

            clusterMarker.addEventListener("pointerleave", function (event) { 
                if(infoBubble)
                {
                    ui.removeBubble(infoBubble);
                    infoBubble = null;
                }
            });             

            return clusterMarker;
        },
        getNoisePresentation: function (noisePoint) {

            // Create a marker for noise points:
            var noiseMarker = new H.map.Marker(noisePoint.getPosition(), {
                icon: noiseIcon,

                // Use min zoom from a noise point to show it correctly at certain
                // zoom levels:
                min: noisePoint.getMinZoom(),
                max: 20
            });

            // Bind cluster data to the marker:
            noiseMarker.setData(noisePoint);

            noiseMarker.addEventListener("pointerenter", function (event) { 

                var point = event.target.getPosition();
                var tooltipContent = ["Latitude: ", point.lat, ", Longitude: ", point.lng].join("");

                var screenPosition = map.geoToScreen(point);

                infoBubble = new H.ui.InfoBubble(map.screenToGeo(screenPosition.x, screenPosition.y), { content: tooltipContent });
                ui.addBubble(infoBubble);

            });
            noiseMarker.addEventListener("pointerleave", function (event) { 
                if(infoBubble)
                {
                    ui.removeBubble(infoBubble);
                    infoBubble = null;
                }
            });


            return noiseMarker;
        }
    }

});

它显示了以下错误:

UPDATE employee SET SSN=’666884444’  WHERE SSN = ‘123456789’; 
UPDATE employee SET SSN=’123456789’ WHERE SSN = ‘666884444’;  

有人可以指导我进行查询吗?

1 个答案:

答案 0 :(得分:0)

https://www.sqlite.org/foreignkeys.html

  1. 将FK约束更改为 DEFERRED 。语法为DEFERRABLE INITIALLY DEFERRED
  2. BEGIN/COMMIT交易块中进行更新。