-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
9 changed files
with
283 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!--- | ||
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. | ||
--> | ||
|
||
# GADBC 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- 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. | ||
|
||
executable('sqlite', 'sqlite.c', | ||
dependencies: [adbc_glib], | ||
link_language: 'c') | ||
|
||
install_data('README.md', | ||
install_dir: join_paths(data_dir, meson.project_name(), 'example')) | ||
|
||
subdir('vala') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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 EXIT_FAILURE; | ||
} | ||
|
||
gadbc_database_set_option(database, "driver", "adbc_driver_sqlite", &error); | ||
|
||
if (error != NULL) { | ||
g_print("Error initializing the database: %s", error->message); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
gadbc_database_set_option(database, "uri", "test.db", &error); | ||
|
||
if (error != NULL) { | ||
g_print("Error initializing the database: %s", error->message); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
gadbc_database_init(database, &error); | ||
|
||
if (error != NULL) { | ||
g_print("Error initializing the database: %s", error->message); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
conn = gadbc_connection_new(&error); | ||
|
||
if (error != NULL) { | ||
g_print("Error creating a Connection: %s", error->message); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
gadbc_connection_init(conn, database, &error); | ||
|
||
if (error != NULL) { | ||
g_print("Error initializing a Connection: %s", error->message); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
g_object_unref(conn); | ||
g_object_unref(database); | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -*- 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, | ||
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// 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 = "CREATE TABLE IF NOT EXISTS test (id INTEGER, name TEXT)"; | ||
stm.set_sql_query (sql); | ||
stm.execute (false, null, null); | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters