Calc BASIC + Firebird : How to add flush?

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

Hello,

Just add after SQL execute & before calling DB closing.

From:

Dim oResult     As Object   : oResult       = oStatement.ExecuteQuery(oSQL)
DisconnectDatabase(db)

To:

Dim oResult     As Object   : oResult       = oStatement.ExecuteQuery(oSQL)
db.getParent().flush
DisconnectDatabase(db)

No need to change Sub to Function since there is no return.

Edit 2019-11-24:

Went one step further. Took your code, added the Flush command as stated above and using my Firebird embedded file the code executed without error. Running the code a second time did show an error with the primary key as expected.

1 Like

ID NAME Note

    49	John	12/31/19

    48	Input 104	01/17/19

    47	Input 104	01/17/19

    46	Input 104	01/17/19

    45	Input 104	01/17/19

    44	Input 104	01/17/19

    43	Input 104	01/17/19
    42	Input 104	01/17/19

    41	Input 104	01/17/19

    40	Input 104	01/17/19

Thank you so much.

Glad to have helped.