DuckDB Plugin for Xojo

EinhugurDuckDB.Database Class (console safe)

Database object representing a DuckDB database.

Object
   Database

class EinhugurDuckDB.Database

Constructors

DatabasePrivate constructor.

Methods

ConnectCreates connection to a database.
shared CreateInMemoryCreates database in memory.
shared OpenOpens or creates database.

Examples

Simple example, creating in memory duckdb database:

var db as EinhugurDuckDB.Database = EinhugurDuckDB.Database.CreateInMemory()
var connection as EinhugurDuckDB.Connection = db.Connect()

// create a table
connection.SQLExecute("CREATE TABLE integers(i INTEGER, j INTEGER)")

// insert three rows into the table
connection.SQLExecute("INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL)")

if connection.Error then
    MessageBox(connection.ErrorMessage)
end if

// Query the table and show the results in message boxes.
var records as EinhugurDuckDB.Recordset = connection.SQLSelect("SELECT * FROM integers")

if connection.Error then
    MessageBox connection.ErrorMessage
    return
end if

for row as Integer = 0 to records.RowCount - 1
    MessageBox("i = " + records.Int32Value(0,row).ToString() + ", j = " + records.Int32Value(1,row).ToString())
next



Simple example creating file database:

var f as FolderItem = FolderItem.ShowSaveFileDialog("*","test.duckdb")

if f = nil then
    return
end if

var db as EinhugurDuckDB.Database = EinhugurDuckDB.Database.Open(f)
var connection as EinhugurDuckDB.Connection = db.Connect()

// create a table
connection.SQLExecute("CREATE TABLE integers(i INTEGER, j INTEGER)")

// insert three rows into the table
connection.SQLExecute("INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL)")

if connection.Error then
    MessageBox(connection.ErrorMessage)
end if

// Query the table and show the results in message boxes.
var records as EinhugurDuckDB.Recordset = connection.SQLSelect("SELECT * FROM integers")

if connection.Error then
    MessageBox connection.ErrorMessage
    return
end if

for row as Integer = 0 to records.RowCount - 1
    MessageBox("i = " + records.Int32Value(0,row).ToString() + ", j = " + records.Int32Value(1,row).ToString())
next

Supported Platforms:

  • macOS Intel 32 bit
  • macOS Intel 64 bit
  • macOS Apple Silicon
  • Windows 32 bit
  • Windows 64 bit
  • Windows ARM 64 bit
  • Linux 32 bit
  • Linux 64 bit
  • Linux ARM 32 bit