【发布时间】:2015-07-19 19:36:54
【问题描述】:
这个问题与我之前问过的一个问题here 有关。
对 firebird 数据库的查询检索到单行记录集,因为 Where 子句包含主键。 然而,在随后的更新中,几乎表中的每一行都被更新了。 我一直期待只更新一行。 这是查询:
sQuery = "select memo from clients where clientID = 10021 "
发生的事情似乎是选择查询需要包含 记录集中的主键列,以便将更新限制为仅一条记录。
sQuery = "select memo, clientID from clients where clientID = 10021 "
但是在 postgresql 中,第一个查询的工作方式与第二个查询在 firebird 中的工作方式相同。
我可以依赖 postgresql 中的这种行为还是应该重写现有查询以包含 记录集中随后将更新的主键列?
有没有办法让 firebird 查询的行为与 postgresql 一样?
虽然我现在可以看到火鸟行为的逻辑,但它不是 我习惯了 MSAccess/DAO 背景。
我真的只是想知道发生了什么,以及 ADO 记录集所期望的更“正常”的行为是什么?
这是使用 firebird 的完整代码。
'FIREBIRD
'vb6 and ms ado 2.8
'windows 7 home edition 64 bit
'Firebird version is 2.5.4.26856 (x64).
'Firebird ODBC driver 2.0.3.154
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cs As String
Dim dbPath As String
dbPath = "c:\Parkes\Parkes.fdb"
cs = "DRIVER={Firebird/Interbase(r) Driver}; DBNAME=localhost:" & dbPath & "; UID=SYSDBA; PWD=masterkey;"
cn.ConnectionString = cs
cn.Open
Dim sQuery As String
sQuery = "select memo from clients where clientID = 10021 "
rs.Open sQuery, cn, adOpenStatic, adLockOptimistic
If rs.BOF <> True Or rs.EOF <> True Then
'putting msgbox rs.recordcount here confirms only 1 record in recordset
rs.Movefirst
rs.Fields("memo") = "blah"
rs.Update
End If
Set rs = Nothing
Set cn = Nothing
这是使用 postgresql 数据库的相同代码;
'POSTGRESQL
'vb6 and ms ado 2.8
'windows 7 home edition 64 bit
Postgresql version is 9.4 64 bit
psql ODBC driver 9.3.4
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cs As String
Dim dbPath As String
dbPath = "c:\Parkes\Parkes.fdb"
cs = "Driver={PostgreSQL ANSI};SERVER=localhost;Port=5432;DATABASE=Parkes;UID=postgres;PWD=masterkey;CONNSETTINGS=SET Datestyle TO 'DMY'%3b;BOOLSASCHAR=0;TEXTASLONGVARCHAR=1;TrueIsMinus1=1;"
cn.ConnectionString = cs
cn.Open
Dim sQuery As String
sQuery = "select memo from clients where clientID = 10021 "
rs.Open sQuery, cn, adOpenStatic, adLockOptimistic
If rs.BOF <> True Or rs.EOF <> True Then
'putting msgbox rs.recordcount here confirms only 1 record in recordset
rs.Movefirst
rs.Fields("memo") = "blah"
rs.Update
End If
Set rs = Nothing
Set cn = Nothing
【问题讨论】:
标签: postgresql vb6 ado firebird