Macros/Basic/Base
< Macros
TDF LibreOffice Document Liberation Project Blog comunitari Weblate Nextcloud Redmine Ask LibreOffice Donazione
Base
Connettetevi per registrare il database
Sub Main()
con = get_db("Bibliography")
End Sub
Function get_db(db_name As String)
dbc = createUnoService("com.sun.star.sdb.DatabaseContext")
If dbc.hasByName(db_name) Then
db = dbc.getByName(db_name)
con = db.getConnection("","")
End If
get_db = con
End Function
Create una tabella con SQL
con = get_db("test")
sql = "CREATE TABLE ""person"" (""id"" INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY NOT NULL, ""name"" VARCHAR(255) NOT NULL, ""last_name"" VARCHAR(255) NOT NULL)"
cursor = con.createStatement()
cursor.execute(sql)
con.getParent().DatabaseDocument.store()
con.close()
Inserite dati con SQL
con = get_db("test")
sql = "INSERT INTO ""person"" (""name"", ""last_name"") VALUES ('Teresa', 'Salgueiro')"
cursor = con.createStatement()
cursor.execute(sql)
con.getParent().DatabaseDocument.store()
con.close()
Inserite dati usando dichiarazioni predeterminate
con = get_db("test")
sql = "INSERT INTO ""person"" (""name"", ""last_name"") VALUES (?, ?)"
cursor = con.prepareStatement(sql)
cursor.setString(1, "Teresa")
cursor.setString(2, "Salgueiro")
cursor.execute()
con.getParent().DatabaseDocument.store()
con.close()