📄 sqlserver实例-2.htm
字号:
CURSORSETPROP("Buffering", 5, "VCustomers")<BR>
REPLACE Phone with '9999' next 4<BR>
*将第1、2、3、4、条记录的Phone改为9999<BR>
BROWSE</font></P>
<P><font color="#FFFFFF">*使用 SQL Server 的Query Analyzer 制造更新冲突<BR>
*启动 SQL Server Query Analyzer,登录Northwind 数据库<BR>
*输入如下语句并执行:<BR>
update customers set phone='00000' whe</font><font color="#000000">re customerid='ANATR'
or customerid='ANTON'</font></P>
<P><font color="#FFFFFF">情况一:TABLEUPDATE(1,.F.,'Vcustomers')</font></P>
<P><font color="#FFFFFF">*返回Visual FoxPro<BR>
?TABLEUPDATE(1,.F.,'Vcustomers')<BR>
*由于记录 2更新时发生冲突,函数返回.F.<BR>
?recno('Vcustomers')<BR>
*指针停在第2条记录上<BR>
?Aerror(err)<BR>
用Aerror函数取得Visual FoxPro错误信息存入err数组中<BR>
?err(1)<BR>
*错误号:1585<BR>
?err(2)<BR>
*错误信息:“更新冲突”</font></P>
<P><font color="#FFFFFF">*回到SQL Server Query Analyzer<BR>
*输入如下语句并执行:<BR>
select customerid,phone from customers<BR>
*您将看到:第一条记录Phone的值已经被Visual FoxPro的客户端修改了,值是:9999。而后三条记录没有发生变化。说明Visual FoxPro依次发送SQL描述到SQL
Server时,遇到更新错误就停止继续往下工作。<BR>
事实上,查看 SQL Server 的 Profiler 工具也证明了以上论述:<BR>
sp_executesql N'UPDATE dbo.Customers SET Phone=@P1 WHERE CustomerID=@P2 AND
Phone=@P3', N'@P1 nvarchar(24),@P2 varchar(50),@P3 nvarchar(24)', N'9999 ',
'ALFKI', N'bbbb '<BR>
sp_executesql N'UPDATE dbo.Customers SET Phone=@P1 WHERE CustomerID=@P2 AND
Phone=@P3', N'@P1 nvarchar(24),@P2 varchar(50),@P3 nvarchar(24)', N'9999 ',
'ANATR</font><font color="#000000">', N'1234 '//此处发生更新错误,Visual FoxPro停止往下工作</font></P>
<P><font color="#FFFFFF">情况二:TABLEUPDATE(1,.T.,'Vcustomers')</font></P>
<P><font color="#FFFFFF">*返回Visual FoxPro<BR>
?TABLEUPDATE(1,.T.,'Vcustomers')<BR>
*函数返回.T.<BR>
?recno('Vcustomers')<BR>
*指针停在第4条记录上</font></P>
<P><font color="#FFFFFF">*回到SQL Server Query Analyzer<BR>
*输入如下语句并执行:<BR>
select customerid,phone from customers<BR>
*您将看到:头四条记录Phone的值已经被Visual FoxPro的客户端修改了,值是:9999。按理说第2条记录被更新时会发生冲突,但由于Visual
FoxPro临时变更了更新冲突的检测方案为“关键字段”,这样原本应该能检测到的冲突被忽略了,Visual FoxPro客户端的新值强行覆盖其它客户端的修改。<BR>
事实上,查看 SQL Server 的 Profiler 工具也证明了以上论述:<BR>
sp_executesql N'UPDATE dbo.Customers SET Phone=@P1 WHERE CustomerID=@P2', N'@P1
nvarchar(24),@P2 varchar(50)', N'9999 ', 'ALFKI'<BR>
sp_executesql N'UPDATE dbo.Customers SET Phone=@P1 WHERE CustomerID=@P2', N'@P1
nvarchar(24),@P2 varchar(50)', N'9999 ', 'ANATR'<BR>
sp_executesql N'UPDATE dbo.Customers SET Phone=@P1 WHERE CustomerID=@P2', N'@P1
nvarchar(24),@P2 varchar(50)', N'9999 ', 'ANTON'<BR>
sp_executesql N'UPDATE dbo.Customers SET Phone=@P1 WHERE CustomerID=@P2', N'@P1
nvarchar(24),@P2 varchar(50)', N'9999 ', 'AROUT'</font></P>
<P><font color="#FFFFFF">情况三:TABLEUPDATE(2,.F.,'Vcustomers',Arry)</font></P>
<P><font color="#FFFFFF">*返回Visual FoxPro<BR>
?TABLEUPDATE(2,.F.,'Vcustomers',Arry)<BR>
*参数nRows设为2,即使记录 2、3发生更新冲突,Visual FoxPro仍然继续往下执行,但参数函数返回.F.<BR>
?recno('Vcustomers')<BR>
*指针停在第4条记录上<BR>
?Aerror(err)<BR>
用Aerror函数取得Visual FoxPro错误信息存入err数组中<BR>
?err(1)<BR>
*错误号:1585<BR>
?err(2)<BR>
*错误信息:“更新冲突”<BR>
?Arry[1]<BR>
*2<BR>
?Arry[2]<BR>
*3<BR>
*Arry返回发生更新错误的记录号</font></P>
<P><font color="#FFFFFF">*回到SQL Server Query Analyzer<BR>
*输入如下语句并执行:<BR>
select customerid,phone from customers<BR>
*您将看到:第一条、第四条记录Phone的值已经被Visual FoxPro的客户端修改了,值是:9999。而第二条、第三条记录没有发生变化。说明Visual
FoxPro依次发送SQL描述到SQL Server时,遇到更新冲突忽略之,继续往下工作。<BR>
事实上,查看 SQL Server 的 Profiler 工具也证明了以上论述:<BR>
sp_executesql N'UPDATE dbo.Customers SET Phone=@P1 WHERE CustomerID=@P2 AND
Phone=@P3', N'@P1 nvarchar(24),@P2 varchar(50),@P3 nvarchar(24)', N'9999 ',
'ALFKI', N'cccc '<BR>
sp_executesql N'UPDATE dbo.Customers SET Phone=@P1 WHERE CustomerID=@P2 AND
Phone=@P3', N'@P1 nvarchar(24),@P2 varchar(50),@P3 nvarchar(24)', N'9999 ',
'ANATR', N'cccc '//发生更新冲突,Visual FoxPro继续往下执行<BR>
sp_executesql N'UPDATE dbo.Customers SET Phone=@P1 WHERE CustomerID=@P2 AND
Phone=@P3', N'@P1 nvarchar(24),@P2 varchar(50),@P3 nvarchar(24)', N'9999 ',
'ANTON', N'cccc '//发生更新冲突,Visual FoxPro继续往下执行<BR>
sp_executesql N'UPDATE dbo.Customers SET Phone=@P1 WHERE CustomerID=@P2 AND
Phone=@P3', N'@P1 nvarchar(24),@P2 varchar(50),@P3 nvarchar(24)', N'9999 ',
'AROUT', N'cccc '</font></P>
<P><font color="#FFFFFF">情况四:TABLEUPDATE(2,.T.,'Vcustomers',Arry)</font></P>
<P><font color="#FFFFFF">*返回Visual FoxPro<BR>
?TABLEUPDATE(2,.T.,'Vcustomers',Arry)<BR>
*但参数函数返回.T.<BR>
?recno('Vcustomers')<BR>
*指针停在第4条记录上<BR>
?Arry[1]<BR>
*-1<BR>
*没有发生更新错误</font></P>
<P><font color="#FFFFFF">*回到SQL Server Query Analyzer<BR>
*输入如下语句并执行:<BR>
select customerid,phone from customers<BR>
*您将看到:所有记录Phone的值已经被Visual FoxPro的客户端修改了,值是:9999。按理说第2条、第3条记录被更新时会发生冲突,但由于Visual
FoxPro临时变更了更新冲突的检测方案为“关键字段”,这样原本应该能检测到的冲突被忽略了,Visual FoxPro客户端的新值强行覆盖其它客户端的修改。<BR>
事实上,查看 SQL Server 的 Profiler 工具也证明了以上论述:<BR>
sp_executesql N'UPDATE dbo.Customers SET Phone=@P1 WHERE CustomerID=@P2', N'@P1
nvarchar(24),@P2 varchar(50)', N'9999 ', 'ALFKI'<BR>
sp_executesql N'UPDATE dbo.Customers SET Phone=@P1 WHERE CustomerID=@P2', N'@P1
nvarchar(24),@P2 varchar(50)', N'9999 ', 'ANATR'<BR>
sp_executesql N'UPDATE dbo.Customers SET Phone=@P1 WHERE CustomerID=@P2', N'@P1
nvarchar(24),@P2 varchar(50)', N'9999 ', 'ANTON'<BR>
sp_executesql N'UPDATE dbo.Customers SET Phone=@P1 WHERE CustomerID=@P2', N'@P1
nvarchar(24),@P2 varchar(50)', N'9999 ', 'AROUT'</font></P>
<P><font color="#FFFFFF">放弃更新</font></P>
<P
class=boe_list><font color="#FFFFFF">如果要“放弃客户端对光标已经实施的变动”,该怎么办呢?这很简单,请使用TABLEREVERT()函数。这里有一个概念很重要:任何情况下执行本函数均不都会与远程数据源发生通讯,Visual
FoxPro只是从缓冲中把原先的数值取回填写入光标中。</font></P>
<P><font color="#FFFFFF">那么Visual FoxPro是怎样从缓冲中取回数据的呢?您可以用OLDVAL()函数得到相同的效果,它的用法这里暂不介绍!</font></P>
<P><font color="#FFFFFF">在开放式行缓冲下使用TABLEREVERT()函数:</font></P>
<TABLE width="100%" border=0>
<TBODY>
<TR>
<TD width="100%" bgcolor="#CCCCCC"> <LI>
<P class=boe_list><font color="#000000">语法:TABLEUPDATE(.f.[,nWorkAear|cTableAlias])
</font></P>
<LI>
<P class=boe_list><font color="#000000">返回值:1。如果当前记录没有被修改,则返回0。 </font></P>
<LI>
<P
class=boe_list><font color="#000000">可选参数——nWorkAear|cTableAlias。表示实行TABLEREVERT()的工作区,缺省表示对当前工作区有效。
</font></P>
</LI>
<font color="#000000"> </font></TD>
</TR>
</TBODY>
</TABLE>
<P class=boe_list><font color="#FFFFFF">例如:</font></P>
<P><font color="#FFFFFF">USE VCustomers<BR>
CURSORSETPROP("Buffering", 3, "VCustomers")<BR>
REPLACE Phone with '9999' <BR>
?VCustomer.phone<BR>
*9999<BR>
?TABLEREVERT(.F.,'VCustomers')<BR>
*返回1<BR>
?VCustomer.phone<BR>
*123456</font></P>
<P><font color="#FFFFFF">USE VCustomers<BR>
CURSORSETPROP("Buffering", 3, "VCustomers")<BR>
?TABLEREVERT(.F.,'VCustomers')<BR>
*返回0</font></P>
<P><font color="#FFFFFF">在开放式表缓冲下使用TABLEREVERT()函数:</font></P>
<TABLE width="100%" border=0>
<TBODY>
<TR>
<TD width="100%" bgcolor="#CCCCCC"> <LI>
<P class=boe_list><font color="#000000">语法:TABLEUPDATE(lAllRows[,nWorkAear|cTableAlias])
</font></P>
<LI>
<P class=boe_list><font color="#000000">返回值:放弃更新的记录数目 </font></P>
<LI>
<P class=boe_list><font color="#000000">必选参数——lAllRows。默认值为.F.,表示对当前记录放弃更新;本参数设定为
.T.,放弃更新所有被修改过的记录。 </font></P>
<LI>
<P
class=boe_list><font color="#000000">可选参数——nWorkAear|cTableAlias。表示实行TABLEREVERT()的工作区,缺省表示对当前工作区有效。
</font></P>
</LI>
<font color="#FFFFFF"> </font></TD>
</TR>
</TBODY>
</TABLE>
<P><font color="#FFFFFF">USE VCustomers<BR>
CURSORSETPROP("Buffering", 5, "VCustomers")<BR>
REPLACE Phone with '9999' next 4<BR>
*将第1、2、3、4、条记录的Phone改为9999<BR>
BROWSE<BR>
go 2<BR>
?TABLEREVERT(.F.,'VCustomers')<BR>
*1<BR>
?TABLEREVERT(.T.,'VCustomers')<BR>
*3</font></P>
<P><font color="#FFFFFF"> </font></P>
<P class=boe_head2><font color="#FFFFFF">刷新缓冲(refreshing buffers)</font></P>
<P><font color="#FFFFFF">记得在“以缓冲理解更新冲突”一节中我们提到过什么情况下Visual FoxPro会刷新缓冲区。其中“远程视图光标被打开”是很好的理解,这里不再累述。</font></P>
<P><font color="#FFFFFF">以 REQUERY()函数刷新远</font><font color="#000000">程视图光标</font></P>
<P><font color="#FFFFFF">REQUERY()函数的作用就是重新执行远程视图的SELECT-SQL描述,也就是重新打开远程视图光标,所以对系统造成较大的负担。对于这个函数,我有几点建议:</font></P>
<TABLE width="100%" border=0>
<TBODY>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -