MS-SQL에서 저장 프로 시저를 MySQL로 변환 중입니다. Directed Acyclic Graph를 기반으로하지만 구문 오류가 발생합니다. http://www.codeproject.com/Articles/22824/A-Model-to-Represent-Directed-Acyclic-Graphs-DAG-oMS-SQL에서 MySQL로 변환 된 저장 프로 시저를 사용하는 IF 문에 구문 오류가 발생했습니다.
내가 오류는 다음과 같습니다 :
원래 MS-SQL 스크립트는 다음 페이지에 목록 2에 # 1064 - 당신은 당신의 SQL 구문에 오류가 있습니다; 올바른 구문이 'DECLARE varId int'근처에서 사용되도록 MySQL 서버 버전에 해당하는 설명서를 확인하십시오. 줄에서 '엉 가장자리 (startVertex, 삽입 반 (36)
MySQL의 코드 :
DELIMITER //
CREATE PROCEDURE AddEdge(
IN iStartVertexId varchar(36),
IN iEndVertexId varchar(36),
IN iSource varchar(150)
)
MAIN_BLOCK: BEGIN
DECLARE counter int default 0;
SET counter = (SELECT id
FROM edges
WHERE startVertex = iStartVertexId
AND endVertex = iEndVertexId
AND hops = 0);
IF counter > 0 THEN
BEGIN
LEAVE MAIN_BLOCK;
END;
END IF;
SET counter = 0;
SET counter = (SELECT Id
FROM edges
WHERE StartVertex = @EndVertexId
AND EndVertex = @StartVertexId);
IF iStartVertexId = iEndVertexId
OR counter > 0
THEN
BEGIN
LEAVE MAIN_BLOCK;
END;
END IF;
DECLARE varId int;
INSERT INTO edges (
startVertex,
endVertex,
hops,
source)
VALUES (
iStartVertexId,
iEndVertexId,
0,
iSource);
SELECT varId = LAST_INSERT_ID();
UPDATE edges
SET entryEdgeId = varId
, exitEdgeId = varId
, directEdgeId = varId
WHERE id = varId;
-- step 1: A's incoming edges to B
INSERT INTO edges (
entryEdgeId,
directEdgeId,
exitEdgeId,
startVertex,
endVertex,
hops,
source)
SELECT id
, varId
, varId
, startVertex
, iEndVertexId
, hops + 1
, iSource
FROM edges
WHERE endVertex = iStartVertexId;
-- step 2: A to B's outgoing edges
INSERT INTO edges (
entryEdgeId,
directEdgeId,
exitEdgeId,
startVertex,
endVertex,
hops,
source)
SELECT varId
, varId
, id
, iStartVertexId
, endVertex
, hops + 1
, iSource
FROM edges
WHERE startVertex = iEndVertexId;
-- step 3: A’s incoming edges to end vertex of B's outgoing edges
INSERT INTO edges (
entryEdgeId,
directEdgeId,
exitEdgeId,
startVertex,
endVertex,
hops,
source)
SELECT A.id
, varId
, B.id
, A.startVertex
, B.endVertex
, A.hops + B.hops + 1
, iSource
FROM edges A
CROSS JOIN edges B
WHERE A.endVertex = iStartVertexId
AND B.startVertex = iEndVertexId;
END //
DELIMITER ;
이 어떤 아이디어를 내 구문이 조금 잘못된 생각 때문에 IF 문없이 잘 작동
SP가 아닌 트리거를 사용하는 것이 좋습니다. 올바르게 정의 된 경우 기본 테이블을 직접 변경하고 MySQL이 자동으로 DAG를 유지 관리 할 수 있습니다. – eggyal