From this report, how to add flush
to the code ?
How to change from Sub DisconnectDatabase(db)
to Function
?
Will there be any problem on connection like this ?
Function ConnectDatabase(dbFilename As String) As Object
Dim dbContext As Object : dbContext = createUNOService("com.sun.star.sdb.DatabaseContext")
Dim oDataSource As Object : oDataSource = dbContext.GetByName(dbFilename)
ConnectDatabase = oDataSource.GetConnection("","")'("Username","Password")
End Function
Sub DisconnectDatabase(db)
db.Close
db.Dispose()
End Sub
Sub AddNewDueDate
Dim FirstName$ : FirstName = "John"
Dim DueDate$ : DueDate = "2019-12-31"
InsertRecord(FirstName, DueDate)
End Sub
Sub InsertRecord(sFirstName$, sDueDate$)
On Local Error GoTo CloseConn
Dim db AS Object : db = ConnectDatabase("file:///home/fedora002/Documents/Firebird.odb")
Dim oStatement As Object : oStatement = db.CreateStatement
Dim oSQL$
oSQL = "INSERT INTO ""TABLE3"" (""NAME"", ""Note"") VALUES ('" & sFirstName & "', '" & sDueDate & "'" & ");"
Dim oResult As Object : oResult = oStatement.ExecuteQuery(oSQL)
DisconnectDatabase(db)
Exit Sub
CloseConn:
MsgBox "Error " & Err & ": " & Error$ & " (line : " & Erl & ")"
DisconnectDatabase(db)
End Sub