Merge pull request #1768 from heuripedes/master

libretro-db improvements
This commit is contained in:
Twinaphex 2015-06-10 20:05:05 +02:00
commit ca998b1d3e
4 changed files with 56 additions and 15 deletions

View File

@ -226,10 +226,7 @@ static int database_cursor_iterate(libretrodb_cursor_t *cur,
db_info->publisher = strdup(val->string.buff);
break;
case DB_CURSOR_DEVELOPER:
{
db_info->developer = string_list_new();
db_info->developer = string_split(val->string.buff, "|");
}
db_info->developer = string_split(val->string.buff, "|");
break;
case DB_CURSOR_ORIGIN:
db_info->origin = strdup(val->string.buff);

View File

@ -323,7 +323,10 @@ retry:
if (cursor->query)
{
if (!libretrodb_query_filter(cursor->query, out))
{
rmsgpack_dom_value_free(out);
goto retry;
}
}
return 0;

View File

@ -483,6 +483,7 @@ static struct buffer parse_string(struct buffer buff,
const char * str_start;
char terminator = '\0';
char c = '\0';
int is_binstr = 0;
(void)c;
@ -491,6 +492,12 @@ static struct buffer parse_string(struct buffer buff,
if (*error)
return buff;
if (terminator == 'b')
{
is_binstr = 1;
buff = get_char(buff, &terminator, error);
}
if (terminator != '"' && terminator != '\'')
{
buff.offset--;
@ -509,18 +516,42 @@ static struct buffer parse_string(struct buffer buff,
if (!*error)
{
value->type = RDT_STRING;
size_t nmemb = is_binstr ? (value->string.len + 1) / 2 : (value->string.len + 1);
value->type = is_binstr ? RDT_BINARY : RDT_STRING;
value->string.len = (buff.data + buff.offset) - str_start - 1;
value->string.buff = (char*)calloc(value->string.len + 1, sizeof(char));
value->string.buff = (char*)calloc(nmemb, sizeof(char));
if (!value->string.buff)
raise_enomem(error);
else if (is_binstr)
{
unsigned i, j;
const char *tok = str_start;
j = 0;
for (i = 0; i < value->string.len; i += 2)
{
uint8_t hi, lo;
char hic = tok[i];
char loc = tok[i + 1];
if (hic <= '9')
hi = hic - '0';
else
hi = (hic - 'A') + 10;
if (loc <= '9')
lo = loc - '0';
else
lo = (loc - 'A') + 10;
value->string.buff[j++] = hi * 16 + lo;
}
value->string.len = j;
}
else
memcpy(
value->string.buff,
str_start,
value->string.len
);
memcpy(value->string.buff, str_start, value->string.len);
}
return buff;
}
@ -568,7 +599,7 @@ static struct buffer parse_value(struct buffer buff,
value->type = RDT_BOOL;
value->bool_ = 0;
}
else if (peek(buff, "\"") || peek(buff, "'"))
else if (peek(buff, "b") || peek(buff, "\"") || peek(buff, "'"))
buff = parse_string(buff, value, error);
else if (isdigit(buff.data[buff.offset]))
buff = parse_integer(buff, value, error);
@ -824,6 +855,7 @@ static struct buffer parse_argument(struct buffer buff,
peek(buff, "nil")
|| peek(buff, "true")
|| peek(buff, "false")
|| peek(buff, "b\"") || peek(buff, "b'") /* bin string prefix*/
)
)
{
@ -854,6 +886,10 @@ void libretrodb_query_free(void *q)
for (i = 0; i < real_q->root.argc; i++)
argument_free(&real_q->root.argv[i]);
free(real_q->root.argv);
real_q->root.argv = NULL;
free(real_q);
}
void *libretrodb_query_compile(libretrodb_t *db,

View File

@ -127,7 +127,7 @@ static int database_info_iterate_next(database_info_handle_t *db)
return -1;
}
static int database_info_list_iterate_new(database_state_handle_t *db_state)
static int database_info_list_iterate_new(database_state_handle_t *db_state, const char *query)
{
const char *new_database = db_state->list->elems[db_state->list_index].data;
#if 0
@ -136,7 +136,7 @@ static int database_info_list_iterate_new(database_state_handle_t *db_state)
#endif
if (db_state->info)
database_info_list_free(db_state->info);
db_state->info = database_info_list_new(new_database, NULL);
db_state->info = database_info_list_new(new_database, query);
return 0;
}
@ -230,7 +230,12 @@ static int database_info_iterate_crc_lookup(
return database_info_list_iterate_end_no_match(db_state);
if (db_state->entry_index == 0)
database_info_list_iterate_new(db_state);
{
char query[50];
snprintf(query, sizeof(query), "{crc: b\"%08X\"}", swap_if_big32(db_state->crc));
database_info_list_iterate_new(db_state, query);
}
if (db_state->info)
{