Giter Site home page Giter Site logo

giorgi / duckdb.net Goto Github PK

View Code? Open in Web Editor NEW
347.0 13.0 62.0 5.31 MB

Bindings and ADO.NET Provider for DuckDB

Home Page: https://duckdb.net

License: MIT License

C# 100.00%
duckdb ado-net data-science duckdb-database hacktoberfest hacktoberfest2023

duckdb.net's Introduction

Hi there ๐Ÿ‘‹ I'm Giorgi

Twitter Follow Website Hire Giorgi Sponsor Giorgi

I am a software developer with more than a decade of experience, working mainly with C#, ASP.NET Core, REST, GraphQL, MAUI, Xamarin, Entity Framework Core, AWS, Azure, and SQL Server. I have also worked with many other frameworks and systems such as ASP.NET MVC, ASP.NET Web API, WCF, Avalonia, WinForms, Oracle, and many more. Top 1% on Stack Overflow, member of Top 3% freelance software developers network and InfoQ Editor.

Check out my portfolio or read my blog and Follow me on Twitter and Follow me on InfoQ

GitHub Streak

Shows an illustrated sun in light mode and a moon with stars in dark mode. Shows an illustrated sun in light mode and a moon with stars in dark mode.

duckdb.net's People

Contributors

acinep avatar arontsang avatar chris-barton avatar colombod avatar cricle avatar dev-gavinfang avatar giorgi avatar hazzik avatar jhudler avatar kmosegaard avatar magneto-81 avatar miketwc1984 avatar pkese avatar roee88 avatar rubiktubik avatar sartorialoffense avatar seddryck avatar simoncropp avatar szarnyasg avatar travis-leith avatar unconverged avatar urizn avatar yxmm-wxe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

duckdb.net's Issues

Feature Request: NuGet package containing native libraries

Having a package with libraries for every platform would be nice. If referenced as a dependency the .NET runtime will find native libs automatically.
Just need to name them correctly runtimes/<platform rid>/native/duckdb.<dll/so/dylib>, for example runtimes/win-x86/native/duckdb.dll

DuckDBException when inserting some Unicode characters using appender

When using the DuckDBAppender, I am receiving exceptions when inserting some Unicode characters. I believe this is a DuckDB.NET issue, as similar code works fine with Python.

Example code (uses the new .NET6 console application template):

using DuckDB.NET.Data;

var USE_APPENDER = true;

var DB_FILE = "csharptest.duckdb";
var TABLE_NAME = "TestTable";

File.Delete(DB_FILE);
File.Delete($"{DB_FILE}.wal");

using var db = new DuckDBConnection($"DataSource={DB_FILE}");
db.Open();

var dbCommand = db.CreateCommand();

dbCommand.CommandText = $"CREATE TABLE {TABLE_NAME}(index INTEGER, words VARCHAR);";
dbCommand.ExecuteNonQuery();

var words = new List<string> { "hello", "์•ˆ๋…•ํ•˜์„ธ์š”", "ร˜3mm CHAIN" };

if (USE_APPENDER) {
    using var appender = db.CreateAppender(TABLE_NAME);

    for (int i = 0; i < words.Count; i++) {
        Console.WriteLine($"Creating row {i}...");

        var row = appender.CreateRow();
        row.AppendValue(i).AppendValue(words[i]);

        row.EndRow();
    }

    appender.Close();
} else {
    for (int i = 0; i < words.Count; i++) {
        Console.WriteLine($"Creating row {i}...");

        dbCommand.CommandText = $"INSERT INTO {TABLE_NAME} VALUES ({i}, '{words[i]}');";
        dbCommand.ExecuteNonQuery();
    }
}

db.Close();

If USE_APPENDER = true, the program will crash when inserting the 3rd word with the following log:

