Skip to content

Commit

Permalink
Improve parsing of metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Silviu Caragea committed Jun 30, 2015
1 parent 2583cb3 commit 187ddb3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
36 changes: 26 additions & 10 deletions c_src/metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,39 @@ SchemaColumn atom_to_schema_column(ErlNifEnv* env, ERL_NIF_TERM value)
{
if(enif_is_identical(ATOMS.atomList, items[0]))
{
SchemaColumn ss(CASS_VALUE_TYPE_LIST);
ss.subtypes.push_back(atom_to_cass_value_type(items[1]));
return ss;
CassValueType subtype = atom_to_cass_value_type(items[1]);

if(subtype != CASS_VALUE_TYPE_UNKNOWN)
{
SchemaColumn ss(CASS_VALUE_TYPE_LIST);
ss.subtypes.push_back(subtype);
return ss;
}
}
else if(enif_is_identical(ATOMS.atomSet, items[0]))
{
SchemaColumn ss(CASS_VALUE_TYPE_SET);
ss.subtypes.push_back(atom_to_cass_value_type(items[1]));
return ss;
CassValueType subtype = atom_to_cass_value_type(items[1]);

if(subtype != CASS_VALUE_TYPE_UNKNOWN)
{
SchemaColumn ss(CASS_VALUE_TYPE_SET);
ss.subtypes.push_back(subtype);
return ss;
}
}
}
else if (arity == 3 && enif_is_identical(ATOMS.atomMap, items[0]))
{
SchemaColumn ss(CASS_VALUE_TYPE_MAP);
ss.subtypes.push_back(atom_to_cass_value_type(items[1]));
ss.subtypes.push_back(atom_to_cass_value_type(items[2]));
return ss;
CassValueType subtype_key = atom_to_cass_value_type(items[1]);
CassValueType subtype_value = atom_to_cass_value_type(items[2]);

if(subtype_key != CASS_VALUE_TYPE_UNKNOWN && subtype_value != CASS_VALUE_TYPE_UNKNOWN)
{
SchemaColumn ss(CASS_VALUE_TYPE_MAP);
ss.subtypes.push_back(subtype_key);
ss.subtypes.push_back(subtype_value);
return ss;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions c_src/nif_cass_statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ ERL_NIF_TERM nif_cass_statement_new(ErlNifEnv* env, int argc, const ERL_NIF_TERM

SchemaColumn type = atom_to_schema_column(env, items[0]);

if(type.type == CASS_VALUE_TYPE_UNKNOWN)
return enif_make_badarg(env);

ERL_NIF_TERM result = bind_param_by_index(env, stm, index, type, items[1]);

if(!enif_is_identical(result, ATOMS.atomOk))
Expand Down

0 comments on commit 187ddb3

Please sign in to comment.