Hello,
I have a LotusScript agent which write data to a back-end MySQL database. Everything is working fine.
Here’s the code:
'Access ODBC data source
Dim con As New ODBCConnection
Dim qry As New ODBCQuery
Dim result As New ODBCResultSet
If con.ConnectTo(“data source”, “login”, “password”) Then
'Access MySQL data
Set qry.Connection = con
Set result.Query = qry
qry.SQL = “select * from accounts”
result.Execute
result.LastRow
'Add a new row (a new account)
result.AddRow
'Call result.SetValue(“AccountUnq”, 0)
Call result.SetValue(“Login”, “test”)
Call result.SetValue(“Password”, “test”)
Call result.SetValue(“AddDate”, Now)
Call result.SetValue(“HomeDomain”, 1)
Call result.SetValue(“IgnoreGlobal”, “”)
Call result.SetValue(“Authenticated”, “T”)
Call result.SetValue(“AuthID”, 0)
'Write the new data into the MySQL db
result.UpdateRow
Dim AccountUnq As Integer
Call result.GetValue(“AccountUnq”, AccountUnq)
Print AccountUnq
result.Close(DB_CLOSE)
con.Disconnect
End If
Notice that in the code, I have the AccountUnq field which is an auto-increment integer in MySQL. I’m not giving a value to this field, since MySQL is gonna assign one when I update the row.
However, I was wondering how to get that number?
I tried this:
Dim AccountUnq As Integer
Call result.GetValue(“AccountUnq”, AccountUnq)
Print AccountUnq
But it always prints “0”.
In the Notes help, they are saying this:
“UpdateRow leaves you on the current row. If you perform an AddRow followed by an UpdateRow, you remain on the added row.”
So that means I’m at the right place.
I know I could do the same SQL Query again, and then access the LastRow, and then it works.
But I’m afraid some other rows might have been added by then… and I’m sure there’s a better way to do this.
Any idea?
Thanks!
Pascal