kou commented on code in PR #1152: URL: https://github.com/apache/arrow-adbc/pull/1152#discussion_r1346641512
########## glib/example/README.md: ########## @@ -0,0 +1,48 @@ +<!--- + 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 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, Lua example codes exists +in `lua/` sub directory. + +## C example codes + +Here are example codes in this directory: + + * `build.c`: It shows how to create an array by array builder. + +<!--- + * `write-file.c`: It shows how to write Arrow array to file in file + format. +--> + + * `read-file.c`: It shows how to read Arrow array from file in file + format. + +<!--- + * `write-stream.c`: It shows how to write Arrow array to file in + stream format. +--> + + * `read-stream.c`: It shows how to read Arrow array from file in + stream format. Review Comment: Could you update this content? ########## glib/example/sqlite.c: ########## @@ -0,0 +1,72 @@ +/* + * 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 <stdlib.h> + +#include <adbc-glib/adbc-glib.h> + +int main(int argc, char** argv) { + GADBCDatabase* database; + GADBCConnection* conn; + GError* error = NULL; + + database = gadbc_database_new(&error); + + if (error != NULL) { + g_print("Error creating a Database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "driver", "adbc_driver_sqlite", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "uri", "test.db", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; Review Comment: ```suggestion if (!gadbc_database_set_option(database, "uri", "test.db", &error)) { g_print("Error setting the database path: %s", error->message); g_error_free(error); return EXIT_FAILURE; ``` ########## glib/example/vala/README.md: ########## @@ -0,0 +1,36 @@ +<!--- + 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. +--> + +# ADBC 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 +``` + +## Vala example codes + +Here are example codes in this directory: + + * `build.vala`: It shows how to create an array by array builder. Review Comment: Could you update this? ########## glib/example/vala/sqlite.vala: ########## @@ -0,0 +1,33 @@ +// 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.db"); + database.init (); + var conn = new GADBC.Connection (); + conn.init (database); + } + catch (GLib.Error e) { + GLib.message ("Error: %s", e.message); Review Comment: ```suggestion GLib.message("Error: %s", e.message); ``` ########## glib/example/sqlite.c: ########## @@ -0,0 +1,72 @@ +/* + * 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 <stdlib.h> + +#include <adbc-glib/adbc-glib.h> + +int main(int argc, char** argv) { + GADBCDatabase* database; + GADBCConnection* conn; + GError* error = NULL; + + database = gadbc_database_new(&error); + + if (error != NULL) { + g_print("Error creating a Database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "driver", "adbc_driver_sqlite", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; Review Comment: ```suggestion if (!gadbc_database_set_option(database, "driver", "adbc_driver_sqlite", &error)) { g_print("Error setting the driver: %s", error->message); g_error_free(error); return EXIT_FAILURE; ``` ########## glib/example/vala/sqlite.vala: ########## @@ -0,0 +1,33 @@ +// 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.db"); + database.init (); + var conn = new GADBC.Connection (); + conn.init (database); Review Comment: ```suggestion var database = new GADBC.Database(); database.set_option("driver", "adbc_driver_sqlite"); database.set_option("uri", "test.sqlite"); database.init(); try { var connection = new GADBC.Connection(); connection.init(database); connection.release(); } catch (GLib.Error error) { GLib.message("Error: %s", e.message); } database.release(); ``` ########## glib/example/sqlite.c: ########## @@ -0,0 +1,72 @@ +/* + * 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 <stdlib.h> + +#include <adbc-glib/adbc-glib.h> + +int main(int argc, char** argv) { + GADBCDatabase* database; + GADBCConnection* conn; + GError* error = NULL; + + database = gadbc_database_new(&error); + + if (error != NULL) { + g_print("Error creating a Database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "driver", "adbc_driver_sqlite", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "uri", "test.db", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + gadbc_database_init(database, &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; Review Comment: ```suggestion if (!gadbc_database_init(database, &error)) { g_print("Error initializing the database: %s", error->message); g_error_free(error); return EXIT_FAILURE; ``` ########## glib/adbc-glib/meson.build: ########## @@ -86,7 +86,8 @@ pkgconfig.generate(libadbc_glib, variables: pkgconfig_variables, version: meson.project_version()) -adbc_glib_gir = gnome.generate_gir(libadbc_glib, +if have_gi + adbc_glib_gir = gnome.generate_gir(libadbc_glib, Review Comment: We don't need this check because we always require GObject Introspection: ```suggestion adbc_glib_gir = gnome.generate_gir(libadbc_glib, ``` ########## glib/example/sqlite.c: ########## @@ -0,0 +1,72 @@ +/* + * 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 <stdlib.h> + +#include <adbc-glib/adbc-glib.h> + +int main(int argc, char** argv) { + GADBCDatabase* database; + GADBCConnection* conn; + GError* error = NULL; + + database = gadbc_database_new(&error); + + if (error != NULL) { + g_print("Error creating a Database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "driver", "adbc_driver_sqlite", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "uri", "test.db", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + gadbc_database_init(database, &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + conn = gadbc_connection_new(&error); + + if (error != NULL) { + g_print("Error creating a Connection: %s", error->message); + return 1; + } Review Comment: ```suggestion if (!conn) { g_print("Error creating a connection: %s", error->message); g_error_free(error); return EXIT_FAILURE; } ``` ########## glib/example/sqlite.c: ########## @@ -0,0 +1,72 @@ +/* + * 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 <stdlib.h> + +#include <adbc-glib/adbc-glib.h> + +int main(int argc, char** argv) { + GADBCDatabase* database; + GADBCConnection* conn; + GError* error = NULL; + + database = gadbc_database_new(&error); + + if (error != NULL) { + g_print("Error creating a Database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "driver", "adbc_driver_sqlite", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "uri", "test.db", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + gadbc_database_init(database, &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + conn = gadbc_connection_new(&error); + + if (error != NULL) { + g_print("Error creating a Connection: %s", error->message); + return 1; + } + + gadbc_connection_init(conn, database, &error); + + if (error != NULL) { + g_print("Error initializing a Connection: %s", error->message); + return 1; + } + + return EXIT_SUCCESS; Review Comment: ```suggestion if (!gadbc_connection_release(conn, &error)) { g_print("Error releasing a connection: %s\n", error->message); g_error_free(error); error = NULL; } g_object_unref(conn); if (!gadbc_database_release(database, &error)) { g_print("Error releasing a database: %s\n", error->message); g_error_free(error); } g_object_unref(database); return EXIT_SUCCESS; ``` ########## glib/example/sqlite.c: ########## @@ -0,0 +1,72 @@ +/* + * 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 <stdlib.h> + +#include <adbc-glib/adbc-glib.h> + +int main(int argc, char** argv) { + GADBCDatabase* database; + GADBCConnection* conn; + GError* error = NULL; + + database = gadbc_database_new(&error); + + if (error != NULL) { + g_print("Error creating a Database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "driver", "adbc_driver_sqlite", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "uri", "test.db", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + gadbc_database_init(database, &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + conn = gadbc_connection_new(&error); + + if (error != NULL) { + g_print("Error creating a Connection: %s", error->message); + return 1; + } + + gadbc_connection_init(conn, database, &error); + + if (error != NULL) { + g_print("Error initializing a Connection: %s", error->message); + return 1; Review Comment: ```suggestion if (!gadbc_connection_init(conn, database, &error)) { g_print("Error initializing a connection: %s", error->message); g_error_free(error); return EXIT_FAILURE; ``` ########## glib/meson.build: ########## @@ -67,7 +68,15 @@ else dirs: [adbc_build_dir]) endif +have_gi = dependency('gobject-introspection-1.0', required: false).found() Review Comment: We don't need this variable because we always require GObject Introspection. ########## glib/example/sqlite.c: ########## @@ -0,0 +1,72 @@ +/* + * 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 <stdlib.h> + +#include <adbc-glib/adbc-glib.h> + +int main(int argc, char** argv) { + GADBCDatabase* database; + GADBCConnection* conn; + GError* error = NULL; + + database = gadbc_database_new(&error); + + if (error != NULL) { + g_print("Error creating a Database: %s", error->message); + return 1; Review Comment: ```suggestion if (!database) { g_print("Error creating a Database: %s", error->message); g_error_free(error); return EXIT_FAILURE; ``` ########## glib/example/sqlite.c: ########## @@ -0,0 +1,72 @@ +/* + * 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 <stdlib.h> + +#include <adbc-glib/adbc-glib.h> + +int main(int argc, char** argv) { + GADBCDatabase* database; + GADBCConnection* conn; + GError* error = NULL; + + database = gadbc_database_new(&error); + + if (error != NULL) { + g_print("Error creating a Database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "driver", "adbc_driver_sqlite", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "uri", "test.db", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; Review Comment: `test.sqlite` may be better. ########## glib/example/vala/README.md: ########## @@ -0,0 +1,36 @@ +<!--- + 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. +--> + +# ADBC Vala example Review Comment: ```suggestion # ADBC GLib Vala example ``` ########## glib/example/sqlite.c: ########## @@ -0,0 +1,72 @@ +/* + * 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 <stdlib.h> + +#include <adbc-glib/adbc-glib.h> + +int main(int argc, char** argv) { + GADBCDatabase* database; + GADBCConnection* conn; Review Comment: How about using `connection` for readability? ########## glib/example/sqlite.c: ########## @@ -0,0 +1,72 @@ +/* + * 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 <stdlib.h> + +#include <adbc-glib/adbc-glib.h> + +int main(int argc, char** argv) { + GADBCDatabase* database; + GADBCConnection* conn; + GError* error = NULL; + + database = gadbc_database_new(&error); + + if (error != NULL) { + g_print("Error creating a Database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "driver", "adbc_driver_sqlite", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + gadbc_database_set_option(database, "uri", "test.db", &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + gadbc_database_init(database, &error); + + if (error != NULL) { + g_print("Error initializing the database: %s", error->message); + return 1; + } + + conn = gadbc_connection_new(&error); + + if (error != NULL) { + g_print("Error creating a Connection: %s", error->message); + return 1; + } + + gadbc_connection_init(conn, database, &error); + + if (error != NULL) { + g_print("Error initializing a Connection: %s", error->message); + return 1; + } + + return EXIT_SUCCESS; Review Comment: How about running a query too? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
