Created
March 22, 2012 14:26
-
-
Save hhatto/2158613 to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
#include <string.h> | |
#include "groonga.h" | |
static void execute_gql(grn_ctx *ctx, char *gql, int len) | |
{ | |
unsigned int result_size; | |
char *result = NULL; | |
grn_ctx_send(ctx, gql, len, 0); | |
grn_ctx_recv(ctx, &result, &result_size, 0); | |
printf("rc:%d, result:%s\n", ctx->rc, result); | |
} | |
int main(int argc, char **argv) | |
{ | |
char gql[1000]; | |
grn_ctx ctx; | |
grn_obj *db; | |
grn_rc rc; | |
grn_db_create_optarg create_optargs; | |
if (argc != 2) { | |
fprintf(stderr, "Usage: ./prog DB_FILE\n"); | |
return 1; | |
} | |
memset(gql, 0, sizeof(gql)); | |
grn_init(); | |
rc = grn_ctx_init(&ctx, 0); | |
if (GRN_SUCCESS != rc) { | |
fprintf(stderr, "grn_ctx_init() error. rc=%d\n", rc); | |
return 1; | |
} | |
create_optargs.builtin_type_names = NULL; | |
create_optargs.n_builtin_type_names = 0; | |
db = grn_db_open(&ctx, argv[1]); | |
if (!db) { | |
db = grn_db_create(&ctx, argv[1], &create_optargs); | |
if (!db) { | |
fprintf(stderr, "grn_db_create() error.\n"); | |
return 1; | |
} | |
} | |
strcpy(gql, "table_create --name Users --flags TABLE_HASH_KEY --key_type ShortText"); | |
execute_gql(&ctx, gql, strlen(gql)); | |
strcpy(gql, "select --table Users"); | |
execute_gql(&ctx, gql, strlen(gql)); | |
grn_ctx_fin(&ctx); | |
grn_fin(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment