Xbasic
SQL::ConnectionAffectedRows Method
Syntax
RowCount as N = AffectedRows()
Returns
- RowCountNumeric
Returns the number of affected rows.
Description
Return affected rows.
Discussion
The AffectedRows() method returns the number of rows affected by the last SQL INSERT, DELETE, or UPDATE statement. IMPORTANT: In Version 10.5 and above, if there are no records that match the WHERE clause in the UPDATE or DELETE statement, the call result is set to .F.. across all database types. Previously, the call result was set inconsistently (.t. for MySQL and .f. for other database types).
Example
dim conn as SQL::Connection
dim del as SQL::DeleteStatement
dim sql_delete as C
sql_delete = "DELETE FROM CustomerX WHERE substring(lastname,1,1) = 'J'"
if .not. conn.open("{A5API=Access, FileName='C:\Program Files\A5V8\MDBFiles\Alphasports.mdb', UserName='Admin'}") then
ui_msg_box("Error", conn.callresult.text)
end
end if
conn.PortableSQLEnabled = .t.
dim flag as l
flag = conn.execute(sql_delete) then
if flag = .f. then
if "Database API" $ conn.callResult then
'a critical database error
ui_msg_box("Critical Database Error",conn.callresult.text)
else
'No matching record was found
ui_msg_box("Error","No record satisfied the WHERE clause")
end if
else
ui_msg_box("Affected Rows", str(conn.AffectedRows()))
end if
conn.close()See Also