int main() { char* table = "collect_item"; char* column1 = "item_collector_count"; char* column2 = "item_collect_count"; char* rowkey1 = "AAAAAAAAA"; char* rowkey2 = "AAAAAAAAF"; //memset(rowkey1, 0x00, 9); OB* ob = ob_api_init(); if (NULL == ob) { fprintf(stderr, "ob_init error: %s\n", ob_error()); return 1; } ob_api_debug_log(ob, "DEBUG", NULL); // 连接OceanBase OB_ERR_CODE err = ob_connect(ob, "10.232.36.33", 12010, NULL, NULL); if (OB_ERR_SUCCESS != err) { fprintf(stderr, "ob_connect error: %s\n", ob_error()); } else { // 获得OB_SCAN结构体 OB_SCAN* scan_st = ob_acquire_scan_st(ob); if (NULL == scan_st) { fprintf(stderr, "ob_acquire_scan_st error: %s\n", ob_error()); } else { ob_scan(scan_st, table, rowkey1, 9, 1, rowkey2, strlen(rowkey2), 1); ob_scan_column(scan_st, column1, 1); ob_scan_column(scan_st, column2, 1); ob_scan_res_join_append(scan_st, column2, "join_table", "level", "ding"); ob_scan_res_join_append(scan_st, column2, "join_table", "ding", "level"); if (OB_ERR_SUCCESS != ob_errno()) { fprintf(stderr, "ob_scan error: %s\n", ob_error()); } else { OB_RES* res_st = ob_exec_scan(ob, scan_st); if (NULL == res_st) { fprintf(stderr, "ob_exec_scan error(%d): %s\n", ob_errno(), ob_error()); } else { printf("scan succ: row_num=%ld\n", ob_fetch_row_num(res_st)); OB_CELL* cell = NULL; while ((cell = ob_fetch_cell(res_st)) != NULL) { pcell(cell); } } ob_release_res_st(ob, res_st); } ob_release_scan_st(ob, scan_st); } } ob_api_destroy(ob); return 0; }
int main(int argc, char** argv) { char* table = "test_seller_wm_4"; char* column1 = "nick"; char* column2 = "prov"; char* column3 = "auc_cnt_max_cnt"; char rowkey1[44]; char rowkey2[44]; OB* ob = ob_api_init(); if (NULL == ob) { fprintf(stderr, "ob_init error: %s\n", ob_error()); return 1; } ob_api_debug_log(ob, "DEBUG", NULL); // 连接OceanBase OB_ERR_CODE err = OB_ERR_SUCCESS; if (argc > 2) { fprintf(stderr, "hello"); fprintf(stderr, "connection param used: %s:%s\n", argv[1], argv[2]); char* rs_ip = argv[1]; int rs_port = atoi(argv[2]); // 连接OceanBase err = ob_connect(ob, rs_ip, rs_port, NULL, NULL); } else { // 连接OceanBase err = ob_connect(ob, "172.24.131.234", 5433, NULL, NULL); } if (OB_ERR_SUCCESS != err) { fprintf(stderr, "ob_connect error: %s\n", ob_error()); } else { // 获得OB_REQ结构体 OB_SET* set_st = ob_acquire_set_st(ob); if (NULL == set_st) { fprintf(stderr, "ob_acquire_set_st error: %s\n", ob_error()); } else { fprintf(stderr, "init rowkey... %s\n", ob_error()); memset(rowkey1, 0x00, 44); memset(rowkey2, 0x00, 44); memcpy(&rowkey1[0], "201145", 6); rowkey1[8 + 6 - 1] = 16; memcpy(&rowkey2[0], "201145", 6); rowkey2[8 + 6 - 1] = 16; memset(&rowkey2[14], 0xee, 8); OB_VARCHAR r1c1 = {"lovinlovin", strlen("lovinlovin")}; OB_VARCHAR r1c2 = {"shanghai", strlen("shanghai")}; OB_VARCHAR r2c1 = {"songyi0209", strlen("songyi0209")}; OB_VARCHAR r2c2 = {"beijing", strlen("beijing")}; fprintf(stderr, "insert value... %s\n", ob_error()); //memset(rowkey1, 0x00, 44); //memset(rowkey2, 0xFF, 44); ob_insert_varchar(set_st, table, rowkey1, 22, column1, r1c1); ob_insert_varchar(set_st, table, rowkey1, 22, column2, r1c2); ob_insert_varchar(set_st, table, rowkey2, 22, column1, r2c1); ob_insert_varchar(set_st, table, rowkey2, 22, column2, r1c2); /* ob_insert_int(set_st, table, rowkey1, strlen(rowkey1), column1, 1); ob_insert_int(set_st, table, rowkey1, strlen(rowkey1), column2, 3); ob_insert_int(set_st, table, rowkey2, strlen(rowkey2), column1, 1); ob_insert_int(set_st, table, rowkey2, strlen(rowkey2), column2, 4); */ if (OB_ERR_SUCCESS != ob_errno()) { fprintf(stderr, "insert error: %s\n", ob_error()); } else { int32_t t = 0; OB_ERR_CODE err = ob_exec_set(ob, set_st); if (OB_ERR_SUCCESS != err) { fprintf(stderr, "set failed: %s\n", ob_error()); } else { printf("set succ\n"); } } ob_release_set_st(ob, set_st); } } ob_api_destroy(ob); return 0; }
int main() { OB_REQ* req = NULL; int64_t num = 0; char* table = "collect_item"; char* column1 = "item_collector_count"; char* column2 = "item_collect_count"; char* rowkey1 = "AAAAAAAAA"; //char rowkey1[9]; char* rowkey2 = "AAAAAAAAF"; //memset(rowkey1, 0x00, 9); OB* ob = ob_api_init(); if (NULL == ob) { fprintf(stderr, "ob_init error: %s\n", ob_error()); return 1; } ob_api_debug_log(ob, "DEBUG", "scan_demo.log"); //ob_api_debug_log(ob, "DEBUG", NULL); // 连接OceanBase OB_ERR_CODE err = ob_connect(ob, "10.232.36.33", 11010, NULL, NULL); if (OB_ERR_SUCCESS != err) { fprintf(stderr, "ob_connect error: %s\n", ob_error()); } else { // 获得OB_REQ结构体 req = ob_acquire_scan_req(ob); // 用户自定义请求id req->req_id = 1; ob_scan(NULL, table, rowkey1, 9, 1, rowkey2, strlen(rowkey2), 1); printf("%s\n", ob_error()); ob_scan(req->ob_scan, table, rowkey1, 9, 1, rowkey2, strlen(rowkey2), 1); //ob_scan(req->ob_scan, table, rowkey1, 9, 1, 0, 0, 0); //ob_scan(req->ob_scan, table, NULL, 0, 0, NULL, 0, 0); ob_scan_column(req->ob_scan, column1, 1); ob_scan_column(req->ob_scan, column2, 1); ob_scan_column(req->ob_scan, "item_title", 1); //ob_scan_set_limit(req->ob_scan, 0, 2); //ob_scan_orderby_column(req->ob_scan, column2, OB_DESC); if (OB_ERR_SUCCESS != ob_errno()) { fprintf(stderr, "insert error: %s\n", ob_error()); } else { err = ob_submit(ob, req); if (OB_ERR_SUCCESS != err) { fprintf(stderr, "ob_submit error: %s\n", ob_error()); } else { err = ob_get_results(ob, 1, 1, 1000000, &num, &req); if (OB_ERR_SUCCESS == err && req->err_code == OB_ERR_SUCCESS) { printf("scan succ: row_num=%ld\n", ob_fetch_row_num(req->ob_res)); OB_CELL* cell = NULL; while ((cell = ob_fetch_cell(req->ob_res)) != NULL) { //printf("%ld\n", cell->v.v.v_int); pcell(cell); } ob_res_seek_to_begin_cell(req->ob_res); while ((cell = ob_fetch_cell(req->ob_res)) != NULL) { //printf("%ld\n", cell->v.v.v_int); pcell(cell); } } else { fprintf(stderr, "scan failed: %s\n", ob_error()); } } } ob_release_req(ob, req, 1); } ob_api_destroy(ob); return 0; }