コード例 #1
0
ファイル: test_sqlite.c プロジェクト: carloslack/esskyuehl
static void
on_query_results(Esql_Res *res, void *data)
{
   struct ctx *ctx = data;
   const Esql_Row *row;
   Eina_Iterator *itr;
   const char *cname;
   int i;

   assert(esql_res_rows_count(res) == INSERTED_ROWS);
   assert(esql_res_cols_count(res) == 2);

   ctx->res++;
   printf("results %u: rows=%d, columns=%d\n",
          ctx->res,
          esql_res_rows_count(res),
          esql_res_cols_count(res));

   cname = esql_res_col_name_get(res, 0);
   assert(cname!=NULL);
   assert(strcmp(cname, "i") == 0);

   cname = esql_res_col_name_get(res, 1);
   assert(cname!=NULL);
   assert(strcmp(cname, "s") == 0);

   i = 0;
   itr = esql_res_row_iterator_new(res);
   EINA_ITERATOR_FOREACH(itr, row)
     {
        const Eina_Value *val = esql_row_value_struct_get(row);
        const char *str;
        char buf[100];
        int num;

        assert(eina_value_struct_get(val, "i", &num));
        assert(i == num);

        snprintf(buf, sizeof(buf), "some-text-%10d", i);

        assert(eina_value_struct_get(val, "s", &str));
        assert(str!=NULL);
        assert(strcmp(str, buf) == 0);

        i++;
     }
   eina_iterator_free(itr);

   ecore_main_loop_quit();
}
コード例 #2
0
ファイル: zrpcdb_vm.c プロジェクト: zmike/ezrpc
static Eina_List *
zrpcdb_vm_keyvalue(Esql_Res *res){
  Eina_Iterator *it;
  Esql_Row *r;
  Eina_List *ret = NULL;
  KEYVALUE * tmp;
  EINA_SAFETY_ON_NULL_RETURN_VAL(res, NULL);

  if (!esql_res_rows_count(res)) return NULL;
  it = esql_res_row_iterator_new(res);
  EINA_ITERATOR_FOREACH(it, r)
    {
      Eina_Inlist *l;
      Esql_Cell *c;

      tmp = KEYVALUE_new();
      l = esql_row_cells_get(r);
      EINA_INLIST_FOREACH(l, c)
	{
	  if (!strcmp(c->colname, "uuid"))
	    tmp->key = eina_stringshare_add(c->value.string);
	  else if (!strcmp(c->colname, "avg"))
	    tmp->value = eina_stringshare_add(c->value.string);
	  tmp->type = eina_stringshare_add("double");
	}
      ret = eina_list_append(ret, tmp);
    }
コード例 #3
0
ファイル: basic_pool.c プロジェクト: carloslack/esskyuehl
static void
callback_(Esql_Res *res, char *data)
{
   printf("%i rows returned to callback!\n", esql_res_rows_count(res)); /**< could do more here, but it's a simple example so we just print the number of rows */
   printf("data stored: '%s'\n", data);
   printf("Query string: '%s'\n", esql_res_query_get(res));
   free(data);
   ecore_main_loop_quit();
}
コード例 #4
0
ファイル: test_sqlite.c プロジェクト: carloslack/esskyuehl
static void
on_query_populate(Esql_Res *res, void *data)
{
   struct ctx *ctx = data;

   assert(esql_res_rows_count(res) == 0);
   assert(esql_res_cols_count(res) == 0);
   ctx->res++;
   printf("populated %u: %s\n", ctx->res, esql_res_query_get(res));

   if (ctx->res == INSERTED_ROWS + 1)
     {
        Esql *e = esql_res_esql_get(res);
        Esql_Query_Id id = esql_query(e, ctx, "SELECT i, s FROM t");
        assert(id > 0);
        esql_query_callback_set(id, on_query_results);
     }
}
コード例 #5
0
ファイル: zrpcdb.c プロジェクト: zmike/ezrpc
void
event_cb(Esql_Res *res, Zentific_Ctx *ctx){
	const char *query;
	Z_Ctx_Cb end_cb;
	Zrpcdb_Cb cb;
	Esql_Query_Id qid;
	long long int insert_id;
	DB *db;
	Eina_Bool state;

	qid = esql_res_query_id_get(res);
	state = ctx->state;
	ctx->state = EINA_FALSE;
	if (esql_res_error_get(res)){
		ERR("Query %lu: \"%s\" - %s", qid, esql_res_query_get(res), esql_res_error_get(res));
		eina_hash_del_by_key(db_cbs, &qid);
		ctx->error = AZY_ERR(DB_QUERY);
		ecore_event_add(ZRPCDB_EVENT_ERROR, ctx, fake_free, NULL);
		return;
	}
	query = esql_res_query_get(res);
	cb = eina_hash_find(type_cbs, &qid);
	db = esql_data_get(esql_res_esql_get(res));
	if (cb) { /* all SELECT calls have cbs */
		DBG("%i rows returned", esql_res_rows_count(res));
		if (state && (esql_res_rows_count(res) > 1)){
			ctx->error = AZY_ERR(DB_MULTI);
			eina_hash_del_by_key(db_cbs, &qid);
			ctx->state = state;
			ecore_event_add(ZRPCDB_EVENT_ERROR, ctx, fake_free, NULL);
			return;
		}
		end_cb = eina_hash_find(db_cbs, &qid); /* another db call queued */
		if (end_cb) {
			eina_hash_del_by_key(db_cbs, &qid);
			end_cb(res, ctx, cb(res));
			return;
		}
		if (ctx->cbs){
			end_cb = ctx->cbs->data;
			end_cb(ctx, cb(res));
		} else {
			ctx->state = state;
			ctx->retval = cb(res);
			ecore_event_add(ZRPCDB_EVENT_RESULT, ctx, fake_free, NULL);
		}
		return;
	}
	end_cb = eina_hash_find(db_cbs, &qid); /* another db call queued */
	insert_id = esql_res_id(res);
	if (esql_res_rows_affected(res))
		INF("Query \"%s\" inserted with id %lli", esql_res_query_get(res), insert_id);
	else
		ERR("Query \"%s\" affected 0 rows", esql_res_query_get(res));
	if (end_cb) {
		eina_hash_del_by_key(db_cbs, &qid);
		if (state) end_cb(res, ctx, insert_id);
		else end_cb(res, ctx);
		return;
	}
	if (ctx->cbs) {
		end_cb = ctx->cbs->data;
		if (state) end_cb(ctx, insert_id);
		else end_cb(ctx);
	} else {
		ctx->state = state;
		ctx->retval = (intptr_t*)(int)insert_id;
		ecore_event_add(ZRPCDB_EVENT_RESULT, ctx, fake_free, NULL);
	}
}
コード例 #6
0
ファイル: basic_pool.c プロジェクト: carloslack/esskyuehl
#include <Ecore.h>

static void
callback_(Esql_Res *res, char *data)
{
   printf("%i rows returned to callback!\n", esql_res_rows_count(res)); /**< could do more here, but it's a simple example so we just print the number of rows */
   printf("data stored: '%s'\n", data);
   printf("Query string: '%s'\n", esql_res_query_get(res));
   free(data);
   ecore_main_loop_quit();
}

static Eina_Bool
result_(void *data EINA_UNUSED, int type EINA_UNUSED, Esql_Res *res)
{
   printf("%i rows returned!\n", esql_res_rows_count(res)); /**< could do more here, but it's a simple example so we just print the number of rows */
   printf("data stored: '%s'\n", (char*)esql_res_data_get(res));
   printf("Query string: '%s'\n", esql_res_query_get(res));
   free(esql_res_data_get(res));
   ecore_main_loop_quit();
   return ECORE_CALLBACK_RENEW;
}

static Eina_Bool
error_(void *data EINA_UNUSED, int type EINA_UNUSED, Esql *e)
{
   fprintf(stderr, "%s\n", esql_error_get(e)); /**< print error condition */
   printf("Query string: '%s'\n", esql_current_query_get(e));
   ecore_main_loop_quit();
   return ECORE_CALLBACK_RENEW;
}