I am currently creating an application but when running the following code:
ADOQRanking.Edit;
ADOQRanking['Bye']:=True;
ADOQRanking['TableAssigned']:=True;
ADOQRanking.Post;
... a new record with null values is created in ADOTPoints (the table that ADOQRanking sorts), with Bye and TableAssigned both set to true, rather than the intended record being edited. It should also be noted that there is no code in the entire procedure that creates a record in ADOTPoints.
try to use fields by it's names
ADOQRanking.FieldByName('Byte').Value := true ;
and so on ..
Related
Need help on getting query on a text file using stored procedure in db2. I'm very new to this so please help.
Till now i am able to create a file and get get data in created file. But i want a complete query in the file not a single column data.
I have created a Stored Procedure like this
CREATE or replace PROCEDURE SCOPEMASTERP(my_statement varchar(10000))
AUTONOMOUS
BEGIN
DECLARE v_filehandle UTL_FILE.FILE_TYPE;
DECLARE v_dirAlias VARCHAR(50) DEFAULT 'mydir';
DECLARE v_filename VARCHAR(100) DEFAULT 'bluestar_transaction-';
DECLARE v_format VARCHAR(200);
SET v_format = '%s\n';
set v_filename = concat(v_filename, VARCHAR_FORMAT(current_date, 'DD-MM-YYYY'));
set v_filename = concat(v_filename, '.log');
CALL UTL_DIR.CREATE_OR_REPLACE_DIRECTORY('D:', '/archivelog/asd/');
SET v_filehandle = UTL_FILE.FOPEN(v_dirAlias,v_filename,'a');
CALL UTL_FILE.PUTF(v_filehandle,v_format, my_statement);
CALL DBMS_OUTPUT.PUT_LINE('Wrote to file: ' || v_filename);
CALL UTL_FILE.FCLOSE(v_filehandle);
END
and i have created a trigger inside trigger i am calling stored procedure
CREATE OR REPLACE TRIGGER SCOPEMASTER_Trigger
AFTER INSERT ON SERVEIT.SCOPENAMEMASTER
REFERENCING NEW AS N
FOR EACH ROW
BEGIN ATOMIC
call SCOPEMASTERP(N.SCOPENAMEID);
END
insert statement i am executing
Insert into SERVEIT.SCOPENAMEMASTER (SCOPENAMEID) values (1013)
GO
And file which is creating in "D" drive i am getting
But instead of just getting 1013 i need the complete query in the file
Insert into SERVEIT.SCOPENAMEMASTER (SCOPENAMEID) values (1013)
What changes i need to do please help. Thanks in advance!!
There are no special registers/variables/etc. available in DB2 that provide the SQL statement that is being executed, so what you're asking for is not possible.
I have an existing table that resides in one database, and each night I want to completely overwrite all contents of this existing table (TO_TABLE), with all data from another database/table (FROM_TABLE).
Currently I am manually dropping the TO_TABLE and re-writing it using this:
INTO SDE_SPATIAL.GISADMIN.TO_TABLE
FROM GAVIN..AUTH.FROM_TABLE
This works fine, but I would eventually like to convert this into a stored procedure and get this to happen automatically every 24hrs.
Does anyone know how to do the above a bit better and ready for a stored procedure??
UPDATE:
This is the code as it currently stands. I was getting these two errors occur when I run it, the first was"Incorrect Syntax near 'ON'" and the other was "Incorrect Syntax near 'END'".
I removed the ; characters and run again, this time I was getting no errors, and the procedure was being created successfully.
CREATE
PROCEDURE [_ACC_OVERWRITE_PROPERTY_DETAILS]
AS
BEGIN
SET NOCOUNT ON
TRUNCATE TABLE
SDE_SPATIAL.GISADMIN._ACC_TEMP
INSERT
INTO
SDE_SPATIAL.GISADMIN._ACC_TEMP
(
Parcel ,
Assessment ,
House ,
Street ,
St_Type ,
Title ,
Area ,
Area_Units ,
Suburb
)
SELECT
parc.pcl_num ,
parc.ass_num ,
STAD.HOU_NUM ,
stad.str_nme ,
stad.str_typ ,
parc.fmt_ttl ,
aps.property_area ,
LOWER(aps.AREA_INDICATOR) + '²',
stad.sbr_nme
FROM
GAVIN..AUTH.AUPRSTAD stad,
GAVIN..AUTH.AUSRMAST mast,
GAVIN..AUTH.AV_PROPERTY_SUMMARY aps,
GAVIN..AUTH.AUPRPARC parc
WHERE
PARC.PCL_NUM=STAD.PCL_NUM
AND STAD.STR_NUM=MAST.STR_NUM
AND (
PARC.PCL_FLG='R'
OR PARC.PCL_FLG='P')
AND PARC.PCL_NUM=aps.PARCEL_NUMBER
AND stad.SEQ_NUM = 0
END
This is how I would do it with a SQL Server stored procedure (sorry, but I don't think you named your particular SQL dialect):
CREATE PROCEDURE [ResetSpatialData]
AS
BEGIN
SET NOCOUNT ON;
TRUNCATE TABLE SDE_SPATIAL.GISADMIN.TO_TABLE;
INSERT INTO SDE_SPATIAL.GISADMIN.TO_TABLE
([field1], [field2], [field3], [etc], [you get the idea])
SELECT [field1], [field2], [field3], [etc], [you get the idea]
FROM GAVIN..AUTH.FROM_TABLE;
END
You could then schedule this for regular execution on some time basis by using a SQL Server Agent job.
Note: corrected as per #Nick McDermaid's suggestion.
So, I Googled the following, but cannot seem to find an answer.
I've got a few Access tables that I am trying to update from Delphi.
The one table updates perfectly, so I know my database connection is active (the connection is set when the main form loads).
The problem is the second table. I keep on getting the error: "Dataset not in edit or insert mode".
In the formshow procedure I've got the following code:
//Connect to the individuals details table
dmoDonations.tblInd.Connection:= dmoDonations.adoDonations;
dmoDonations.tblInd.ReadOnly:= False; //Enable read / write
dmoDonations.tblInd.Active:= False;
dmoDonations.tblInd.TableName:='Individuals';
dmoDonations.tblInd.Active:= True;
dmoDonations.tblInd.Append; //Insert new record
dmoDonations.cdsInd.Open;
dmoDonations.cdsInd.Active:= True;
dmoDonations.cdsInd.ReadOnly:= False;
dmoDonations.cdsInd.Refresh;
And the rest of the code to update the table is under the updateButtonClick procedure:
dmoDonations.tblInd.Insert; //Insert new record
dmoDonations.tblInd['Name']:= edtName.Text;
dmoDonations.tblInd['Address1']:= edtAddress1.Text;
dmoDonations.tblInd['Address2']:= edtAddress2.Text;
dmoDonations.tblInd['Address3']:= edtAddress3.Text;
dmoDonations.tblInd['Phone']:= edtPhone.Text;
dmoDonations.tblInd['Email']:= edtEmail.Text;
dmoDonations.tblInd.Post; //Saves new records
It's at the last line where the error pops up when I step through the code. Why would this error occur even though the table is open and active and I've inserted / appended the table (have tried both options in both sections of code)?
I have a very big Stored Procedure in iSeries DB2 v8 which does the following:
Calls other stored procedures inside the same schema
Prepares dynamic sql statments from strings and runs them
Calls other functions from the same schema
Uses various tables from the same schema
My problem is that this Stored Procedure and the accompanying functions may change from that schema into another (ie. from 'superlib' to 'restorelib') and the whole code is currently hardcoded to run with the named schema.
What I want is to be able to do one of the two: either pass the name of the schema where everything is located via a parameter to the stored procedure, or have the stored procedure detect the name of the schema and use it to run itself.
This is a sample of my current code:
SELECT COUNT(*) INTO TotalNotDone FROM superlib.PROCESSTABLES WHERE PROCESS_FLAG < 1;
WHILE TotalNotDone > 0 DO
SET SQLLOOPSTMT = 'select name_to_proces from ' CONCAT SOURCELIBRARY CONCAT '.processtables where process_flag = 0' ;
PREPARE LOOPSTMT FROM SQLLOOPSTMT ;
OPEN LOOPCUR ;
FETCH LOOPCUR INTO TABLETOPROCESS ;
CALL superlib.SP_RESTORE_INSERTS ( SOURCELIBRARY , DESTLIBRARY , TABLETOPROCESS, P_STARTTIME ) ;
CLOSE LOOPCUR;
SELECT COUNT(*) INTO TotalNotDone FROM superlib.PROCESSTABLES WHERE PROCESS_FLAG < 1;
END WHILE ;
What I want is for NOT to have to write superlib inside the stored procedure to call or reference the tables i'm using and just have the Stored Procedure recognize it currently IS living in the schema superlib.
I've tried SET CURRENT SCHEMA = 'SUPERLIB'; and SET SCHEMA = 'SUPERLIB'; but neither works when calling the TABLES.
I've also changed the path when creating the Stored Procedure from:
SET PATH "QSYS","QSYS2","SYSPROC","SYSIBMADM","PROGUSER1" ;
to
SET PATH "QSYS","QSYS2","SYSPROC","SYSIBMADM","SUPERLIB" ;
but that apparently does nothing.
i believe you'll need to set the current path on the connection that calls the stored proc, not just when creating it.
see this: Weblogic: Call DB2 stored procedure without schema name (property currentSchema)
current path documentation here: http://publib.boulder.ibm.com/infocenter/db2luw/v8//topic/com.ibm.db2.udb.doc/admin/r0005877.htm
I am trying to create a BEFORE INSERT trigger that will check the incoming value of a field, and replace it with the same field in another row if that the field is null. However, when I add the CALL statement to my trigger, an error is returned "The trigger "ORGSTRUCT.CSTCNTR_IN" is defined with an unsupported triggered SQL statement". I checked the documentation and saw that cursors weren't supported in the BEFORE (part of the reason for making the stored procedure in the first place), but even when I remove the cursor declaration from the stored procedure the call still generates the same error.
Trigger:
CREATE TRIGGER orgstruct.cstcntr_IN
NO CASCADE
BEFORE INSERT ON orgstruct.tOrgs
REFERENCING NEW AS r
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
DECLARE prnt_temp BIGINT;
DECLARE cstcntr_temp CHAR(11);
SET prnt_temp = r.prnt;
SET cstcntr_temp = r.cstcntr;
CALL orgstruct.trspGetPrntCstCntr(prnt_temp,cstcntr_temp);
SET r.cstcntr = cstcntr_temp;
END
Stored procedure:
CREATE PROCEDURE orgstruct.trspGetPrntCstCntr (
IN p_prnt BIGINT,
OUT p_cstcntr CHAR(11)
)
SPECIFIC trGetPrntCstCntr
BEGIN
IF p_prnt IS NULL THEN
RETURN;
END IF;
BEGIN
DECLARE c1 CURSOR
FOR
SELECT cstcntr
FROM orgstruct.tOrgs
WHERE id = p_prnt
FOR READ ONLY;
OPEN c1;
FETCH FROM c1 INTO p_cstcntr;
CLOSE c1;
END;
END
According to the documentation, CALL is allowed in a BEFORE trigger, so I don't understand what the problem is.
A before trigger can call a stored procedure, but the stored proc can't do anything not allowed in the trigger.
In your case, the default level of data access for a SQL stored proc is MODIFIES SQL DATA, which is not allowed in the trigger. You could recreate your stored procedure, changing the data access level to READS SQL DATA; this will allow you to create the trigger.
However: There is no reason to call a stored procedure for something this simple; You can do it using a simple inline trigger:
create trigger orgstruct.cstcntr_IN
no cascade
before insert on orgstruct.tOrgs
referencing new as r
for each row
mode db2sql
set r.cstcntr = case
when r.p_prnt is not null
then (select cstcntr from tOrgs where id = r.p_prnt fetch first 1 row only)
else r.cstcntr
end;
This will be a LOT more efficient because it eliminates both the stored procedure call and the cursor processing inside the stored proc. Even if you wanted to use the stored proc, you could eliminate the cursor inside the stored proc and improve performance.
FYI: the logic that you posted contains an error, and will always set CSTCNTR to NULL. The trigger posted in this answer not do this. :-)