本文整理汇总了C++中ObString::assign_ptr方法的典型用法代码示例。如果您正苦于以下问题:C++ ObString::assign_ptr方法的具体用法?C++ ObString::assign_ptr怎么用?C++ ObString::assign_ptr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObString
的用法示例。
在下文中一共展示了ObString::assign_ptr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
TEST(TestLogMysqlAdaptor, init)
{
ObLogConfig config;
ObLogServerSelector server_selector;
ObLogRpcStub rpc_stub;
ObLogSchemaGetter schema_getter;
ObLogMysqlAdaptor mysql_adaptor;
config.init("./liboblog.conf");
server_selector.init(config);
rpc_stub.init();
schema_getter.init(&server_selector, &rpc_stub);
mysql_adaptor.init(config, &schema_getter);
ObObj objs[4];
objs[0].set_int(13490859);
objs[1].set_int(0);
objs[2].set_int(1);
ObString str;
str.assign_ptr((char*)("fenxiao-001"), 11);
objs[3].set_varchar(str);
ObRowkey rk;
rk.assign(objs, 4);
const IObLogColValue *list = NULL;
int ret = mysql_adaptor.query_whole_row(3001, rk, list);
TBSYS_LOG(INFO, "query_whole_row ret=%d", ret);
const IObLogColValue *iter = list;
while (NULL != iter)
{
std::string str;
iter->to_str(str);
TBSYS_LOG(INFO, "[VALUE] [%s]", str.c_str());
iter = iter->get_next();
}
////////////////////
objs[0].set_int(2222504619);
str.assign_ptr((char*)("IC"), 2);
objs[3].set_varchar(str);
list = NULL;
ret = mysql_adaptor.query_whole_row(3001, rk, list);
TBSYS_LOG(INFO, "query_whole_row ret=%d", ret);
iter = list;
while (NULL != iter)
{
std::string str;
iter->to_str(str);
TBSYS_LOG(INFO, "[VALUE] [%s]", str.c_str());
iter = iter->get_next();
}
}
示例2: resolve_set_password_stmt
int resolve_set_password_stmt(ResultPlan* result_plan,
ParseNode* node,
uint64_t& query_id)
{
OB_ASSERT(result_plan);
OB_ASSERT(node && node->type_ == T_SET_PASSWORD && node->num_child_ == 2);
int& ret = result_plan->err_stat_.err_code_ = OB_SUCCESS;
ObSetPasswordStmt *stmt = NULL;
if (OB_SUCCESS != (ret = prepare_resolve_stmt(result_plan, query_id, stmt)))
{
}
else
{
ObString user;
if (NULL != node->children_[0])
{
user.assign_ptr(const_cast<char*>(node->children_[0]->str_value_),
static_cast<int32_t>(strlen(node->children_[0]->str_value_)));
}
ObString password = ObString::make_string(node->children_[1]->str_value_);
if (OB_SUCCESS != (ret = stmt->set_user_password(user, password)))
{
PARSER_LOG("Failed to set UserPasswordStmt");
}
}
return ret;
}
示例3: get_cid_by_idx
uint64_t ObMetaTableColumnSchema::get_cid_by_idx(const int64_t i) const
{
uint64_t ret = OB_INVALID_ID;
if (i >= get_columns_num() || 0 > i)
{
TBSYS_LOG(ERROR, "invalid column index, i=%ld tid=%lu", i, table_schema_.table_id_);
}
else
{
ObString cname;
const int buf_len = meta_table_cname::STARTKEY_OBJ_PREFIX.length() + 8;
char cname_buf[buf_len];
cname_buf[0] = '\0';
if (i < static_cast<int64_t>(ARRAYSIZEOF(COLUMNS_NAME)))
{
cname = COLUMNS_NAME[i];
}
else
{
// start_rowkey_obj1, start_rowkey_obj2, ...
int len = snprintf(cname_buf, buf_len, "%.*s%ld", meta_table_cname::STARTKEY_OBJ_PREFIX.length(),
meta_table_cname::STARTKEY_OBJ_PREFIX.ptr(), i - ARRAYSIZEOF(COLUMNS_NAME) + 1);
cname.assign_ptr(cname_buf, len);
}
if (OB_SUCCESS != get_cid_by_name(cname, ret))
{
TBSYS_LOG(ERROR, "meta table column not found, cname=%.*s tid=%lu",
cname.length(), cname.ptr(), table_schema_.table_id_);
}
}
return ret;
}
示例4:
TEST_F(ObObjCastTest, varchar_to_xxx)
{
ObExprObj in;
const char* cases[] = {"1970-1-1 8:0:0", "2012-9-24 16:59:60.000000", "-123456", "-123.456", "true", "false"};
int64_t int_expected[ARRAYSIZEOF(cases)] = {1970, 2012, -123456, -123, 0, 0};
float float_expected[ARRAYSIZEOF(cases)] = {1970.0f, 2012.0f, -123456.0f, -123.456f, 0.0f, 0.0f};
double double_expected[ARRAYSIZEOF(cases)] = {1970.0, 2012.0, -123456.0, -123.456, 0.0, 0.0};
int64_t pdt_expected[ARRAYSIZEOF(cases)] = {0, 1348477200000000, 0, 0, 0, 0};
bool bool_expected[ARRAYSIZEOF(cases)] = {false, false, false, false, true, false};
const char *dec_expected[ARRAYSIZEOF(cases)] = {"0", "0", "-123456", "-123.456", "0", "0"};
for (int64_t i = 0; i < static_cast<int64_t>(ARRAYSIZEOF(cases)); ++i)
{
ObString v;
v.assign_ptr(const_cast<char*>(cases[i]), static_cast<int32_t>(strlen(cases[i])));
in.set_varchar(v);
//printf("case %ld: %s\n", i, cases[i]);
MY_EXPECT(ObVarcharType, in, ObNullType, int_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObIntType, int_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObFloatType, float_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObDoubleType, double_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObDateTimeType, (pdt_expected[i]/1000000L), cases[i]);
MY_EXPECT(ObVarcharType, in, ObPreciseDateTimeType, pdt_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObVarcharType, int_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObSeqType, int_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObCreateTimeType, pdt_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObModifyTimeType, pdt_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObExtendType, int_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObBoolType, bool_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObDecimalType, int_expected[i], dec_expected[i]);
}
}
示例5: convert
int ObUpsRowUtil::convert(const ObUpsRow &row, ObString &compact_row)
{
int ret = OB_SUCCESS;
ObCompactCellWriter cell_writer;
cell_writer.init(compact_row.ptr(), compact_row.size());
const ObObj *cell = NULL;
uint64_t table_id = OB_INVALID_ID;
uint64_t column_id = OB_INVALID_ID;
ObObj cell_clone;
if(row.get_is_delete_row())
{
if(OB_SUCCESS != (ret = cell_writer.row_delete()))
{
TBSYS_LOG(WARN, "append delete row fail:ret[%d]", ret);
}
}
for (int64_t i = 0; (OB_SUCCESS == ret) && i < row.get_column_num(); ++i)
{
if (OB_SUCCESS != (ret = row.raw_get_cell(i, cell, table_id, column_id)))
{
TBSYS_LOG(WARN, "failed to get cell, err=%d", ret);
break;
}
else
{
if(ObExtendType == cell->get_type() && ObActionFlag::OP_NOP == cell->get_ext())
{
//不用处理,OP_NOP不序列化
}
else if (OB_SUCCESS != (ret = cell_writer.append(column_id, *cell)))
{
if (OB_SIZE_OVERFLOW != ret)
{
TBSYS_LOG(WARN, "failed to append cell, err=%d", ret);
}
break;
}
}
} // end for i
if (OB_SUCCESS == ret)
{
if (OB_SUCCESS != (ret = cell_writer.row_finish()))
{
if (OB_SIZE_OVERFLOW != ret)
{
TBSYS_LOG(WARN, "failed to append cell, err=%d", ret);
}
}
else
{
compact_row.assign_ptr(compact_row.ptr(), (int32_t)(cell_writer.size()));
}
}
return ret;
}
示例6:
ScanConds::ScanConds(const char* column_name, const ObLogicOperator& cond_op, ObString& value)
{
ObString name;
name.assign_ptr(const_cast<char*>(column_name), static_cast<int32_t>(strlen(column_name)));
ObObj obj;
obj.set_varchar(value);
EasyArray<ObSimpleCond>(ObSimpleCond(name, cond_op, obj));
}
示例7: execute_sql
int execute_sql(MockClient &client, const char* sql_query)
{
int ret = OB_SUCCESS;
ObString query;
query.assign_ptr(const_cast<char*>(sql_query), static_cast<int32_t>(strlen(sql_query)));
printf("execute_sql, query=[%.*s]...\n", query.length(), query.ptr());
ret = client.execute_sql(query, timeout);
printf("ret=%d\n", ret);
return ret;
}
示例8: create_row_key
void create_row_key(
CharArena& allocator,
ObString& rowkey,
const char* sk)
{
int64_t sz = strlen(sk);
char* msk = allocator.alloc(sz);
memcpy(msk, sk, sz);
rowkey.assign_ptr(msk, sz);
}
示例9: add_column
int ObMutatorHelper::add_column(const char* table_name, const ObString& rowkey, const char* column_name, const ObObj& value, ObMutator* mutator)
{
int ret = OB_SUCCESS;
ObString tname;
ObString column;
if(NULL == table_name)
{
ret = OB_INVALID_ARGUMENT;
TBSYS_LOG(WARN, "table_name is null");
}
if(OB_SUCCESS == ret && NULL == column_name)
{
ret = OB_INVALID_ARGUMENT;
TBSYS_LOG(WARN, "column_name is null");
}
if(OB_SUCCESS == ret && NULL == mutator)
{
ret = OB_INVALID_ARGUMENT;
TBSYS_LOG(WARN, "mutator is null");
}
if(OB_SUCCESS == ret)
{
tname.assign_ptr(const_cast<char*>(table_name), static_cast<int32_t>(strlen(table_name)));
column.assign_ptr(const_cast<char*>(column_name), static_cast<int32_t>(strlen(column_name)));
ret = mutator->update(tname, rowkey, column, value);
if(OB_SUCCESS != ret)
{
TBSYS_LOG(WARN, "add value to mutator fail:table_name[%s], column_name[%s]",
table_name, column_name);
}
}
return ret;
}
示例10: get_random_rowkey
ObString RowkeyBuilder::get_random_rowkey(const int64_t cur_prefix_end, PageArena<char> &allocer)
{
ObString ret;
int64_t prefix = calc_prefix_(cur_prefix_end);
int64_t suffix = calc_suffix_(prefix);
int32_t length = I64_STR_LENGTH + suffix_length_;
char *ptr = allocer.alloc(length);
if (NULL != ptr)
{
sprintf(ptr, "%020ld", prefix);
build_string(ptr + I64_STR_LENGTH, suffix_length_, suffix);
}
ret.assign_ptr(ptr, length);
return ret;
}
示例11: modify_all_cluster_table
int ObRootInnerTableTask::modify_all_cluster_table(const ObRootAsyncTaskQueue::ObSeqTask & task)
{
int ret = OB_SUCCESS;
// write cluster info to internal table
char buf[OB_MAX_SQL_LENGTH] = "";
if (task.type_ == LMS_ONLINE)
{
char ip_buf[OB_MAX_SERVER_ADDR_SIZE] = "";
if (false == task.server_.ip_to_string(ip_buf, sizeof(ip_buf)))
{
ret = OB_INVALID_ARGUMENT;
TBSYS_LOG(WARN, "convert server ip to string failed:ret[%d]", ret);
}
else
{
const char * sql_temp = "REPLACE INTO %s"
"(cluster_id, cluster_vip, cluster_port)"
"VALUES(%d, \'%s\',%u);";
snprintf(buf, sizeof (buf), sql_temp, OB_ALL_CLUSTER, cluster_id_, ip_buf,
task.server_.get_port());
}
}
else if (task.type_ == OBI_ROLE_CHANGE)
{
const char * sql_temp = "REPLACE INTO %s"
"(cluster_id, cluster_role)"
"VALUES(%d, %d);";
snprintf(buf, sizeof (buf), sql_temp, OB_ALL_CLUSTER, cluster_id_, task.cluster_role_);
}
else
{
ret = OB_INVALID_ARGUMENT;
TBSYS_LOG(WARN, "check input param failed:task_type[%d]", task.type_);
}
if (OB_SUCCESS == ret)
{
ObString sql;
sql.assign_ptr(buf, static_cast<ObString::obstr_size_t>(strlen(buf)));
ret = proxy_->query(true, RETRY_TIMES, TIMEOUT, sql);
if (OB_SUCCESS == ret)
{
TBSYS_LOG(INFO, "process inner task succ:task_id[%lu], timestamp[%ld], sql[%s]",
task.get_task_id(), task.get_task_timestamp(), buf);
}
}
return ret;
}
示例12: read_log_file_by_location
int read_log_file_by_location(const char* log_dir, const int64_t file_id, const int64_t offset,
char* buf, const int64_t len, int64_t& read_count, const bool dio = true)
{
int err = OB_SUCCESS;
char path[OB_MAX_FILE_NAME_LENGTH];
int64_t path_len = 0;
ObString fname;
ObFileReader file_reader;
read_count = 0;
if (NULL == log_dir || 0 >= file_id || 0 > offset || NULL == buf || 0 >= len)
{
err = OB_INVALID_ARGUMENT;
}
else if (0 >= (path_len = snprintf(path, sizeof(path), "%s/%ld", log_dir, file_id))
|| path_len > (int64_t)sizeof(path))
{
err = OB_ERROR;
}
else
{
fname.assign_ptr(path, static_cast<int32_t>(path_len));
}
if (OB_SUCCESS != err)
{}
else if (OB_SUCCESS != (err = file_reader.open(fname, dio)))
{
if (OB_FILE_NOT_EXIST != err)
{
TBSYS_LOG(WARN, "file_reader.open(%s/%ld)=>%d", path, file_id, err);
}
else
{
err = OB_SUCCESS;
}
}
else if (OB_SUCCESS != (err = file_reader.pread(buf, len, offset, read_count)))
{
TBSYS_LOG(ERROR, "file_reader.pread(buf=%p[%ld], offset=%ld)=>%d", buf, len, offset, err);
}
if (file_reader.is_opened())
{
file_reader.close();
}
return err;
}
示例13: writer
TEST(TESTObBufferHelper, reader)
{
ObBufferWriter writer(buf);
ObBufferReader reader(buf);
writer.write<uint16_t>(13);
writer.write<int64_t>(32);
const char* str = "oceanbase test";
ObString varchar;
varchar.assign_ptr(const_cast<char*>(str), (int32_t)strlen(str));
writer.write_varchar(varchar);
writer.write<int64_t>(32);
Foo foo;
foo.k1 = 3;
foo.k2 = 24;
writer.write<Foo>(foo);
writer.write<int64_t>(32);
const uint16_t *int_value = NULL;
OK(reader.get<uint16_t>(int_value));
ASSERT_EQ(13, *int_value);
//ASSERT_EQ(13, reader.get<uint16_t>());
ASSERT_EQ(32, reader.get<int64_t>());
ASSERT_EQ(0, memcmp(str, reader.cur_ptr(), strlen(str)));
reader.skip(strlen(str));
ASSERT_EQ(32, reader.get<int64_t>());
Foo* foo1 = reader.get_ptr<Foo>();
ASSERT_EQ(3, foo1->k1);
ASSERT_EQ(24, foo1->k2);
ASSERT_EQ(32, reader.get<int64_t>());
}
示例14: sprintf
ObString RowkeyBuilder::get_rowkey4apply(PageArena<char> &allocer, int64_t *cur_prefix_end)
{
ObString ret;
// 生成一个新的前缀
int64_t prefix = cur_prefix_;
if (cur_suffix_num_ >= cur_max_suffix_num_)
{
prefix = get_prefix_();
int64_t rand = 0;
lrand48_r(&prefix_rand_seed_, &rand);
cur_max_suffix_num_ = range_rand(1, max_suffix_per_prefix_, rand);
cur_suffix_num_ = 0;
srand48_r(prefix, &suffix_rand_seed_);
}
if (NULL != cur_prefix_end)
{
if (cur_prefix_ + 1 == cur_prefix_end_)
{
*cur_prefix_end = cur_prefix_;
}
else
{
*cur_prefix_end = cur_prefix_end_;
}
}
// 生成后缀
int64_t suffix = 0;
lrand48_r(&suffix_rand_seed_, &suffix);
++cur_suffix_num_;
int32_t length = I64_STR_LENGTH + suffix_length_;
char *ptr = allocer.alloc(length);
if (NULL != ptr)
{
sprintf(ptr, "%020ld", prefix);
build_string(ptr + I64_STR_LENGTH, suffix_length_, suffix);
}
ret.assign_ptr(ptr, length);
return ret;
}
示例15: SetUp
void ObMergeSortTest::SetUp()
{
sort_columns_.clear();
ObSortColumn sort_column;
sort_column.table_id_ = test::ObFakeTable::TABLE_ID;
sort_column.column_id_ = OB_APP_MIN_COLUMN_ID;
sort_column.is_ascending_ = false;
ASSERT_EQ(OB_SUCCESS, sort_columns_.push_back(sort_column));
sort_column.table_id_ = test::ObFakeTable::TABLE_ID;
sort_column.column_id_ = OB_APP_MIN_COLUMN_ID+1;
sort_column.is_ascending_ = true;
ASSERT_EQ(OB_SUCCESS, sort_columns_.push_back(sort_column));
ObString filename;
char* filename_buf = (char *)"ob_merge_sort_test.run";
filename.assign_ptr(filename_buf, strlen(filename_buf));
merge_sort_.set_run_filename(filename);
merge_sort_.set_sort_columns(sort_columns_);
in_mem_sort_.set_sort_columns(sort_columns_);
}