diff --git a/glib/adbc-glib/database.c b/glib/adbc-glib/database.c index 886b3474bb..0c86443d07 100644 --- a/glib/adbc-glib/database.c +++ b/glib/adbc-glib/database.c @@ -75,6 +75,12 @@ GADBCDatabase* gadbc_database_new(GError** error) { AdbcStatusCode status_code = AdbcDatabaseNew(&(priv->adbc_database), &adbc_error); priv->initialized = gadbc_error_check(error, status_code, &adbc_error, "[adbc][database][new]"); + if (priv->initialized) { + status_code = AdbcDriverManagerDatabaseSetLoadFlags( + &(priv->adbc_database), GADBC_LOAD_FLAGS_DEFAULT, &adbc_error); + priv->initialized = gadbc_error_check(error, status_code, &adbc_error, + "[adbc][database][set-load-flags]"); + } if (!priv->initialized) { g_object_unref(database); return NULL; diff --git a/glib/adbc-glib/database.h b/glib/adbc-glib/database.h index 5f510b3463..1c04649874 100644 --- a/glib/adbc-glib/database.h +++ b/glib/adbc-glib/database.h @@ -48,7 +48,7 @@ typedef enum { } GADBCLoadFlags; /** - * GADBC_LOAD_FLAGAS_DEFAULT: + * GADBC_LOAD_FLAGS_DEFAULT: * * The default GADBCLoadFlags. * diff --git a/ruby/lib/adbc/database.rb b/ruby/lib/adbc/database.rb index 15e6abfbc5..60e715d550 100644 --- a/ruby/lib/adbc/database.rb +++ b/ruby/lib/adbc/database.rb @@ -18,13 +18,14 @@ module ADBC class Database class << self - def open(**options) + def open(load_flags: nil, **options) database = new need_release = true begin options.each do |key, value| database.set_option(key, value) end + database.set_load_flags(load_flags) unless load_flags.nil? database.init if block_given? yield(database) diff --git a/ruby/test/test-database.rb b/ruby/test/test-database.rb new file mode 100644 index 0000000000..19d9ad009f --- /dev/null +++ b/ruby/test/test-database.rb @@ -0,0 +1,63 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +class DatabaseTest < Test::Unit::TestCase + sub_test_case(".open") do + sub_test_case("manifest") do + def setup + Dir.mktmpdir do |tmpdir| + File.write(File.join(tmpdir, "testdriver.toml"), <<~TOML) + name = "test driver" + version = "0.1.0" + + [Driver] + shared = "adbc_driver_sqlite" + TOML + driver_path, ENV["ADBC_DRIVER_PATH"] = ENV["ADBC_DRIVER_PATH"], tmpdir + begin + yield + ensure + ENV["ADBC_DRIVER_PATH"] = driver_path + end + end + end + + def test_search_env_finds_driver + ADBC::Database.open(driver: "testdriver", + uri: ":memory:", + load_flags: :search_env) do |database| + database.connect do |connection| + assert_equal([ + Arrow::Table.new("1" => Arrow::Int64Array.new([1])), + -1, + ], + connection.query("SELECT 1")) + end + end + end + + def test_no_flags_cannot_find_driver + assert_raise(ADBC::Error::NotFound) do + ADBC::Database.open(driver: "testdriver", + uri: ":memory:", + load_flags: 0) do |_database| + end + end + end + end + end +end