Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DuckDB support #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ ${line.separator}with the full path to the 'libraries' folder inside your sketch
<property name="author" value="Florian Jenett"/>
<property name="copyright" value="(c) 2005 - 2023"/>
<property name="libraryName" value="BezierSQLib"/>
<property name="versionNumber" value="0.3.2"/>
<property name="versionNumber" value="0.3.3"/>
<property name="yourLink" value="http://bezier.de/" />
<property name="keywords" value="MySQL, SQLite, PostgreSQL, SQL, database"/>
<property name="keywords" value="MySQL, SQLite, PostgreSQL, DuckDB, SQL, database"/>
<property name="javaVersion" value="1.8"/>

<buildnumber file="resources/build.number" />
Expand All @@ -39,6 +39,7 @@ ${line.separator}with the full path to the 'libraries' folder inside your sketch
<include name="mysql-connector-j-8.0.31.jar"/> <!-- MySQL -->
<include name="sqlite-jdbc-3.7.2.jar"/> <!-- SQLite -->
<include name="postgresql-9.2-1002.jdbc3.jar"/> <!-- PostgreSQL -->
<include name="duckdb_jdbc-0.7.1.jar"/> <!-- DuckDB -->
</fileset>
</path>

Expand Down
31 changes: 31 additions & 0 deletions examples/DuckDB_example1/DuckDB_example1.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import de.bezier.data.sql.*;

DuckDB db;

void setup()
{
size( 100, 100 );

db = new DuckDB( this, "test.db" ); // open database file

if ( db.connect() )
{
// list table names
db.query( "SHOW TABLES" );

while (db.next())
{
println( db.getString(1) );
}

// read all in table "table_one"
db.query( "SELECT * FROM table_one" );

while (db.next())
{
println( db.getString("field_one") );
println( db.getInt("field_two") );
}
}
}

4 changes: 2 additions & 2 deletions lib/build.number
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Sun Jan 08 14:58:26 CET 2023
build.number=599
#Sat Mar 18 00:50:53 GMT 2023
build.number=612
Binary file added lib/duckdb_jdbc-0.7.1.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions release/BezierSQLib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ url = https://github.com/fjenett/sql-library-processing
category = Data
sentence = A library to facilitate communication with SQL-based databases
paragraph = SQLibrary is an interface to MySQL, SQLite and PostgreSQL databases
version = 1192
prettyVersion = 0.3.2
version = 1206
prettyVersion = 0.3.3
Binary file modified release/BezierSQLib.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions resources/build.number
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Sun Jan 08 14:58:26 CET 2023
build.number=1194
#Sat Mar 18 00:50:53 GMT 2023
build.number=1207
59 changes: 59 additions & 0 deletions src/de/bezier/data/sql/DuckDB.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package de.bezier.data.sql;

import processing.core.*;
import java.util.ArrayList;

/**
* DuckDB wrapper for SQL library for Processing 2+
*/
public class DuckDB
extends de.bezier.data.sql.SQL
{
/**
* Creates a new DuckDB connection.
*
* @param _papplet Your sketch, pass "this" in here
* @param _database Path to the database file, if this is just a name the data and sketch folders are searched for the file
*/
public DuckDB ( PApplet _papplet, String _database )
{
super( _papplet, _database );
init();
}

/**
* Creates a new DuckDB connection, same as DuckDB( PApplet, String )
*
* @param _papplet Your sketch, pass "this" in here
* @param _server Ignored
* @param _database Path to the database file, if this is just a name the data and sketch folders are searched for the file
* @param _user Ignored
* @param _pass Ignored
*/
public DuckDB ( PApplet _papplet, String _server, String _database, String _user, String _pass )
{
this( _papplet, _database );
}


private void init ()
{
this.driver = "org.duckdb.DuckDBDriver";
this.type = "duckdb";

this.url = "jdbc:" + type + ":" + database;
}

public String[] getTableNames ()
{
if ( tableNames == null )
{
tableNames = new ArrayList<String>();
query( "SHOW TABLES" );
while ( next() ) {
tableNames.add( getObject(1).toString() );
}
}
return tableNames.toArray(new String[0]);
}
}