example in C; always write `errored` in C API;
parent
9054794296
commit
2e14648dbf
@ -0,0 +1 @@
|
||||
example
|
@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Ziyang Hu
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -0,0 +1,3 @@
|
||||
```bash
|
||||
gcc -L../target/release/ -lcozo_c example.c -o example && ./example
|
||||
```
|
@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "cozo_c.h"
|
||||
|
||||
void run_query(int32_t db_id, const char* query) {
|
||||
const char *empty_params = "{}";
|
||||
bool errored;
|
||||
char *res;
|
||||
res = cozo_run_query(db_id, query, empty_params, &errored);
|
||||
|
||||
if (errored) {
|
||||
printf("encountered an error:\n%s\n\n", res);
|
||||
} else {
|
||||
printf("query is successful with result:\n%s\n\n", res);
|
||||
}
|
||||
cozo_free_str(res);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int32_t db_id;
|
||||
char* err = cozo_open_db("_test_db", &db_id);
|
||||
|
||||
if (err) {
|
||||
printf("%s", err);
|
||||
cozo_free_str(err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
run_query(db_id, "?[a, b, c] <- [[1, 2, 3]]");
|
||||
run_query(db_id, "?[a] <- [[1, 2, 3]]");
|
||||
|
||||
cozo_close_db(db_id);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue