Пример #1
0
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();
}
Пример #2
0
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);
     }
}
Пример #3
0
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);
	}
}
Пример #4
0
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;
}

static Eina_Bool