Creating row 0...
Creating row 1...
Creating row 2...
Unhandled exception. DuckDB.NET.Data.DuckDBException (0x80004005): INTERNAL Error: Invalid unicode (byte sequence mismatch) detected in segment statistics update
   at DuckDB.NET.Data.DuckDBAppender.ThrowLastError(DuckDBAppender appender)
   at DuckDB.NET.Data.DuckDBAppender.Close()
   at Program.<Main>$(String[] args) in C:\Users\jmyers\projects\duckdb-test\Program.cs:line 33

If USE_APPENDER = false, the program will complete successfully. Opening up the database with Tad reveals that all data was inserted successfully, with no encoding issues.

The only way I have found to insert strings containing ร˜ has been to convert the string to ASCII like Encoding.ASCII.GetString(Encoding.UTF8.GetBytes(s)), however this results in the ร˜ being replaced with ?? - not exactly desirable.

Other information:

  • Windows 11 22H2 x64
  • dotnet --version is 7.0.102
  • Using package DuckDB.NET.Data.Full, version 0.6.1

Does not work with Dapper

For some reason I can't get this to work with Dapper.
As I understand it, Dapper is just a wrapper around ADO.Net so anything that looks like ADO.Net should work, in principle.

When I try to execute something using Dapper, I get "DuckDBOpen failed". I tried to work out a way to find a more detailed error message but was unsuccessful.

I created a branch which demonstrates the error here: https://github.com/travis-leith/DuckDB.NET/tree/show_dapper_error

Please provide more detail on error messages

I noticed that in comparing CLI error messages, I get a clear descriptive error. When I use this library I just get "DuckDBQuery failed".

Is there any additional error information coming from the external dlls (something similar to what the CLI shows) that can be propagated in .net?

Strange Exception error on sample

Hi,
The idea to have access from c# to DuckDB performance & its easiness to read parquet files looks amazing, but I tried to run this sample from the readme, and it returns a strange exception with the following message:
"plรบ=:โ˜ป"

this is the code producing it:
(using windows amd64 duckdb.dll v0.2.8)

 using (var conn = new DuckDBConnection("Data Source=:memory:"))
  {
      try
      {
          conn.Open();
          var command = conn.CreateCommand();
          command.CommandText = "CREATE TABLE integers(foo INTEGER, bar INTEGER);";
          var executeNonQuery = command.ExecuteNonQuery();
      }
      catch (Exception ex)
      {
          Console.WriteLine(ex.Message);
      }
  }

Thanks,

Feature Request: ADO Transaction support

I have no idea how one goes from sql with BEGIN TRANSACTION to supporting transactions as a separate object in ADO, but would be a welcome addition to this library.

Error strings appear mangled

When trying to send a SQL insert, I'm getting mangled error strings:

One or more errors occurred. (๏ฟฝ-๏ฟฝ๏ฟฝ	V)
Unhandled exception. System.AggregateException: One or more errors occurred. (๏ฟฝ-๏ฟฝ๏ฟฝ	V)
 ---> DuckDB.NET.Data.DuckDBException (0x00000001): ๏ฟฝ-๏ฟฝ๏ฟฝ	V
   at DuckDB.NET.Data.DuckDbCommand.ExecuteScalarOrNonQuery()
   at DuckDB.NET.Data.DuckDbCommand.ExecuteNonQuery()

Maybe there's actually something wrong with my insert statement, so no need to worry about inserts not working, just the text appears wrong (however the same SQL command works fine on sqlite, but then again the SQL syntax is not exactly the same between duckdb and sqlite).

This is with DuckDB.Net 0.4.0 and latest duckdb.so (on Linux).

And I should use this occasion to thank you very much for all your updates & commits.

update to DuckDB 0.7.1

Hi there,

is it possible to push an update to Nuget that references DuckDB 0.7.1?

Thanks

Which version of DuckDB is supported?

I can't seem to find in your code (please excuse my incompetence) where you bring in the external functionality. I can only find .cs files. Does this mean this library assumes a prior installation of DuckDB, and if so, which version(s) is(are) supported?

Allow multiple concurrent connections to the same DB

The following code

