关于Oracle 8i上的事务处理(急!!!)(200分)(200分)

  • 主题发起人 主题发起人 jqw
  • 开始时间 开始时间
J

jqw

Unregistered / Unconfirmed
GUEST, unregistred user!
Delphi 4.0(Pack #3)+BDE 5.1.1+Oracle 8i;

有一个简单的程序:
database,table,datasource,dbgrid,dbnavigator各一个(见源程序)

在table.beforeEdit中
with database1 do
if not intransaction then
starttransaction;

当修改一条记录后,post,出现"capability not supported.",
难道oracle 8i不支持事务中的修改(好象删除也不支持),可是
在oracle 7.x中是完全支持的。

望各位高手帮忙,如解决的好,还会加分!


附:
(1). unit1.dfm
object Form1: TForm1
Left = 176
Top = 96
Width = 870
Height = 600
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 120
TextHeight = 16
object DBNavigator1: TDBNavigator
Left = 80
Top = 448
Width = 470
Height = 41
DataSource = DataSource1
TabOrder = 0
end
object DBGrid1: TDBGrid
Left = 32
Top = 56
Width = 793
Height = 369
DataSource = DataSource1
TabOrder = 1
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -13
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object Button1: TButton
Left = 584
Top = 456
Width = 105
Height = 33
Caption = 'Commit'
TabOrder = 2
OnClick = Button1Click
end
object Button2: TButton
Left = 728
Top = 456
Width = 81
Height = 33
Caption = 'Rollback'
TabOrder = 3
OnClick = Button2Click
end
object Database1: TDatabase
AliasName = 'plat_db'
Connected = True
DatabaseName = '1234'
LoginPrompt = False
Params.Strings = (
'USER NAME=platzhk'
'password=platzhk')
SessionName = 'Default'
Left = 64
Top = 8
end
object Table1: TTable
Active = True
BeforeEdit = Table1BeforeEdit
DatabaseName = '1234'
IndexFieldNames = 'A1'
TableName = 'TEST'
Left = 104
Top = 8
end
object DataSource1: TDataSource
DataSet = Table1
Left = 144
Top = 8
end
end

(2).unit1.pas
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids, DBGrids, ExtCtrls, DBCtrls, Db, DBTables;

type
TForm1 = class(TForm)
Database1: TDatabase;
Table1: TTable;
DataSource1: TDataSource;
DBNavigator1: TDBNavigator;
DBGrid1: TDBGrid;
Button1: TButton;
Button2: TButton;
procedure Table1BeforeEdit(DataSet: TDataSet);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
procedure ComStartTransaction;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ComStartTransaction;
begin
with Database1 do
if not inTransaction then
StartTransaction;
end;

procedure TForm1.Table1BeforeEdit(DataSet: TDataSet);
begin
ComStartTransaction;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
with Database1 do
if not InTransaction then
Windows.MessageBox(0,PChar('没有事务可提交!'),'提示信息',MB_OK)
else if Windows.MessageBox(0,PChar('真的要保存吗?'),'确认信息',MB_YESNO)=IDYES then
begin
try
Commit;
except
Rollback;
end;
ComStartTransaction;
end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
with Database1 do
if not InTransaction then
Windows.MessageBox(0,PChar('没有事务可放弃!'),'提示信息',MB_OK)
else if Windows.MessageBox(0,PChar('真的要修改吗?'),'确认信息',MB_YESNO)=IDYES then
begin

RollBack;
ComStartTransaction;
end;


end;

end.


 
兄弟们:
快来帮忙!!
 
能否用单步跟踪。
 
用单步跟踪是不行的。
 
兄弟们:
快来帮忙!!
 
if not InTransaction then
Windows.MessageBox(0,PChar('没有事务可提交!'),'提示信息',MB_OK)
else if Windows.MessageBox(0,PChar('真的要保存吗?'),'确认信息',MB_YESNO)=IDYES then
begin
......
Rollback;
end;
ComStartTransaction; // 与 beforepost 重复
end;
// 同时检查BDE设置中是否为 SHARED AUTOCOMMIT == 自动提交
 
谢谢各位:

to jasonfu:
代码好像没有问题,
BDE设置中是否为 SHARED AUTOCOMMIT or SHARED NOAUTOCOMMIT 对问题没有影响.

兄弟们可以将上面的源代码粘贴到DELPHI环境试试,好吗?
 
兄弟们:
快来帮忙!!
 
兄弟们:
快来帮忙!!

 
版主:
我如何删除该问题!
 
好了吗?如果没有,我建议你不要用post方法,用Tquery非常好做,你会知道的,不是吗?
 
to goldstone:
you may try it??
 
多人接受答案了。
 
其实你只要将用Tquery+updatesql就可以了,记住关键字段不要选错就可以了,我试过了,可以的
因为以前有人向我提过这个问题,记的给我分数啊
 
jqw:
你好,最后你是怎么解决的呢?能告诉我吗?谢谢!
 
to longwx:
use view
 

Similar threads

I
回复
0
查看
673
import
I
I
回复
0
查看
686
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
709
import
I
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部