Base Macro Calculations write to controls but don't save?

I have several simple calculations that i write to text or numeric controls.

The correct data is displayed in the form fields but will not save to the database unless I initiate a minor edit like adding a zero or space.

Neither Basic nor Python seem to provide a solution. Frustrated I switched to SQLite3 and rebuilt the data and forms only to find the problem still persisted.

Resorting to an AI assistant to help and 3 hours of ideas tested; the AI finally reported:

Root Cause: Bug #68746 (13+ years) - Base dirty flag only trusts real user keyboard input

I am on Linux Arch running the latest Fresh LibreOffice.

Am considering a data integration to Calc where I doubt that this issue exits?

Any insight will be greatly appreciated.

Did you try something like commit() or updateRow() with your form?

AI guessing bogus bugs: 68746 – CRASH - Base wizard crashes on embedded firebird db creation - LibreOffice 64bit OSX

@LOBster26 : Could be you only write the data to display, but not to the current value of the control. We will need a hint how you put the result of the calculation to the control.

Yes both and all sorts of property tests to evaluate the condition of the control.

Yes Agree!!!
AI hallucination is a real caution.
I could not find it either which is why im asking what’s up with such a basic issue.

Best upload something to test for us. HSQLDB will be easiest, but I use also sqlite…

Yes the simple multiplication appears in the debit field but will not save to DB unless I manually tinker it. Some update flag is refusing to let the virtual data displayed write to the db.

I have literally pages of fails but I’ll post the (abbreviated) code where I left it.
This code does everything error free but will not save the write to the HSQLDB database.

def CalcWeightedAvgPrice_Py(oEvent):
    # 1) Get root/main form from the document
    oRootForm = GetRootForm()
    if oRootForm is None:
        return  # Root form not found, abort

    oTradesForm = GetMySubForm(oRootForm, "sf_trades_editable")
        
    oMessageModel = oTradesForm.getByName("txt_TradeNotes")
    oDebitModel   = oTradesForm.getByName("c_debit")
    oStopPriceModel   = oTradesForm.getByName("c_stopPrice")
    oTgtPriceModel   = oTradesForm.getByName("c_tgtPrice")

    # Write Messages
    oMessageModel.Text = msg2
    oStopPriceModel.Value =  stopPrice
    oTgtPriceModel.Value =  tgtPrice
    oDebitModel.Value  = debit

# commit() updateRow() save form, refresh form, property checks.... nothing would save the data without my touching it.
    
# At this point the correct data appears in the correct form controls but not in the database unless I  
# make a manual change like a space char or a trailing zero   

# This was the last thrash at the matter before I call it a WOT and shutdown the machine.
    try:
        # Only try to update when the form is on an existing or valid new record
        if not oTradesForm.IsNew:           # on an existing record
            oTradesForm.updateRow()
        else:
            # For a new record, let the user save normally (or design an explicit insert logic)
            show_msgbox("Finish entering the new record, then save.", "New Record")
    except Exception as e:
        show_msgbox(f"Error saving record: {e}", "Save Error")
    
# 7) Commit current record on the form so changes go to the table
    # # Direct SQLite write - with import uno at top
    # try:
    #     db_ctx = uno.createUnoService("com.sun.star.sdb.DatabaseContext")  # Note: uno.
    #     data_source = db_ctx.getByName("DemoLobo")
    #     connection = data_source.getActiveConnection()
    #
    #     record_id = int(oTradesForm.getByName("ID").Value)
    #     stmt = connection.createStatement()
    #     sql = f'UPDATE "tbl_Trades" SET "stpPrice"={stopPrice}, "debit"={debit} WHERE "ID"={record_id}'
    #     stmt.executeUpdate(sql)
    #     connection.commit()
    #     stmt.close()
    #
    # except Exception as e:
    #     show_msgbox(f"SQL failed: {e}", "Error")
    #

All fields are connected to a data field of the database?
Try something like
oDebitModel.BoundField.updateDouble(debit)

1 Like

WOW Robert!
A oneliner to make my new year a great one:
That wrote instantly to the record!
I used:
oMessageModel.BoundField.updateString(msg2)
to write the string!

So very thankful!!!

There is no issue at all. This is perfectly well documented. Just don’t ask the slop machines.