using var duckDBConnection = new DuckDBConnection("Data Source=file.db");
  duckDBConnection.Open();

  using var conn2 = new DuckDBConnection("Data Source=file.db");
  conn2.Open();

raises an error.

According to the c++ api docs, concurrent connections are allowed.

This one might be tricky to solve.

Zero IntPtr for string fails

Here is the test that fails with ADO wrapper.


            command.CommandText = "PRAGMA show('integers');";
             reader = command.ExecuteReader();
            PrintQueryResults(reader);

To Fix, I had changed DuckDbDataReader.cs for following code to check for zero IntPtr.

        public override string GetString(int ordinal)
        {
            var unmanagedString = PlatformIndependentBindings.NativeMethods.DuckDBValueVarchar(queryResult, ordinal, currentRow);
            return (unmanagedString.Equals(IntPtr.Zero)) ? "" : unmanagedString.ToManagedString();
        }

Thanks,
Ravi

Support shared in-memory databases

Python library (probably others as well) support connecting to a shared in-memory database with a connection string like this: :memory:?cache=shared

DbParameter Support

ADO default use @param as paremnt, but duckdb use ?, can fill the gap with specified name of parameters?

DuckDBDataReader.cs does not implement GetSchemaTable() method that causes DataTable.Loader(IDataReader) and Dapper's Query() method fail

