I have been using Lazarus 2.x with Firebird 3 (via flamerobin) and i try to commit records via TSQLConnection, TSQLQuery, TDataSource in a data module.
I run the following script successfully in order to configure initially DBLookupCombobox, where the records are displayed without any problem.
procedure TForm3.FormCreate(Sender: TObject);
begin
appeals.SQLQuery4.Close;
appeals.SQLQuery4.SQL.Text:='select id,fullname from promoter';
appeals.SQLQuery4.Open;
appeals.DataSource2.DataSet:=appeals.SQLQuery4;
DBLookupComboBox1.ListSource:=appeals.DataSource2;
DBLookupComboBox1.ScrollListDataset:=True;
DBLookupComboBox1.Style:=csDropDownList;
DBLookupComboBox1.KeyField:='id';
DBLookupComboBox1.DataField:='id';
DBLookupComboBox1.ListField:='fullname';
end;
Afterwards i use the following snippet for record submission:
procedure TForm3.Button1Click(Sender: TObject);
begin
appeals.SQLTransaction1.Active:=false;
appeals.SQLQuery1.SQL.Text:='UPDATE appeals set name=:name,date_entry=:entry,date_suspended=:suspended,'+
'date_court=:court,date_judgement=:judgement,promoter_id=:code where id='+IntToStr(row_num);
appeals.SQLQuery1.Params.ParamByName('name').AsString:=Trim(Edit1.Text);
appeals.SQLQuery1.Params.ParamByName('entry').AsDate:=DateTimePicker1.Date;
appeals.SQLQuery1.Params.ParamByName('suspended').AsDate:=IncDay(DateTimePicker1.Date,10);
appeals.SQLQuery1.Params.ParamByName('court').AsDate:=DateTimePicker2.Date;
appeals.SQLQuery1.Params.ParamByName('judgement').AsDate:=IncDay(DateTimePicker2.Date,20);
appeals.SQLQuery1.Params.ParamByName('code').AsInteger:=DBLookupComboBox1.KeyValue;
appeals.SQLTransaction1.StartTransaction;
appeals.SQLQuery1.ExecSQL;
appeals.SQLTransaction1.Commit;
Application.MessageBox('Record submission with success !', 'Information', MB_ICONINFORMATION);
end;
I have also attached the following script in Form Create event without any luck from wiki article.
If (DBLookupComboBox1.KeyValue = Null) And (appeals.SQLQuery4.RecordCount > 0) Then
DBLookupComboBox1.KeyValue := appeals.SQLQuery4.FieldByName('id').AsVariant;
Any idea would help me a lot regarding DBLookupComboBox1.KeyValue where the following error appears!
I would like to update the fields of a table via DBLookupCombobox (foreign key) that loads data from another table, two datetimepickers and edit control.
Regards
I just found that before appeals.SQLTransaction1.Active:=false, i have to store DBLookupComboBox1.KeyValue into a local variable as database connection afterwards is lost and thus there is not any value to DBLookupComboBox1.KeyValue but NULL.
Therefore i have to use that local variable into my SQL query to update the appropriate record.
I should be more careful next time!
Related
I use a pl/sql code in a dynamic action (which is launched when I press a button).
I do an update table. after the update, I want to notify to the user if the update succeed or not.
I use the code :
if ( ) then
update ....
apex_application.g_print_success_message := '<span style="color:green">OK</span>';
end if;
but the code does not work. it does the update, but I do not see the notification.
thank for your help.
Hervé
Here's how I do that:
create a stored procedure which accepts certain parameters, do stuff and puts success (or failure) message into the OUT parameter. For example,
create or replace procedure p_upd (par_empno in number, par_msg out varchar2) as
begin
update ...
where empno = par_empno;
par_msg := 'Updated ' || sql%rowcount || ' rows';
end;
In Apex, create a hidden item (let's call it P1_MSG)
create a button which - when pushed - calls a process which utilizes previously mentioned stored procedure:
p_upd (:P1_EMPNO, :P1_MSG);
finally, set this as a Success process message:
&P1_MSG.
(note leading ampersand (&) and trailing dot (.) - without them, it won't work. The final result will be "Updated 17 rows" message displayed on the screen (just as you see the default "Action processed" message).
That's all.
Of course, instead of calling a procedure, you can write some PL/SQL code directly into the process, but I prefer a procedure, especially when there's a lot of things to be done (I rather do that in the database).
my suggestion is write your plsql code in process by selecting type as plsql code. from there you can set your success message as well. I also tried earlier with apex_application.g_print_success_message but it was not work for me. So I changed by process flow.
I am doing data insert into a table in Oracle which is having a sequence set to it in one of the columns say Id column. I would like to know how to do data loads into such tables.
I followed the below link -
It's possible to use OleDbConnections with the Script Component?
and tried to create a function to get the .nextval from the Oracle table but I am getting the following error -
Error while trying to retrieve text for error ORA-01019
I realized that manually setting the value via the package i.e. by using the Script task to enumerate the values but is not incrementing the sequence and that is causing the problem. How do we deal with it? Any links that can help me solve it?
I am using SSIS-2014 but I am not able to tag it as I don't due to paucity of reputation points.
I created a workaround to cater to this problem. I have created staging tables of the destination without the column that takes the Sequence Id. After the data gets inserted, I am then calling SQL statement to get the data into the main tables from staging table and using the .nextval function. Finally truncating/dropping the table depending on the need. It would still be interesting to know how this same thing can be handled via script rather having this workaround.
For instance something like below -
insert into table_main
select table_main_sequence_name.nextval
,*
from (
select *
from table_stg
)
ORA-01019 may be related to fact you have multiple Oracle clients installed. Please check ORACLE_HOME variable if it contains only one client.
One workaround I'm thinking about is creating two procedures for handling sequence. One to get value you start with:
create or replace function get_first from seq as return number
seqid number;
begin
select seq_name.nexval into seqid from dual;
return seqid;
end;
/
Then do your incrementation in script. And after that call second procedure to increment sequence:
create or replace procedure setseq(val number) as
begin
execute immediate 'ALTER SEQUENCE seq_name INCREMENT BY ' || val;
end;
/
This is not good approach but maybe it will solve your problem
I have an error: 'ORA-04092: cannot COMMIT in a trigger' when trying to execute ddl command in one simple oracle after update trigger. Trigger needs to create public database link after one field in column is updated. Here is the source:
create or replace
TRIGGER CreateLinkTrigger
after UPDATE of Year ON tableInit
for each row
DECLARE
add_link VARCHAR2(200);
BEGIN
IF :new.year = '2014'
then
add_link := q'{create public database link p2014 connect to test14 identified by temp using 'ora'}';
execute immediate add_link;
END IF;
END;
So, as You can see i need to create new public database link after new year has been activated.
So when i try to update table 'tableInit' with year value of '2014' i get ORA-04092 error.
Is there any way to avoid this error, or another solution for this?
Thanks...
Creating a database link on the fly seems like an unusual thing to do; your schema should generally be static and stable. However, if you must, it would be simpler to wrap the update and the link in a procedure, or just issue two statements - presumably whatever performs the update is fairly controlled anyway, otherwise you'd have to deal with multiple people triggering this multiple times, which would be even more of a mess.
You can probably make this work by adding PRAGMA autonomous_transaction; to your trigger, as demonstrated for a similar issue (creating a view rather than a link) in this answer, but I'm not in a position to test that at the moment.
create or replace
TRIGGER CreateLinkTrigger
after UPDATE of Year ON tableInit
for each row
DECLARE
add_link VARCHAR2(200);
PRAGMA autonomous_transaction;
BEGIN
...
You could also make the trigger submit an asynchronous job to perform the DDL, as described in this answer, and there's more of an example in this answer, where you'd change the job's anonymous block to do your execute immediate.
It would probably be better to just create the links for the next few years in advance during a maintenance window, or on a schedule, or from a procedure; rather than trying to associate a schema change to a data change.
I googled this but, unfortunately, could not find any solution.
I have a simple form (Oracle Forms Builder 10g) with a single block. The form is written in Oracle EBS style, that is, the block is based on a view that fetches the base table fields together with the rowid and DML events (on-insert, on-update etc. triggers) are handled by a table handler package.
The functionality I wanted to add was the following: when a user creates a new record, the form automatically suggests values for all fields in the form. So, I created a WHEN-CREATE-RECORD trigger that calculates the field values and assigns them. All, except the primary key wich is based on a Sequence and is handled by the package.
Everything runs OK when I create the new record but when I attempt to save it, all I get is a FRM-40401 "no changes to save" error and nothing happens.
I tried to trace the error and it seems like the form considers the record as NEW with no changes on it. This happens even if I try to explicitly alter the record status to INSERT.
I already tried to change the default behaviour to STANDARD.COMMIT (created an ON-COMMIT trigger for that) but this did not dfix anything.
For the record, I tried to make the form table-based, getting rid of table handlers and leaving all DML to Forms. I still get FRM-40401.
I can't understand what is going wrong, any ideas please?
The record status is reset to NEW after the when-create-record trigger completes. This normally makes sense, since you are effectively setting the default values for items, but the user hasn't actually entered any data yet.
You need something to mark the record for insert after the trigger has finished - normally the user would do this when they enter some data into the record. If you want the user to be able to save the record without changing anything in it, you could perhaps add something to the save button to do a no-change assignment, e.g.
:MYBLOCK.ANYITEM := :MYBLOCK.ANYITEM;
This would cause the record to be marked for insert.
OK, for the time being I used the classic TIMER workaround and everything works as it should:
PACKAGE body form_timers IS
PROCEDURE CREATE_NEW_RECORD;
procedure do_create(name varchar2) is
timer_id TIMER;
Begin
timer_id := CREATE_TIMER(name,1,NO_REPEAT);
End;
procedure expired is
expired_timer CHAR(20);
BEGIN
expired_timer:=GET_APPLICATION_PROPERTY(TIMER_NAME);
IF expired_timer='CREATE_NEW_RECORD' THEN
CREATE_NEW_RECORD;
-- ELSIF expired_timer='T2' THEN
-- /* handle timer T2 */ NULL;
ELSE
NULL;
END IF;
END;
PROCEDURE CREATE_NEW_RECORD IS
/* create record logic goes here */
END;
END;
... but still, I'd like to know why this behaviour occurs.
I have a form that I'm looking at, which makes use of stored procedures as data block source. I'm trying to find when/where the block gets populated.
The block as query data source type as Procedure, but the procedure listed as the data source name does nothing - literally nothing. The code in the procedure is
begin
null;
end;
Going through the list of procedures in the package responsible for handling the form, I found a procedure which does populates the data.
Searching for this procedure, I found that this procedure is invoked during ON-SELECT trigger.
So - does ON-SELECT trigger get fired during/after QUERY-PROCEDURE event? If not when does it get fired?
I'm using Oracle Forms10.1.2.3.0, 32-bit on Windows Vista.
From the Forms on-line help for ON_SELECT:
Fires when Oracle Forms would normally
execute the open cursor, parse, and
execute phases of a query, to identify
the records in the database that match
the current query criteria.
Use an On-Select trigger to open and
execute the database cursor.
Specifically, use this trigger when
you are retrieving data from a
non-ORACLE data source. The On-Select
trigger can be used in conjunction
with the On-Fetch trigger to replace
the processing that normally occurs in
the EXECUTE_QUERY built-in subprogram.