From 11b20f5f303434cd7a304e0805f9ead99ec80311 Mon Sep 17 00:00:00 2001 From: Daniel Espinosa Date: Mon, 2 Oct 2023 19:31:59 -0600 Subject: [PATCH 1/8] feat(glib): add Vala VAPI for GADBC Vala VAPI file is generated for current GADBC 1.0 API version. It is disable by default, but recommended to be enable when a development package is distributed. This commit force a 1.0 API versioning, replacing the old one where 0 were used for GIR API version (gir_version), so now shows '1.0' instead of '0.0'. Also examples are provided for C and Vala. --- glib/adbc-glib/meson.build | 6 ++ glib/example/README.md | 32 ++++++++ glib/example/meson.build | 29 +++++++ glib/example/sqlite.c | 147 ++++++++++++++++++++++++++++++++++ glib/example/vala/README.md | 36 +++++++++ glib/example/vala/meson.build | 43 ++++++++++ glib/example/vala/sqlite.vala | 59 ++++++++++++++ glib/meson.build | 11 ++- glib/meson_options.txt | 5 ++ 9 files changed, 367 insertions(+), 1 deletion(-) create mode 100644 glib/example/README.md create mode 100644 glib/example/meson.build create mode 100644 glib/example/sqlite.c create mode 100644 glib/example/vala/README.md create mode 100644 glib/example/vala/meson.build create mode 100644 glib/example/vala/sqlite.vala diff --git a/glib/adbc-glib/meson.build b/glib/adbc-glib/meson.build index 1fe245e51b..87ce64fa51 100644 --- a/glib/adbc-glib/meson.build +++ b/glib/adbc-glib/meson.build @@ -102,3 +102,9 @@ adbc_glib_gir = gnome.generate_gir(libadbc_glib, nsversion: api_version, sources: sources + definition_headers + enums, symbol_prefix: 'gadbc') +if generate_vapi + adbc_glib_vapi = gnome.generate_vapi('adbc-glib', + install: true, + packages: ['gobject-2.0', 'arrow-glib'], + sources: [adbc_glib_gir[0]]) +endif diff --git a/glib/example/README.md b/glib/example/README.md new file mode 100644 index 0000000000..070db256e6 --- /dev/null +++ b/glib/example/README.md @@ -0,0 +1,32 @@ + + +# ADBC GLib example + +There are example codes in this directory. + +C example codes exist in this directory. Language bindings example +codes exists in sub directories. For example, Vala example codes exists +in `vala/` sub directory. + +## C example codes + +Here are example codes in this directory: + + * `sqlite.c`: It shows how to connect to a database using SQLite. diff --git a/glib/example/meson.build b/glib/example/meson.build new file mode 100644 index 0000000000..76a07079c3 --- /dev/null +++ b/glib/example/meson.build @@ -0,0 +1,29 @@ +# -*- indent-tabs-mode: nil -*- +# +# 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. + +arrow_glib = dependency('arrow-glib') + +executable('sqlite', 'sqlite.c', + dependencies: [adbc_glib, arrow_glib], + link_language: 'c') + +install_data('README.md', + install_dir: join_paths(data_dir, meson.project_name(), 'example')) + +subdir('vala') diff --git a/glib/example/sqlite.c b/glib/example/sqlite.c new file mode 100644 index 0000000000..2f285c6179 --- /dev/null +++ b/glib/example/sqlite.c @@ -0,0 +1,147 @@ +/* + * 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. + */ + +#include + +#include +#include + +int main(int argc, char** argv) { + GADBCDatabase* database; + GADBCConnection* conn; + GError* error = NULL; + database = gadbc_database_new(&error); + if (!database) { + g_print("Error creating a Database: %s", error->message); + g_error_free(error); + g_object_unref(database); + return EXIT_FAILURE; + } + + if (!gadbc_database_set_option(database, "driver", "adbc_driver_sqlite", &error)) { + g_print("Error initializing the database: %s", error->message); + g_error_free(error); + g_object_unref(database); + return EXIT_FAILURE; + } + if (!gadbc_database_set_option(database, "uri", "test.db", &error)) { + g_print("Error initializing the database: %s", error->message); + g_error_free(error); + g_object_unref(database); + return EXIT_FAILURE; + } + if (!gadbc_database_init(database, &error)) { + g_print("Error initializing the database: %s", error->message); + g_error_free(error); + g_object_unref(database); + return EXIT_FAILURE; + } + + conn = gadbc_connection_new(&error); + if (!conn) { + g_print("Error creating a Connection: %s", error->message); + g_error_free(error); + g_object_unref(database); + g_object_unref(conn); + return EXIT_FAILURE; + } + if (!gadbc_connection_init(conn, database, &error)) { + g_print("Error initializing a Connection: %s", error->message); + g_error_free(error); + g_object_unref(database); + g_object_unref(conn); + return EXIT_FAILURE; + } + + GADBCStatement* statement = gadbc_statement_new(conn, &error); + if (!statement) { + g_print("Error initializing a statement: %s", error->message); + g_error_free(error); + g_object_unref(conn); + g_object_unref(database); + return EXIT_FAILURE; + } + if (!gadbc_statement_set_sql_query(statement, "select sqlite_version() as version", + &error)) { + g_print("Error setting a query: %s", error->message); + g_error_free(error); + g_object_unref(statement); + g_object_unref(conn); + g_object_unref(database); + return EXIT_FAILURE; + } + + gpointer c_abi_array_stream; + gint64 n_rows_affected; + if (!gadbc_statement_execute(statement, TRUE, &c_abi_array_stream, &n_rows_affected, + &error)) { + g_print("Error executing a query: %s", error->message); + g_error_free(error); + g_object_unref(statement); + g_object_unref(conn); + g_object_unref(database); + return EXIT_FAILURE; + } + + GArrowRecordBatchReader* reader = + garrow_record_batch_reader_import(c_abi_array_stream, &error); + g_free(c_abi_array_stream); + if (!reader) { + g_print("Error importing a result: %s", error->message); + g_error_free(error); + g_object_unref(statement); + g_object_unref(conn); + g_object_unref(database); + return EXIT_FAILURE; + } + + GArrowTable* table = garrow_record_batch_reader_read_all(reader, &error); + g_object_unref(reader); + if (!table) { + g_print("Error reading a result: %s", error->message); + g_error_free(error); + g_object_unref(statement); + g_object_unref(conn); + g_object_unref(database); + return EXIT_FAILURE; + } + gchar* table_content = garrow_table_to_string(table, &error); + g_object_unref(table); + if (!table_content) { + g_print("Error stringify a result: %s", error->message); + g_error_free(error); + g_object_unref(statement); + g_object_unref(conn); + g_object_unref(database); + return EXIT_FAILURE; + } + g_print("Result:\n%s\n", table_content); + g_free(table_content); + gadbc_statement_release(statement, &error); + if (error) { + g_print("Error releasing a statement: %s", error->message); + g_error_free(error); + error = NULL; + } + g_object_unref(statement); + g_object_unref(conn); + g_object_unref(database); + + return EXIT_SUCCESS; +} diff --git a/glib/example/vala/README.md b/glib/example/vala/README.md new file mode 100644 index 0000000000..19900ae1a9 --- /dev/null +++ b/glib/example/vala/README.md @@ -0,0 +1,36 @@ + + +# ADBC GLib Vala example + +There are Vala example codes in this directory. + +## How to build + +Here is a command line to build an example in this directory: + +```console +$ valac --pkg adbc-glib --pkg posix XXX.vala +``` + +## GLib Vala example codes + +Here are example codes in this directory: + + * `sqlite.vala`: It shows how to connect to a SQLite database. diff --git a/glib/example/vala/meson.build b/glib/example/vala/meson.build new file mode 100644 index 0000000000..1fa8413bb7 --- /dev/null +++ b/glib/example/vala/meson.build @@ -0,0 +1,43 @@ +# -*- indent-tabs-mode: nil -*- +# +# 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. + +if generate_vapi + vala_example_executable_kwargs = { + 'c_args': [ + '-I' + meson.build_root(), + '-I' + meson.source_root(), + ], + 'dependencies': [ + adbc_glib_vapi, + arrow_glib, + dependency('gobject-2.0'), + ], + 'vala_args': [ + '--pkg', 'posix', + ], + } + executable('sqlite', 'sqlite.vala', + kwargs: vala_example_executable_kwargs) +endif + +install_data('README.md', + install_dir: join_paths(data_dir, + meson.project_name(), + 'example', + 'vala')) diff --git a/glib/example/vala/sqlite.vala b/glib/example/vala/sqlite.vala new file mode 100644 index 0000000000..37037e47a0 --- /dev/null +++ b/glib/example/vala/sqlite.vala @@ -0,0 +1,59 @@ +// 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. + + +int main (string[] args) { + try { + var database = new GADBC.Database (); + database.set_option ("driver", "adbc_driver_sqlite"); + database.set_option ("uri", "test.sqlite"); + database.init (); + GLib.message ("Database initialization done..."); + try { + var conn = new GADBC.Connection (); + conn.init (database); + GLib.message ("Connection to database initialized..."); + try { + var stm = new GADBC.Statement (conn); + string sql = "SELECT sqlite_version() AS version"; + stm.set_sql_query (sql); + void *c_abi_array_stream = null; + stm.execute (true, out c_abi_array_stream, null); + try { + GLib.message ("Statement executed: %s", sql); + var reader = GArrow.RecordBatchReader.import (c_abi_array_stream); + var table = reader.read_all (); + GLib.message ("Executed result: %s", table.to_string ()); + } finally { + GLib.free (c_abi_array_stream); + } + GLib.message ("Statement executed: %s", sql); + } + catch (GLib.Error e) { + GLib.message ("Error executing statement: %s", e.message); + } + } + catch (GLib.Error e) { + GLib.message ("Error initializing the connection: %s", e.message); + } + } + catch (GLib.Error e) { + GLib.message ("Error initializing the database: %s", e.message); + } + + return Posix.EXIT_SUCCESS; +} diff --git a/glib/meson.build b/glib/meson.build index 03dccc2e53..b4752f794f 100644 --- a/glib/meson.build +++ b/glib/meson.build @@ -30,7 +30,7 @@ version_major = version_numbers[0].to_int() version_minor = version_numbers[1].to_int() version_micro = version_numbers[2].to_int() -api_version = '@0@.0'.format(version_major) +api_version = '1.0' so_version = version_major library_version = '.'.join(version_numbers) @@ -39,6 +39,7 @@ include_dir = get_option('includedir') project_include_sub_dir = meson.project_name() data_dir = get_option('datadir') gir_dir = prefix / data_dir / 'gir-1.0' +vapi_dir = data_dir / 'vala' / 'vapi' gnome = import('gnome') pkgconfig = import('pkgconfig') @@ -67,7 +68,15 @@ else dirs: [adbc_build_dir]) endif +dependency('gobject-introspection-1.0', required: false).found() +generate_vapi = get_option('vapi') +if generate_vapi + pkgconfig_variables += ['vapidir=@0@'.format(vapi_dir)] + add_languages('vala') +endif + subdir('adbc-glib') +subdir('example') install_data('../LICENSE.txt', 'README.md', diff --git a/glib/meson_options.txt b/glib/meson_options.txt index 0ae1e6c341..ee0ae9497f 100644 --- a/glib/meson_options.txt +++ b/glib/meson_options.txt @@ -21,3 +21,8 @@ option('adbc_build_dir', type: 'string', value: '', description: 'Use this option to build with not installed ADBC') + +option('vapi', + type: 'boolean', + value: false, + description: 'Build Vala API') From 94ad68fc898792a909da54f2e403c2648c6c9999 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Tue, 14 Nov 2023 08:37:23 +0900 Subject: [PATCH 2/8] Clean up * Enable Vala-Lint * Use gadbc-1.0 for Vala package name * Require Apache Arrow GLib only when -Dexample=true or -Dvapi=true * Simplify examples --- .pre-commit-config.yaml | 6 ++ glib/adbc-glib/meson.build | 8 +- glib/example/README.md | 7 +- glib/example/meson.build | 11 +-- glib/example/sqlite.c | 138 ++++++++++++++++------------------ glib/example/vala/README.md | 4 +- glib/example/vala/meson.build | 3 +- glib/example/vala/sqlite.vala | 71 ++++++++--------- glib/meson.build | 2 + glib/meson_options.txt | 5 ++ 10 files changed, 131 insertions(+), 124 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9b96d95562..01e624caa0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -87,6 +87,12 @@ repos: hooks: - id: isort types_or: [python] + # TODO: Change this to vala-lang/vala-lint after + # https://github.com/vala-lang/vala-lint/pull/179 is merged. + - repo: https://github.com/kou/vala-lint + rev: pre-commit-hook + hooks: + - id: vala-lint - repo: local hooks: - id: apache-rat diff --git a/glib/adbc-glib/meson.build b/glib/adbc-glib/meson.build index 87ce64fa51..7b76d9e0e7 100644 --- a/glib/adbc-glib/meson.build +++ b/glib/adbc-glib/meson.build @@ -103,8 +103,8 @@ adbc_glib_gir = gnome.generate_gir(libadbc_glib, sources: sources + definition_headers + enums, symbol_prefix: 'gadbc') if generate_vapi - adbc_glib_vapi = gnome.generate_vapi('adbc-glib', - install: true, - packages: ['gobject-2.0', 'arrow-glib'], - sources: [adbc_glib_gir[0]]) + adbc_glib_vapi = gnome.generate_vapi('gadbc-1.0', + install: true, + packages: ['gobject-2.0'], + sources: [adbc_glib_gir[0]]) endif diff --git a/glib/example/README.md b/glib/example/README.md index 070db256e6..feb18efea5 100644 --- a/glib/example/README.md +++ b/glib/example/README.md @@ -22,11 +22,12 @@ There are example codes in this directory. C example codes exist in this directory. Language bindings example -codes exists in sub directories. For example, Vala example codes exists -in `vala/` sub directory. +codes exists in sub directories: + + * `vala/`: Vala examples ## C example codes Here are example codes in this directory: - * `sqlite.c`: It shows how to connect to a database using SQLite. + * `sqlite.c`: It shows how to connect to a SQLite database. diff --git a/glib/example/meson.build b/glib/example/meson.build index 76a07079c3..6ba16b0819 100644 --- a/glib/example/meson.build +++ b/glib/example/meson.build @@ -17,11 +17,12 @@ # specific language governing permissions and limitations # under the License. -arrow_glib = dependency('arrow-glib') - -executable('sqlite', 'sqlite.c', - dependencies: [adbc_glib, arrow_glib], - link_language: 'c') +if build_example + arrow_glib = dependency('arrow-glib') + executable('sqlite', 'sqlite.c', + dependencies: [adbc_glib, arrow_glib], + link_language: 'c') +endif install_data('README.md', install_dir: join_paths(data_dir, meson.project_name(), 'example')) diff --git a/glib/example/sqlite.c b/glib/example/sqlite.c index 2f285c6179..f0a9f39857 100644 --- a/glib/example/sqlite.c +++ b/glib/example/sqlite.c @@ -23,125 +23,113 @@ #include int main(int argc, char** argv) { - GADBCDatabase* database; - GADBCConnection* conn; + int result = EXIT_FAILURE; + GADBCDatabase* database = NULL; + GADBCConnection* connection = NULL; + GADBCStatement* statement = NULL; GError* error = NULL; + database = gadbc_database_new(&error); if (!database) { - g_print("Error creating a Database: %s", error->message); - g_error_free(error); - g_object_unref(database); - return EXIT_FAILURE; + g_print("Failed to create a database: %s", error->message); + goto exit; } if (!gadbc_database_set_option(database, "driver", "adbc_driver_sqlite", &error)) { - g_print("Error initializing the database: %s", error->message); - g_error_free(error); - g_object_unref(database); - return EXIT_FAILURE; + g_print("Failed to set driver: %s", error->message); + goto exit; } - if (!gadbc_database_set_option(database, "uri", "test.db", &error)) { - g_print("Error initializing the database: %s", error->message); - g_error_free(error); - g_object_unref(database); - return EXIT_FAILURE; + if (!gadbc_database_set_option(database, "uri", ":memory:", &error)) { + g_print("Failed to set database URI: %s", error->message); + goto exit; } if (!gadbc_database_init(database, &error)) { - g_print("Error initializing the database: %s", error->message); - g_error_free(error); - g_object_unref(database); - return EXIT_FAILURE; + g_print("Failed to initialize a database: %s", error->message); + goto exit; } - conn = gadbc_connection_new(&error); - if (!conn) { - g_print("Error creating a Connection: %s", error->message); - g_error_free(error); - g_object_unref(database); - g_object_unref(conn); - return EXIT_FAILURE; + connection = gadbc_connection_new(&error); + if (!connection) { + g_print("Failed to create a connection: %s", error->message); + goto exit; } - if (!gadbc_connection_init(conn, database, &error)) { - g_print("Error initializing a Connection: %s", error->message); - g_error_free(error); - g_object_unref(database); - g_object_unref(conn); - return EXIT_FAILURE; + if (!gadbc_connection_init(connection, database, &error)) { + g_print("Failed to initialize a connection: %s", error->message); + goto exit; } - GADBCStatement* statement = gadbc_statement_new(conn, &error); + statement = gadbc_statement_new(connection, &error); if (!statement) { - g_print("Error initializing a statement: %s", error->message); - g_error_free(error); - g_object_unref(conn); - g_object_unref(database); - return EXIT_FAILURE; + g_print("Failed to create a statement: %s", error->message); + goto exit; } if (!gadbc_statement_set_sql_query(statement, "select sqlite_version() as version", &error)) { - g_print("Error setting a query: %s", error->message); - g_error_free(error); - g_object_unref(statement); - g_object_unref(conn); - g_object_unref(database); - return EXIT_FAILURE; + g_print("Failed to set a query: %s", error->message); + goto exit; } gpointer c_abi_array_stream; gint64 n_rows_affected; if (!gadbc_statement_execute(statement, TRUE, &c_abi_array_stream, &n_rows_affected, &error)) { - g_print("Error executing a query: %s", error->message); - g_error_free(error); - g_object_unref(statement); - g_object_unref(conn); - g_object_unref(database); - return EXIT_FAILURE; + g_print("Failed to execute a query: %s", error->message); + goto exit; } GArrowRecordBatchReader* reader = garrow_record_batch_reader_import(c_abi_array_stream, &error); g_free(c_abi_array_stream); if (!reader) { - g_print("Error importing a result: %s", error->message); - g_error_free(error); - g_object_unref(statement); - g_object_unref(conn); - g_object_unref(database); - return EXIT_FAILURE; + g_print("Failed to import a result: %s", error->message); + goto exit; } GArrowTable* table = garrow_record_batch_reader_read_all(reader, &error); g_object_unref(reader); if (!table) { - g_print("Error reading a result: %s", error->message); - g_error_free(error); - g_object_unref(statement); - g_object_unref(conn); - g_object_unref(database); - return EXIT_FAILURE; + g_print("Failed to read a result: %s", error->message); + goto exit; } gchar* table_content = garrow_table_to_string(table, &error); g_object_unref(table); if (!table_content) { - g_print("Error stringify a result: %s", error->message); - g_error_free(error); - g_object_unref(statement); - g_object_unref(conn); - g_object_unref(database); - return EXIT_FAILURE; + g_print("Failed to stringify a result: %s", error->message); + goto exit; } g_print("Result:\n%s\n", table_content); g_free(table_content); - gadbc_statement_release(statement, &error); + + result = EXIT_SUCCESS; + +exit: if (error) { - g_print("Error releasing a statement: %s", error->message); g_error_free(error); error = NULL; } - g_object_unref(statement); - g_object_unref(conn); - g_object_unref(database); - - return EXIT_SUCCESS; + if (statement) { + if (!gadbc_statement_release(statement, &error)) { + g_print("Failed to release a statement: %s", error->message); + g_error_free(error); + error = NULL; + } + g_object_unref(statement); + } + if (connection) { + if (!gadbc_connection_release(connection, &error)) { + g_print("Failed to release a connection: %s", error->message); + g_error_free(error); + error = NULL; + } + g_object_unref(connection); + } + if (database) { + if (!gadbc_database_release(database, &error)) { + g_print("Failed to release a database: %s", error->message); + g_error_free(error); + error = NULL; + } + g_object_unref(database); + } + return result; } diff --git a/glib/example/vala/README.md b/glib/example/vala/README.md index 19900ae1a9..b28dfdaeb4 100644 --- a/glib/example/vala/README.md +++ b/glib/example/vala/README.md @@ -26,10 +26,10 @@ There are Vala example codes in this directory. Here is a command line to build an example in this directory: ```console -$ valac --pkg adbc-glib --pkg posix XXX.vala +$ valac --pkg adbc-glib --pkg arrow-glib --pkg posix XXX.vala ``` -## GLib Vala example codes +## Vala example codes Here are example codes in this directory: diff --git a/glib/example/vala/meson.build b/glib/example/vala/meson.build index 1fa8413bb7..5f51b5380b 100644 --- a/glib/example/vala/meson.build +++ b/glib/example/vala/meson.build @@ -17,7 +17,7 @@ # specific language governing permissions and limitations # under the License. -if generate_vapi +if build_example and generate_vapi vala_example_executable_kwargs = { 'c_args': [ '-I' + meson.build_root(), @@ -30,6 +30,7 @@ if generate_vapi ], 'vala_args': [ '--pkg', 'posix', + '--vapidir', arrow_glib.get_variable('vapidir'), ], } executable('sqlite', 'sqlite.vala', diff --git a/glib/example/vala/sqlite.vala b/glib/example/vala/sqlite.vala index 37037e47a0..76183539dc 100644 --- a/glib/example/vala/sqlite.vala +++ b/glib/example/vala/sqlite.vala @@ -15,45 +15,48 @@ // specific language governing permissions and limitations // under the License. - int main (string[] args) { - try { - var database = new GADBC.Database (); - database.set_option ("driver", "adbc_driver_sqlite"); - database.set_option ("uri", "test.sqlite"); - database.init (); - GLib.message ("Database initialization done..."); + var exit_code = Posix.EXIT_FAILURE; + try { - var conn = new GADBC.Connection (); - conn.init (database); - GLib.message ("Connection to database initialized..."); - try { - var stm = new GADBC.Statement (conn); - string sql = "SELECT sqlite_version() AS version"; - stm.set_sql_query (sql); - void *c_abi_array_stream = null; - stm.execute (true, out c_abi_array_stream, null); + var database = new GADBC.Database (); + database.set_option ("driver", "adbc_driver_sqlite"); + database.set_option ("uri", ":memory:"); + database.init (); try { - GLib.message ("Statement executed: %s", sql); - var reader = GArrow.RecordBatchReader.import (c_abi_array_stream); - var table = reader.read_all (); - GLib.message ("Executed result: %s", table.to_string ()); - } finally { - GLib.free (c_abi_array_stream); + var connection = new GADBC.Connection (); + connection.init (database); + try { + var statement = new GADBC.Statement (connection); + string sql = "SELECT sqlite_version() AS version"; + statement.set_sql_query (sql); + try { + void *c_abi_array_stream = null; + int64 n_rows_affected; + statement.execute (true, out c_abi_array_stream, out n_rows_affected); + try { + var reader = GArrow.RecordBatchReader.import (c_abi_array_stream); + var table = reader.read_all (); + stdout.printf ("Result:\n%s", table.to_string ()); + } finally { + GLib.free (c_abi_array_stream); + } + exit_code = Posix.EXIT_SUCCESS; + } catch (GLib.Error error) { + GLib.error ("Failed to execute a statement: %s", error.message); + } + } + catch (GLib.Error error) { + GLib.error ("Failed to create a statement: %s", error.message); + } + } + catch (GLib.Error error) { + GLib.error ("Failed to create a connection: %s", error.message); } - GLib.message ("Statement executed: %s", sql); - } - catch (GLib.Error e) { - GLib.message ("Error executing statement: %s", e.message); - } } - catch (GLib.Error e) { - GLib.message ("Error initializing the connection: %s", e.message); + catch (GLib.Error error) { + GLib.error ("Failed to create a database: %s", error.message); } - } - catch (GLib.Error e) { - GLib.message ("Error initializing the database: %s", e.message); - } - return Posix.EXIT_SUCCESS; + return exit_code; } diff --git a/glib/meson.build b/glib/meson.build index b4752f794f..0deee035db 100644 --- a/glib/meson.build +++ b/glib/meson.build @@ -68,6 +68,8 @@ else dirs: [adbc_build_dir]) endif +build_example = get_option('example') + dependency('gobject-introspection-1.0', required: false).found() generate_vapi = get_option('vapi') if generate_vapi diff --git a/glib/meson_options.txt b/glib/meson_options.txt index ee0ae9497f..8603b78321 100644 --- a/glib/meson_options.txt +++ b/glib/meson_options.txt @@ -22,6 +22,11 @@ option('adbc_build_dir', value: '', description: 'Use this option to build with not installed ADBC') +option('example', + type: 'boolean', + value: false, + description: 'Build example') + option('vapi', type: 'boolean', value: false, From 70e84334bc5fa94f5728cfa535be22ad68eeda63 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Tue, 14 Nov 2023 08:59:10 +0900 Subject: [PATCH 3/8] Update packages --- ci/linux-packages/debian/control | 3 +- .../debian/libadbc-glib-dev.install | 2 ++ ci/linux-packages/debian/rules | 30 ++++++++++--------- ci/linux-packages/yum/almalinux-8/Dockerfile | 3 +- ci/linux-packages/yum/almalinux-9/Dockerfile | 3 +- .../yum/apache-arrow-adbc.spec.in | 16 ++++++---- ci/scripts/glib_build.sh | 12 ++++++++ glib/example/meson.build | 6 +++- glib/example/vala/meson.build | 6 +++- 9 files changed, 55 insertions(+), 26 deletions(-) diff --git a/ci/linux-packages/debian/control b/ci/linux-packages/debian/control index b88fa12f31..cc5441e7ba 100644 --- a/ci/linux-packages/debian/control +++ b/ci/linux-packages/debian/control @@ -180,8 +180,7 @@ Multi-Arch: same Depends: ${misc:Depends}, gir1.2-adbc-1.0 (= ${binary:Version}), - libadbc-driver-manager-dev (= ${binary:Version}), - libarrow-glib-dev + libadbc-driver-manager-dev (= ${binary:Version}) Description: Apache Arrow Database Connectivity (ADBC) driver manager . This package provides GLib based header files. diff --git a/ci/linux-packages/debian/libadbc-glib-dev.install b/ci/linux-packages/debian/libadbc-glib-dev.install index d8b552a630..7e5f0d8dcc 100644 --- a/ci/linux-packages/debian/libadbc-glib-dev.install +++ b/ci/linux-packages/debian/libadbc-glib-dev.install @@ -1,4 +1,6 @@ usr/include/adbc-glib/ usr/lib/*/libadbc-glib.so usr/lib/*/pkgconfig/adbc-glib.pc +usr/share/adbc-glib/example/ usr/share/gir-1.0/ADBC-*.gir +usr/share/vala/vapi/* diff --git a/ci/linux-packages/debian/rules b/ci/linux-packages/debian/rules index b56d1a8a10..a121d77d9b 100755 --- a/ci/linux-packages/debian/rules +++ b/ci/linux-packages/debian/rules @@ -1,3 +1,4 @@ + #!/usr/bin/make -f # -*- makefile-gmake -*- # @@ -31,23 +32,23 @@ export DEB_BUILD_MAINT_OPTIONS=reproducible=-timeless CMAKE_BUILD_TYPE = RelWithDebInfo override_dh_auto_configure: - env \ + env \ PATH=/usr/lib/go-1.20/bin:$${PATH} \ dh_auto_configure \ - --sourcedirectory=c/ \ - --builddirectory=c.build \ + --sourcedirectory=c/ \ + --builddirectory=c.build \ --buildsystem=cmake+ninja \ -- \ - -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \ - -DADBC_DRIVER_MANAGER=ON \ - -DADBC_DRIVER_POSTGRESQL=ON \ - -DADBC_DRIVER_SQLITE=ON \ - -DADBC_DRIVER_FLIGHTSQL=ON \ - -DADBC_DRIVER_SNOWFLAKE=ON + -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \ + -DADBC_DRIVER_FLIGHTSQL=ON \ + -DADBC_DRIVER_MANAGER=ON \ + -DADBC_DRIVER_POSTGRESQL=ON \ + -DADBC_DRIVER_SNOWFLAKE=ON \ + -DADBC_DRIVER_SQLITE=ON override_dh_auto_build: - dh_auto_build \ - --sourcedirectory=c \ + dh_auto_build \ + --sourcedirectory=c \ --builddirectory=c.build dh_auto_configure \ --sourcedirectory=glib \ @@ -55,7 +56,8 @@ override_dh_auto_build: --buildsystem=meson+ninja \ -- \ --buildtype=debugoptimized \ - -Dadbc_build_dir=../c.build/driver_manager + -Dadbc_build_dir=../c.build/driver_manager \ + -Dvapi=true env \ LD_LIBRARY_PATH=$(CURDIR)/c.build/driver_manager \ dh_auto_build \ @@ -64,8 +66,8 @@ override_dh_auto_build: --buildsystem=meson+ninja override_dh_auto_install: - dh_auto_install \ - --sourcedirectory=c \ + dh_auto_install \ + --sourcedirectory=c \ --builddirectory=c.build dh_auto_install \ --sourcedirectory=glib \ diff --git a/ci/linux-packages/yum/almalinux-8/Dockerfile b/ci/linux-packages/yum/almalinux-8/Dockerfile index e33721410f..dfd10dd449 100644 --- a/ci/linux-packages/yum/almalinux-8/Dockerfile +++ b/ci/linux-packages/yum/almalinux-8/Dockerfile @@ -38,5 +38,6 @@ RUN \ python3-pip \ rpmdevtools \ sqlite-devel \ - tar && \ + tar \ + vala && \ yum clean ${quiet} all diff --git a/ci/linux-packages/yum/almalinux-9/Dockerfile b/ci/linux-packages/yum/almalinux-9/Dockerfile index f32f563adf..213590e88a 100644 --- a/ci/linux-packages/yum/almalinux-9/Dockerfile +++ b/ci/linux-packages/yum/almalinux-9/Dockerfile @@ -38,5 +38,6 @@ RUN \ python3-pip \ rpmdevtools \ sqlite-devel \ - tar && \ + tar \ + vala && \ dnf clean ${quiet} all diff --git a/ci/linux-packages/yum/apache-arrow-adbc.spec.in b/ci/linux-packages/yum/apache-arrow-adbc.spec.in index 4aa9ee3c12..7a50a1fe2e 100644 --- a/ci/linux-packages/yum/apache-arrow-adbc.spec.in +++ b/ci/linux-packages/yum/apache-arrow-adbc.spec.in @@ -48,6 +48,7 @@ BuildRequires: libpq-devel BuildRequires: ninja-build BuildRequires: pkgconfig BuildRequires: sqlite-devel +BuildRequires: vala %description Apache Arrow Database Connectivity (ADBC) is an Apache Arrow based database access API @@ -63,11 +64,11 @@ cd c %adbc_cmake \ -DCMAKE_BUILD_TYPE=${cmake_build_type} \ -G"Unix Makefiles" \ + -DADBC_DRIVER_FLIGHTSQL=ON \ -DADBC_DRIVER_MANAGER=ON \ -DADBC_DRIVER_POSTGRESQL=ON \ - -DADBC_DRIVER_SQLITE=ON \ - -DADBC_DRIVER_FLIGHTSQL=ON \ - -DADBC_DRIVER_SNOWFLAKE=ON + -DADBC_DRIVER_SNOWFLAKE=ON \ + -DADBC_DRIVER_SQLITE=ON %adbc_cmake_build cd - @@ -78,7 +79,8 @@ meson setup build \ --default-library=both \ --libdir=%{_libdir} \ --prefix=%{_prefix} \ - -Dadbc_build_dir=$PWD/../c/%{adbc_cmake_builddir}/driver_manager + -Dadbc_build_dir=$PWD/../c/%{adbc_cmake_builddir}/driver_manager \ + -Dvapi=true LD_LIBRARY_PATH=$PWD/../c/%{adbc_cmake_builddir}/driver_manager \ meson compile -C build %{?_smp_mflags} @@ -258,7 +260,7 @@ This package contains the libraries for ADBC GLib. %defattr(-,root,root,-) %doc README.md %license LICENSE.txt NOTICE.txt -%{_libdir}/girepository-1.0/ADBC-*.typelib +%{_libdir}/girepository-1.0/ %{_libdir}/libadbc-glib.so.* %package glib-devel @@ -276,7 +278,8 @@ Libraries and header files for ADBC GLib. %defattr(-,root,root,-) %doc README.md %license LICENSE.txt NOTICE.txt -%{_datadir}/gir-1.0/ADBC-*.gir +%{_datadir}/gir-1.0/ +%{_datadir}/vala/vapi/ %{_includedir}/adbc-glib/ %{_libdir}/libadbc-glib.a %{_libdir}/libadbc-glib.so @@ -293,6 +296,7 @@ Documentation for ADBC GLib. %defattr(-,root,root,-) %doc README.md %license LICENSE.txt NOTICE.txt +%{_datadir}/adbc-glib/example/ %{_docdir}/adbc-glib/ %changelog diff --git a/ci/scripts/glib_build.sh b/ci/scripts/glib_build.sh index b5cadbd720..68f9124d7c 100755 --- a/ci/scripts/glib_build.sh +++ b/ci/scripts/glib_build.sh @@ -38,6 +38,11 @@ build_subproject() { cmake_prefix_path="${CONDA_PREFIX}:${cmake_prefix_path}" pkg_config_path="${pkg_config_path}:${CONDA_PREFIX}/lib/pkgconfig" fi + if type valac > /dev/null 2>&1; then + enable_vapi=true + else + enable_vapi=false + fi meson setup \ --buildtype=debug \ @@ -45,8 +50,15 @@ build_subproject() { --libdir=lib \ --pkg-config-path="${pkg_config_path}" \ --prefix="${install_dir}" \ + -Dexample=true \ + -Dvapi="${enable_vapi}" \ "${build_dir}/glib" \ "${source_dir}/glib" + "${build_dir}/glib/example/sqlite" + if [[ "${enable_vapi}" = "true" ]]; then + "${build_dir}/glib/example/vala/sqlite" + fi + "${build_dir}/build/sqlite" meson install -C "${build_dir}/glib" } diff --git a/glib/example/meson.build b/glib/example/meson.build index 6ba16b0819..ed34fd0285 100644 --- a/glib/example/meson.build +++ b/glib/example/meson.build @@ -24,7 +24,11 @@ if build_example link_language: 'c') endif -install_data('README.md', +files = [ + 'README.md', + 'sqlite.c', +] +install_data(files, install_dir: join_paths(data_dir, meson.project_name(), 'example')) subdir('vala') diff --git a/glib/example/vala/meson.build b/glib/example/vala/meson.build index 5f51b5380b..3486a8c9e9 100644 --- a/glib/example/vala/meson.build +++ b/glib/example/vala/meson.build @@ -37,7 +37,11 @@ if build_example and generate_vapi kwargs: vala_example_executable_kwargs) endif -install_data('README.md', +files = [ + 'README.md', + 'sqlite.vala', +] +install_data(files, install_dir: join_paths(data_dir, meson.project_name(), 'example', From 53f7cb600146c0b57e03f7ab59d94d75286f3a38 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Tue, 14 Nov 2023 09:07:12 +0900 Subject: [PATCH 4/8] Remove garbage --- ci/linux-packages/debian/rules | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/linux-packages/debian/rules b/ci/linux-packages/debian/rules index a121d77d9b..2a766d5d4b 100755 --- a/ci/linux-packages/debian/rules +++ b/ci/linux-packages/debian/rules @@ -1,4 +1,3 @@ - #!/usr/bin/make -f # -*- makefile-gmake -*- # From 8779d929e8c0e062248849cf7430b3eeb64d7ab1 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Tue, 14 Nov 2023 09:07:50 +0900 Subject: [PATCH 5/8] Fix order --- ci/scripts/glib_build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/scripts/glib_build.sh b/ci/scripts/glib_build.sh index 68f9124d7c..0e4dc0fae1 100755 --- a/ci/scripts/glib_build.sh +++ b/ci/scripts/glib_build.sh @@ -54,12 +54,12 @@ build_subproject() { -Dvapi="${enable_vapi}" \ "${build_dir}/glib" \ "${source_dir}/glib" + meson install -C "${build_dir}/glib" "${build_dir}/glib/example/sqlite" if [[ "${enable_vapi}" = "true" ]]; then "${build_dir}/glib/example/vala/sqlite" fi "${build_dir}/build/sqlite" - meson install -C "${build_dir}/glib" } main() { From 39bc6cff452868faa16c540941990d47936f5686 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Tue, 14 Nov 2023 09:28:46 +0900 Subject: [PATCH 6/8] Remove garbage --- ci/scripts/glib_build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/scripts/glib_build.sh b/ci/scripts/glib_build.sh index 0e4dc0fae1..6edd7faf5a 100755 --- a/ci/scripts/glib_build.sh +++ b/ci/scripts/glib_build.sh @@ -59,7 +59,6 @@ build_subproject() { if [[ "${enable_vapi}" = "true" ]]; then "${build_dir}/glib/example/vala/sqlite" fi - "${build_dir}/build/sqlite" } main() { From 2f80efa6acf4edd3c6392af779d82bd01403e2ce Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Tue, 14 Nov 2023 10:15:18 +0900 Subject: [PATCH 7/8] Install libc6-dev --- dev/release/verify-apt.sh | 1 + glib/adbc-glib/error.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dev/release/verify-apt.sh b/dev/release/verify-apt.sh index b65e4d3fcd..c5bd4818c2 100755 --- a/dev/release/verify-apt.sh +++ b/dev/release/verify-apt.sh @@ -149,6 +149,7 @@ ${APT_INSTALL} libadbc-driver-manager-dev=${package_version} required_packages=() required_packages+=(cmake) required_packages+=(gcc) +required_packages+=(libc6-dev) required_packages+=(make) required_packages+=(pkg-config) ${APT_INSTALL} ${required_packages[@]} diff --git a/glib/adbc-glib/error.h b/glib/adbc-glib/error.h index 7538a244ae..939e6b477a 100644 --- a/glib/adbc-glib/error.h +++ b/glib/adbc-glib/error.h @@ -69,7 +69,7 @@ G_BEGIN_DECLS * given operation. * May indicate a database-side error only. * - * The error codes are used by all arrow-glib functions. + * The error codes are used by all adbc-glib functions. * * They are corresponding to `ADBC_STATUS_*` values. */ From 25653fdfa87a4e28f9a78b4034b015bd053b757f Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Tue, 14 Nov 2023 10:47:30 +0900 Subject: [PATCH 8/8] Use the same variable name as Vala's one --- glib/example/sqlite.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/glib/example/sqlite.c b/glib/example/sqlite.c index f0a9f39857..7b2062fab1 100644 --- a/glib/example/sqlite.c +++ b/glib/example/sqlite.c @@ -23,7 +23,7 @@ #include int main(int argc, char** argv) { - int result = EXIT_FAILURE; + int exit_code = EXIT_FAILURE; GADBCDatabase* database = NULL; GADBCConnection* connection = NULL; GADBCStatement* statement = NULL; @@ -100,7 +100,7 @@ int main(int argc, char** argv) { g_print("Result:\n%s\n", table_content); g_free(table_content); - result = EXIT_SUCCESS; + exit_code = EXIT_SUCCESS; exit: if (error) { @@ -131,5 +131,5 @@ int main(int argc, char** argv) { } g_object_unref(database); } - return result; + return exit_code; }