本文整理汇总了C++中TableRef::add_empty_row方法的典型用法代码示例。如果您正苦于以下问题:C++ TableRef::add_empty_row方法的具体用法?C++ TableRef::add_empty_row怎么用?C++ TableRef::add_empty_row使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TableRef
的用法示例。
在下文中一共展示了TableRef::add_empty_row方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
SyncFileActionMetadata::SyncFileActionMetadata(const SyncMetadataManager& manager,
Action action,
const std::string& original_name,
const std::string& url,
const std::string& user_identity,
util::Optional<std::string> new_name)
: m_schema(manager.m_file_action_schema)
{
size_t raw_action = static_cast<size_t>(action);
// Open the Realm.
m_realm = Realm::get_shared_realm(manager.get_configuration());
// Retrieve or create the row for this object.
TableRef table = ObjectStore::table_for_object_type(m_realm->read_group(), c_sync_fileActionMetadata);
m_realm->begin_transaction();
size_t row_idx = table->find_first_string(m_schema.idx_original_name, original_name);
if (row_idx == not_found) {
row_idx = table->add_empty_row();
table->set_string(m_schema.idx_original_name, row_idx, original_name);
}
table->set_string(m_schema.idx_new_name, row_idx, new_name);
table->set_int(m_schema.idx_action, row_idx, raw_action);
table->set_string(m_schema.idx_url, row_idx, url);
table->set_string(m_schema.idx_user_identity, row_idx, user_identity);
m_realm->commit_transaction();
m_row = table->get(row_idx);
}
示例2: set_primary_key_for_object
void ObjectStore::set_primary_key_for_object(Group& group, StringData object_type, StringData primary_key) {
TableRef table = group.get_table(c_primaryKeyTableName);
size_t row = table->find_first_string(c_primaryKeyObjectClassColumnIndex, object_type);
#if REALM_ENABLE_SYNC
// sync::create_table* functions should have already updated the pk table.
if (sync::has_object_ids(group)) {
if (primary_key.size() == 0)
REALM_ASSERT(row == not_found);
else {
REALM_ASSERT(row != not_found);
REALM_ASSERT(table->get_string(c_primaryKeyPropertyNameColumnIndex, row) == primary_key);
}
return;
}
#endif // REALM_ENABLE_SYNC
if (row == not_found && primary_key.size()) {
row = table->add_empty_row();
table->set_string_unique(c_primaryKeyObjectClassColumnIndex, row, object_type);
table->set_string(c_primaryKeyPropertyNameColumnIndex, row, primary_key);
return;
}
// set if changing, or remove if setting to nil
if (primary_key.size() == 0) {
if (row != not_found) {
table->move_last_over(row);
}
}
else {
table->set_string(c_primaryKeyPropertyNameColumnIndex, row, primary_key);
}
}
示例3: create_metadata_tables
void ObjectStore::create_metadata_tables(Group *group) {
TableRef table = group->get_or_add_table(c_primaryKeyTableName);
if (table->get_column_count() == 0) {
table->add_column(type_String, c_primaryKeyObjectClassColumnName);
table->add_column(type_String, c_primaryKeyPropertyNameColumnName);
}
table = group->get_or_add_table(c_metadataTableName);
if (table->get_column_count() == 0) {
table->add_column(type_Int, c_versionColumnName);
// set initial version
table->add_empty_row();
table->set_int(c_versionColumnIndex, c_zeroRowIndex, ObjectStore::NotVersioned);
}
}
示例4: set_primary_key_for_object
void ObjectStore::set_primary_key_for_object(Group *group, StringData object_type, StringData primary_key) {
TableRef table = group->get_table(c_primaryKeyTableName);
// get row or create if new object and populate
size_t row = table->find_first_string(c_primaryKeyObjectClassColumnIndex, object_type);
if (row == not_found && primary_key.size()) {
row = table->add_empty_row();
table->set_string(c_primaryKeyObjectClassColumnIndex, row, object_type);
}
// set if changing, or remove if setting to nil
if (primary_key.size() == 0) {
if (row != not_found) {
table->remove(row);
}
}
else {
table->set_string(c_primaryKeyPropertyNameColumnIndex, row, primary_key);
}
}
示例5: create
Object Object::create(ContextType& ctx, std::shared_ptr<Realm> const& realm,
ObjectSchema const& object_schema, ValueType value,
bool try_update, Row* out_row)
{
realm->verify_in_write();
// get or create our accessor
bool created = false;
// try to get existing row if updating
size_t row_index = realm::not_found;
TableRef table = ObjectStore::table_for_object_type(realm->read_group(), object_schema.name);
bool skip_primary = true;
if (auto primary_prop = object_schema.primary_key_property()) {
// search for existing object based on primary key type
auto primary_value = ctx.value_for_property(value, primary_prop->name,
primary_prop - &object_schema.persisted_properties[0]);
if (!primary_value)
primary_value = ctx.default_value_for_property(object_schema, primary_prop->name);
if (!primary_value) {
if (!is_nullable(primary_prop->type))
throw MissingPropertyValueException(object_schema.name, primary_prop->name);
primary_value = ctx.null_value();
}
row_index = get_for_primary_key_impl(ctx, *table, *primary_prop, *primary_value);
if (row_index == realm::not_found) {
created = true;
if (primary_prop->type == PropertyType::Int) {
#if REALM_HAVE_SYNC_STABLE_IDS
row_index = sync::create_object_with_primary_key(realm->read_group(), *table, ctx.template unbox<util::Optional<int64_t>>(*primary_value));
#else
row_index = table->add_empty_row();
if (ctx.is_null(*primary_value))
table->set_null_unique(primary_prop->table_column, row_index);
else
table->set_unique(primary_prop->table_column, row_index, ctx.template unbox<int64_t>(*primary_value));
#endif // REALM_HAVE_SYNC_STABLE_IDS
}
else if (primary_prop->type == PropertyType::String) {
auto value = ctx.template unbox<StringData>(*primary_value);
#if REALM_HAVE_SYNC_STABLE_IDS
row_index = sync::create_object_with_primary_key(realm->read_group(), *table, value);
#else
row_index = table->add_empty_row();
table->set_unique(primary_prop->table_column, row_index, value);
#endif // REALM_HAVE_SYNC_STABLE_IDS
}
else {
REALM_TERMINATE("Unsupported primary key type.");
}
}
else if (!try_update) {
if (realm->is_in_migration()) {
// Creating objects with duplicate primary keys is allowed in migrations
// as long as there are no duplicates at the end, as adding an entirely
// new column which is the PK will inherently result in duplicates at first
row_index = table->add_empty_row();
created = true;
skip_primary = false;
}
else {
throw std::logic_error(util::format("Attempting to create an object of type '%1' with an existing primary key value '%2'.",
object_schema.name, ctx.print(*primary_value)));
}
}
}
else {
#if REALM_HAVE_SYNC_STABLE_IDS
row_index = sync::create_object(realm->read_group(), *table);
#else
row_index = table->add_empty_row();
#endif // REALM_HAVE_SYNC_STABLE_IDS
created = true;
}
// populate
Object object(realm, object_schema, table->get(row_index));
if (out_row)
*out_row = object.row();
for (size_t i = 0; i < object_schema.persisted_properties.size(); ++i) {
auto& prop = object_schema.persisted_properties[i];
if (skip_primary && prop.is_primary)
continue;
auto v = ctx.value_for_property(value, prop.name, i);
if (!created && !v)
continue;
bool is_default = false;
if (!v) {
v = ctx.default_value_for_property(object_schema, prop.name);
is_default = true;
}
if ((!v || ctx.is_null(*v)) && !is_nullable(prop.type) && !is_array(prop.type)) {
if (prop.is_primary || !ctx.allow_missing(value))
throw MissingPropertyValueException(object_schema.name, prop.name);
}
if (v)
//.........这里部分代码省略.........
示例6: create_object
static Object create_object(SharedRealm realm, const ObjectSchema &object_schema) {
TableRef table = get_table(*realm, object_schema);
return Object(std::move(realm), object_schema, (*table)[table->add_empty_row()]);
}