Subject | Re: trigger primary key problem during record copy |
---|---|
Author | intellekta |
Post date | 2006-01-30T21:10:11Z |
Helen, thanks for the information.
i create the following SP that will do the work:
-- Debug: Returns TMPSQL --
-- ToDo : Check Input Values --
CREATE PROCEDURE RECORDCOPY (
TABLENAME VARCHAR(50),
IDNAME VARCHAR(50),
IDVALUE INTEGER)
RETURNS (
TMPSQL VARCHAR(4096))
AS
DECLARE VARIABLE FIELDNAME VARCHAR(50) CHARACTER SET NONE;
BEGIN
TMPSQL = '';
FOR
SELECT F.RDB$FIELD_NAME
FROM RDB$RELATION_FIELDS F
WHERE F.RDB$RELATION_NAME = :TABLENAME
AND F.RDB$FIELD_NAME <> :IDNAME
INTO :FIELDNAME DO BEGIN
IF (TMPSQL = '') THEN
TMPSQL = RTRIM(FIELDNAME);
ELSE
TMPSQL = TMPSQL || ',' || RTRIM(FIELDNAME);
END
IF (TMPSQL <> '') THEN BEGIN
TMPSQL = 'INSERT INTO ' || TABLENAME || ' (' || TMPSQL || ')
SELECT ' || TMPSQL || ' FROM ' || TABLENAME || ' WHERE ' || IDNAME ||
'=' || IDVALUE;
EXECUTE STATEMENT TMPSQL;
END
SUSPEND;
END
i create the following SP that will do the work:
-- Debug: Returns TMPSQL --
-- ToDo : Check Input Values --
CREATE PROCEDURE RECORDCOPY (
TABLENAME VARCHAR(50),
IDNAME VARCHAR(50),
IDVALUE INTEGER)
RETURNS (
TMPSQL VARCHAR(4096))
AS
DECLARE VARIABLE FIELDNAME VARCHAR(50) CHARACTER SET NONE;
BEGIN
TMPSQL = '';
FOR
SELECT F.RDB$FIELD_NAME
FROM RDB$RELATION_FIELDS F
WHERE F.RDB$RELATION_NAME = :TABLENAME
AND F.RDB$FIELD_NAME <> :IDNAME
INTO :FIELDNAME DO BEGIN
IF (TMPSQL = '') THEN
TMPSQL = RTRIM(FIELDNAME);
ELSE
TMPSQL = TMPSQL || ',' || RTRIM(FIELDNAME);
END
IF (TMPSQL <> '') THEN BEGIN
TMPSQL = 'INSERT INTO ' || TABLENAME || ' (' || TMPSQL || ')
SELECT ' || TMPSQL || ' FROM ' || TABLENAME || ' WHERE ' || IDNAME ||
'=' || IDVALUE;
EXECUTE STATEMENT TMPSQL;
END
SUSPEND;
END