Please add the followings to fix the issue. Thank you so much. (ref: https://github.com/mgravell/fast-member/blob/e7423b71d98fc0dd1d3a6eebf425fd987d5da56e/FastMember/ObjectReader.cs#L111)

public override DataTable GetSchemaTable() { // these are the columns used by DataTable load DataTable table = new DataTable { Columns = { {"ColumnOrdinal", typeof(int)}, {"ColumnName", typeof(string)}, {"DataType", typeof(Type)}, {"ColumnSize", typeof(int)}, {"AllowDBNull", typeof(bool)} } }; object[] rowData = new object[5]; for (int i = 0; i < FieldCount; i++) { rowData[0] = i; rowData[1] = GetName(i); rowData[2] = GetFieldType(i); rowData[3] = -1; rowData[4] = true; table.Rows.Add(rowData); } return table; }

Unrecognised Type (Text)

Using the latest version of the repo, and changing the sample code to the following

command.CommandText = "CREATE TABLE integers(foo text, bar INTEGER);";
var executeNonQuery = command.ExecuteNonQuery();

command.CommandText = "INSERT INTO integers VALUES ('3', 4), ('5', 6), ('7', NULL);";

and PrintQueryResults changed to

if (queryResult.GetFieldType(ordinal) == typeof(string))
                    {
                        var sval = queryResult.GetString(ordinal);
                        Console.Write(sval);
                    }
                    else
                    {
                        var val = queryResult.GetInt32(ordinal);
                        Console.Write(val);
                    }

I get the unrecognized type error.

But if I change the DuckDBType enum to

DuckdbTypeVarchar = 17

then it works. This error existed on the previous version but the latest version of DuckDB.Net was released before I was finished investigating. Note that on the previous version the required value to get it work was 20, not 17. Does this mean that extra types should be inserted in the enum to get it up to at least 17?

Parquet write fails with DuckDB.dll 0.2.8

Thanks for fixing the previous issue so quick.
I have tried to write a parquet file and it throws this error:
Catalog Error: Copy Function with name parquet does not exist!
Did you mean "csv"?

It works on the CLI duckdb.exe, I haven't found any doc stating that the C++ API does not support Parquet, so I don't know if the issue is about your bindings or the Dll API itself.

using var conn = new DuckDBConnection("Data Source=:memory:");
try
{
    conn.Open();
    var command = conn.CreateCommand();

    command.CommandText = "CREATE TABLE integers(foo INTEGER, bar INTEGER);";
    var executeNonQuery = command.ExecuteNonQuery();

    command.CommandText = "INSERT INTO integers VALUES (3, 4), (5, 6), (7, 8);";
    executeNonQuery = command.ExecuteNonQuery();

    command.CommandText = "SELECT foo, bar FROM integers";
    var reader = command.ExecuteReader();

    command.CommandText = "COPY (SELECT * FROM integers) TO 'result-snappy.parquet' (FORMAT 'parquet');";
    executeNonQuery = command.ExecuteNonQuery();
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

Thanks for your effort bringing DuckDB to .NET!

time with milliseconds is not handled properly

Steps to reproduce:

        var duckDbCommand = connection.CreateCommand();
        duckDbCommand.CommandText = "select  now() as tme";
        var reader = duckDbCommand.ExecuteReader();
        reader.GetDateTime(0)

This will crash with below error

"Valid values are between 0 and 999, inclusive. (Parameter 'millisecond')"

now function returns time with milliseconds. If specifying time without milliseconds (e.g. TIMESTAMP '1992-09-20 20:38:40' ) GetDateTime works correctly

Reading DateTime has issue.

Hello,

If I take the current Dev repo and try to select Datetime column. I get following Error.

System.Runtime.InteropServices.SEHException: 'External component has thrown an exception.'
This exception was originally thrown at this call stack:
DuckDB.NET.Windows.WindowsBindNativeMethods.DuckDBValueInt32(DuckDB.NET.DuckDBResult, long, long) in NativeMethods.Windows.cs
DuckDB.NET.Data.DuckDBDataReader.GetInt32(int) in DuckDBDataReader.cs
DuckDB.NET.Samples.Program.PrintQueryResults(System.Data.Common.DbDataReader) in Program.cs
DuckDB.NET.Samples.Program.AdoNetSamples() in Program.cs
DuckDB.NET.Samples.Program.Main(string[]) in Program.cs

Here is my Sample Project snippet to reproduce it.

private static void AdoNetSamples()
        {
            if (File.Exists("file.db"))
            {
                File.Delete("file.db");
            }
            using var duckDBConnection = new DuckDBConnection("Data Source=file.db");
            duckDBConnection.Open();

            var command = duckDBConnection.CreateCommand();

            command.CommandText = "Create table test2 (id Int, dt TIMESTAMP, string varchar  );";
            var executeNonQuery = command.ExecuteNonQuery();

            command.CommandText = "Insert into test2 values(1,'1992-09-20 11:30:00', 'Xyz');";
            executeNonQuery = command.ExecuteNonQuery();

            //command.CommandText = "select * from test2;";
            //var executeScalar = command.ExecuteScalar();

            command.CommandText = "select * from test2;";
            var reader = command.ExecuteReader();
            PrintQueryResults(reader);

            var results = duckDBConnection.Query<FooBar>("SELECT foo, bar FROM integers");

            try
            {
                command.CommandText = "Not a valid Sql statement";
                var causesError = command.ExecuteNonQuery();
            }
            catch (DuckDBException e)
            {
                Console.WriteLine(e.Message);
            }
        }

Parameterized `CREATE TABLE` gives syntax error

Hi,

I'm trying to create a table with a parameterized query, but I get a syntax error. Interestingly, not all creation commands fail (see commented out lines)

var connection = new DuckDBConnection("DataSource=:memory:");
using (var duckDbCommand = connection.CreateCommand())
{
  connection.Open();

  // WORKS:
  // duckDbCommand.CommandText = "CREATE TABLE t1 (id INT, name VARCHAR);";  

  // WORKS:
  // duckDbCommand.CommandText = "CREATE TABLE t2 AS SELECT * FROM read_csv_auto(?);"; 
  // duckDbCommand.Parameters.Add(new DuckDBParameter(csvPath));

  // FAILS:
  duckDbCommand.CommandText = "CREATE TABLE t3(id INT, ? VARCHAR);";  
  duckDbCommand.Parameters.Add(new DuckDBParameter("name"));

  duckDbCommand.ExecuteNonQuery();
}
Error: DuckDB.NET.Data.DuckDBException (0x00000001): Parser Error: syntax error at or near "?"
LINE 1: CREATE TABLE t2 (id INT, ? VARCHAR);
                                 ^
   at DuckDB.NET.Data.PreparedStatement.Prepare(DuckDBNativeConnection connection, String query) in /_/DuckDB.NET.Data/Internal/PreparedStatement.cs:line 55
   at DuckDB.NET.Data.DuckDbCommand.PrepareIfNeeded() in /_/DuckDB.NET.Data/DuckDBCommand.cs:line 114
   at DuckDB.NET.Data.DuckDbCommand.ExecuteNonQuery() in /_/DuckDB.NET.Data/DuckDBCommand.cs:line 70
   at Submission#98.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)

What am I doing wrong? Or is this a bug?

Support for DUCKDB_TYPE_UUID

DuckDb allows for UUID columns and provides a built-in data type, DUCKDB_TYPE_UUID, to handle such columns. However, there are some strange things. We have a value of UUID type. DuckDB identifies the value as UUID. The docs indicate that UUID is actually a duckdb_hugeint (128 bit integer), but when we try getting this value as a HugeInt, we get 0. When we try getting the same value as a string, we get an empty string. Something's wrong here, we need to investigate.

Conversion higeint->double and vice versa works fine. If we have a real hugeint (SELECT 125::HUGEINT; ) it also works fine (we get a value with lower part set to 125), so apparently the problem is in UUID handling.

duckdb/duckdb#4457

Object reference not set to an instance of an object

Description

Running on M1 Mac with .NET6 (6.0.203) using self build libduckdb.dylib (arm64) from recent master.
Samples project fails at line 43: PrintQueryResults(reader);

The actual error happens in DuckDBNativeObjects.cs line 93: var column = Marshal.PtrToStructure(columns + Marshal.SizeOf() * i);
(a
The error message is:

Exception has occurred: CLR/System.NullReferenceException An unhandled exception of type 'System.NullReferenceException' occurred in System.Private.CoreLib.dll: 'Object reference not set to an instance of an object.' at System.Runtime.CompilerServices.CastHelpers.Unbox(Void* toTypeHnd, Object obj) at System.Runtime.InteropServices.Marshal.PtrToStructure[T](IntPtr ptr)

Earlier actions (creating table, inserting data) seem to be successful when I check the file.db database using DuckDB CLI.

Linux support [feature-request]

Hi, I'm interested in trying DuckDB from .NET, and naturally came across your bindings. I see support for Windows and MacOS already exist, and was wondering if you had plans to add Linux support?

Some Dapper issues

I've found that it's easy to break Dapper and I'm including a script to reproduce it here. Works fine with Sqlite.

Not sure about priority of this ... do we even care about Dapper at this point in time?.

#!/usr/bin/env -S dotnet fsi

#r "nuget: DuckDB.NET.Data, 0.4.0"

// or include path to DuckDB.NET.Data build and load the .dll directly
//#I "../org/DuckDB.NET/DuckDB.NET.Data/bin/Debug/netstandard2.0/"
//#r "DuckDB.NET.Data.dll"

// also put libduckdb.{dll|so} someplace (e.g. in current directory) and point to it here
#I "." 

#r "nuget: Microsoft.Data.Sqlite, 6.0.6"
#r "nuget: Dapper, 2.0.123"

open DuckDB.NET.Data
open Microsoft.Data.Sqlite
open Dapper
open System.Data

// test with either DuckDb or Sqlite
let conn =
    //new SqliteConnection("Data Source=:memory:") :> IDbConnection
    new DuckDBConnection("Data Source=:memory:") :> IDbConnection

conn.Open()
conn.Execute("CREATE TABLE test (id INTEGER, name VARCHAR)") |> ignore

[<CLIMutable>] type Row = { id:int; name:string }

conn.Query<Row>("SELECT * FROM test")
|> Seq.length
|> printfn "initial rows: %d"

conn.Execute("INSERT INTO test (id,name) VALUES (123,'test')") |> ignore

for row in conn.Query<Row>("SELECT * FROM test") do
    printfn $"after insertion: {row.id} {row.name}"

Support for BigInteger

Since C#'s BigInteger can be arbitrary large, we could not simply use DuckDB's HUGEINT data type. In case of DuckDB, HUGEINT is always 128 bit large.

We can support BigInteger as a string column, serialize to string on bind and parse on read.

Queries with Decimal type fail ("DuckDBQuery failed")

Description

When querying tables with a decimal data type, duckdb.net returns an error "DuckDBQuery failed". This occurs where the decimal values in the table are NULL or has a value.

Expected result

The query should return the decimal values stored in the table.

##Minimal example: ##

using System;
using System.Data.Common;
using DuckDB.NET.Data;
namespace DuckDbDecimalIssue
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // Using duckdb.dll from:
            //  https://github.com/duckdb/duckdb/releases/download/v0.3.1/libduckdb-windows-amd64.zip
            var connectionString = "Data Source=db.duckdb;";
            using (var cn = new DuckDBConnection(connectionString))
            {
                cn.Open();
                Execute(cn, @"DROP TABLE IF EXISTS test;");
                Execute(cn, @"CREATE TABLE test (dec DECIMAL(18, 4) NULL, value FLOAT NULL);");
                Execute(cn, @"INSERT INTO test (dec, value) SELECT NULL, 10");

                var query = "SELECT * FROM test";
                using (var reader = ExecuteReader(cn, query))
                {
                    while (reader.Read())
                    {
                        Console.WriteLine($"{reader[0]}\t{reader[1]}");
                    }
                }

            }
        }

        static void Execute(DuckDBConnection cn, string sql)
        {
            var createTableCommand = cn.CreateCommand();
            createTableCommand.CommandText = sql;
            createTableCommand.ExecuteNonQuery();
        }

        static DbDataReader ExecuteReader(DuckDBConnection cn, string sql)
        {
            var createTableCommand = cn.CreateCommand();
            createTableCommand.CommandText = sql;
            return createTableCommand.ExecuteReader();
        }
    }
}

If you change the column type of "dec" above to INT, then the code works properly.

No results are received with any query

Hi. I'm experimenting with DuckDb through C# and it appears that I'm not able to get results of any query.

I receive no syntax or execution error, but no result is returned. I've tried several queries and all of the queries that I run with ExecuteScalar return 0 as a value and all of the queries that are expected to return multiple columns return zero columns (i.e. db reader does not iterate over rows). The same queries produce the correct result with DuckDb CLI.

The simplest code is:

await using (var conn = new DuckDBConnection("Data Source=:memory:"))
{
    conn.Open();

    var command = conn.CreateCommand();
    
    command.CommandText = "SELECT 42;";
    var executeScalar = await command.ExecuteScalarAsync();
    Console.WriteLine(executeScalar);
}

We expect this query to return 42, but it returns 0.

My setup:

  • libduckdb 0.4.0 prebuilt
  • DuckDB.NET 0.2.9.1
  • macOS with Intel CPU

concurrent `:memory:` connections are not separate

I want to have multiple DuckDBConnection instances that are having their own memory/database. What I get, however, is instances with shared access to the same memory/database.

Is this expected behavior?

using DuckDB.NET.Data;

// connection 1
Console.WriteLine("connection 1:");
var conn1 = new DuckDBConnection("DataSource=:memory:");
conn1.Open();
var cmd1 = conn1.CreateCommand();
cmd1.CommandText = "CREATE TABLE t1 (foo INTEGER, bar INTEGER);";
cmd1.ExecuteNonQuery();

cmd1.CommandText = "show tables;";
PrintQueryResults(cmd1.ExecuteReader());

// connection 2
Console.WriteLine("connection 2:");
var conn2 = new DuckDBConnection("DataSource=:memory:");
conn2.Open();
var cmd2 = conn2.CreateCommand();
cmd2.CommandText = "CREATE TABLE t2 (foo INTEGER, bar INTEGER);";
cmd2.ExecuteNonQuery();

cmd2.CommandText = "show tables;";
PrintQueryResults(cmd2.ExecuteReader());


conn1.Dispose();
conn2.Dispose();
connection 1:
name 
t1 
connection 2:
name 
t1 
t2 

for comparison with the using the python API, I do get separate databases (as expected)

import duckdb

con1 = duckdb.connect(database=':memory:')   
con1.execute("CREATE TABLE items1(item VARCHAR, value DECIMAL(10,2), count INTEGER)")

con2 = duckdb.connect(database=':memory:')   
con2.execute("CREATE TABLE items2(item VARCHAR, value DECIMAL(10,2), count INTEGER)")


print('tables in con1: ')
con1.execute("show tables")
print(con1.fetchall())
print('tables in con2: ')
con2.execute("show tables")
print(con2.fetchall())

output:

tables in con1: 
[('items1',)]
tables in con2: 
[('items2',)]

Connection string failures and utilities

We should specify a connection string when creating a connection. We currently support connection strings that look like DataSource=<location> or Data Source=<location>. However, connection strings like DataSource = <location> are not valid because we do not allow spaces around the = mark. This does not seem to be a DuckDB requirement actually, for example Microsoft.Data.Sqlite allows such spaces (i.e. connection strings like "Data Source = :memory:".

So, requirement to have no spaces seems buggy to me. If no one minds, I can fix this.

Another connection string related must-have is a connection string builder. It simplifies connection string formatting because people usually do not remember the format they need to use. Again, if no one minds, I can implement this either.

Concurent connections problems

I am having problems with opening multiple connections at the same time. I get the DuckDB open failed error.
Works fine when I take care to open connections one by one.
I think the design whereby a database object is created for the life of the process, and each connection open call takes this database object as a parameter is a simpler design to get right.
It is more in line with the way DuckDb thinks under the hood, and is not contrary to anything in the ado.net spec.

Unhandled exception. System.EntryPointNotFoundException: Unable to find an entry point named 'duckdb_open_ext' in shared library 'duckdb'.

Hi,

When using the DuckDB.Net package on a Mac M1 I receive the following error on db.Open():
Unhandled exception. System.EntryPointNotFoundException: Unable to find an entry point named 'duckdb_open_ext' in shared library 'duckdb'.

I've included the duckdb executable in the project directory and set it to copy to output so it's included in the bin/debug folder.

Not implemented methods to get column data

We have some not implemented methods in DuckDBDataReader. We need to check whether DuckDb supports these data types and implement the methods for the supported type. Maybe we should throw something like NotSupportedException for the types DuckDB does not support.

Here are specific issues for the non-implemented types:

Possible memory leak?

Just looking at the documentation here: https://duckdb.org/docs/api/c/types
I noticed the following

Note that duckdb_value_varchar and duckdb_value_blob require the result to be de-allocated using duckdb_free.

Is this something we have to worry about in .net? I see for instance the following line of code in the data reader

        public override string GetString(int ordinal)
        {
            return PlatformIndependentBindings.NativeMethods.DuckDBValueVarchar(_queryResult, ordinal, _currentRow);
        }

DbProviderFactories.GetFactory fails

Hi!

I get the error below when I try to run:


Imports System.Data.Common

DbProviderFactories.GetFactory("DuckDB.NET.Data")

Error: System.Data.Entity.Core.ProviderIncompatibleException: 'A null was returned after calling the 'get_ProviderFactory' method on a store provider instance of type 'DuckDB.NET.Data.DuckDBConnection'. The store provider might not be functioning correctly.'

I'm trying to use the Entity Framework.

Thanks!
Ulisses.

Feature Request: Apache Arrow support

I'm very interested in Apache Arrow being supported for the in-memory scenario.

Is there any information you can provide on when that might be supported?

Thanks!

How to property the connection string as java

Properties ro_prop = new Properties();
ro_prop.setProperty("duckdb.read_only", "true");
Connection conn_ro = DriverManager.getConnection("jdbc:duckdb:/tmp/my_database", ro_prop);

As java, I can pass configuration to connection.How can I do the same thing with the lib.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.