Macros/Base/ba002

    From The Document Foundation Wiki
    < Macros‎ | Base
    Other languages:

    Description

    Execute update in current database

    Sub main()
        doc = ThisComponent
        conn = doc.DataSource.getConnection("", "")
    
        sql = "UPDATE ""contactos"" SET ""numbers""=TRIM(""numbers"")"
        cursor = conn.prepareStatement(sql)
        result = cursor.executeUpdate()
        doc.store()
        MsgBox result
    End Sub
    def main():
        doc = XSCRIPTCONTEXT.getDocument()
        conn = doc.DataSource.getConnection('', '')
    
        sql = 'UPDATE "contactos" SET "numbers"=TRIM("numbers")'
        cursor = conn.prepareStatement(sql)
        result = cursor.executeUpdate()
        doc.store()
        print(result)  # silent if Python console is absent
        return

    Note pin.svg

    Note:
    Input/Output to screen helps overcoming the absence of Python standard output. Python scripts can be prototyped by use of the Python shell and its Read Execute Print Loop (REPL) mechanism. Refer to Output to Consoles in order to enable such facility

    Notes