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; }
void print_c_body(FILE* ofd, struct bfi * n, struct bfi * e) { while(n != e) { if (n->orgtype == T_END) indent--; switch(n->type) { case T_MOV: if (!disable_indent) pt(ofd, indent,n); if (!do_run && use_dynmem && n->count>0) fprintf(ofd, "m = move_ptr(m,%d);\n", n->count); else if (n->count == 1) fprintf(ofd, "++m;\n"); else if (n->count == -1) fprintf(ofd, "--m;\n"); else if (n->count == INT_MIN) fprintf(ofd, "m -= 0x%x;\n", -n->count); else if (n->count < 0) fprintf(ofd, "m -= %d;\n", -n->count); else if (n->count > 0) fprintf(ofd, "m += %d;\n", n->count); else fprintf(ofd, "/* m += 0; */\n"); break; case T_ADD: if (!disable_indent) pt(ofd, indent,n); if(n->offset == 0) { if (n->count == 1) fprintf(ofd, "++*m;\n"); else if (n->count == -1) fprintf(ofd, "--*m;\n"); else if (n->count == INT_MIN) fprintf(ofd, "*m -= 0x%x;\n", -n->count); else if (n->count < 0) fprintf(ofd, "*m -= %d;\n", -n->count); else if (n->count > 0) fprintf(ofd, "*m += %d;\n", n->count); else fprintf(ofd, "/* *m += 0; */\n"); } else { if (n->count == 1) fprintf(ofd, "++m[%d];\n", n->offset); else if (n->count == -1) fprintf(ofd, "--m[%d];\n", n->offset); else if (n->count == INT_MIN) fprintf(ofd, "m[%d] -= 0x%x;\n", n->offset, -n->count); else if (n->count < 0) fprintf(ofd, "m[%d] -= %d;\n", n->offset, -n->count); else if (n->count > 0) fprintf(ofd, "m[%d] += %d;\n", n->offset, n->count); else fprintf(ofd, "/* m[%d] += 0; */\n", n->offset); } if (enable_trace) { pt(ofd, indent,0); fprintf(ofd, "t(%d,%d,\"\",m+ %d)\n", n->line, n->col, n->offset); } break; case T_SET: if (!disable_indent) pt(ofd, indent,n); if (cell_size <= 0 && (n->count < -128 || n->count >= 256)) { fprintf(ofd, "m[%d] = (%s) %d;\n", n->offset, cell_type, n->count); } else if (n->count == INT_MIN) fprintf(ofd, "m[%d] = 0x%x;\n", n->offset, n->count); else if(n->offset == 0) fprintf(ofd, "*m = %d;\n", n->count); else fprintf(ofd, "m[%d] = %d;\n", n->offset, n->count); if (enable_trace) { pt(ofd, indent,0); fprintf(ofd, "t(%d,%d,\"\",m+ %d)\n", n->line, n->col, n->offset); } break; case T_CALC: if (!disable_indent) pt(ofd, indent,n); do { if (n->count == 0) { if (n->offset == n->offset2 && n->count2 == 1) { if (n->count3 == 1) { fprintf(ofd, "m[%d] += m[%d];\n", n->offset, n->offset3); break; } if (n->count3 == -1) { fprintf(ofd, "m[%d] -= m[%d];\n", n->offset, n->offset3); break; } if (n->count3 != 0) { fprintf(ofd, "m[%d] += m[%d]*%d;\n", n->offset, n->offset3, n->count3); break; } } if (n->count3 == 0 && n->count2 != 0) { if (n->count2 == 1) { fprintf(ofd, "m[%d] = m[%d];\n", n->offset, n->offset2); } else if (n->count2 == -1) { fprintf(ofd, "m[%d] = -m[%d];\n", n->offset, n->offset2); } else { fprintf(ofd, "m[%d] = m[%d]*%d;\n", n->offset, n->offset2, n->count2); } break; } if (n->count3 == 1 && n->count2 != 0) { fprintf(ofd, "m[%d] = m[%d]*%d + m[%d];\n", n->offset, n->offset2, n->count2, n->offset3); break; } } if (n->offset == n->offset2 && n->count2 == 1) { if (n->count3 == 1) { fprintf(ofd, "m[%d] += m[%d] + %d;\n", n->offset, n->offset3, n->count); break; } fprintf(ofd, "m[%d] += m[%d]*%d + %d;\n", n->offset, n->offset3, n->count3, n->count); break; } if (n->count3 == 0) { if (n->count2 == 1) { fprintf(ofd, "m[%d] = m[%d] + %d;\n", n->offset, n->offset2, n->count); break; } if (n->count2 == -1) { fprintf(ofd, "m[%d] = -m[%d] + %d;\n", n->offset, n->offset2, n->count); break; } fprintf(ofd, "m[%d] = %d + m[%d]*%d;\n", n->offset, n->count, n->offset2, n->count2); } else { fprintf(ofd, "m[%d] = %d + m[%d]*%d + m[%d]*%d; /*T_CALC*/\n", n->offset, n->count, n->offset2, n->count2, n->offset3, n->count3); } } while(0); if (enable_trace) { pt(ofd, indent,0); fprintf(ofd, "t(%d,%d,\"\",m+ %d)\n", n->line, n->col, n->offset); } break; #define okay_for_cstr(xc) (((xc) >= ' ' && (xc) <= '~') || \ (xc == '\n') || (xc == '\r') || (xc == '\a') || \ (xc == '\b') || (xc == '\t')) case T_PRT: if (!use_functions) { if (!disable_indent) pt(ofd, indent,n); fprintf(ofd, "%s(%s);\n", putname, pcell(n->offset)); } else { int pcount = 1; while (n->next && n->next->type == T_PRT && n->offset == n->next->offset) { n = n->next; pcount++; } if (pcount == 1) { if (!disable_indent) pt(ofd, indent,n); fprintf(ofd, "%s(%s);\n", putname, pcell(n->offset)); } else if (pcount < 3) { int cn; for(cn=0;cn<pcount;cn++) { pt(ofd, indent, cn?0:n); fprintf(ofd, "%s(%s);\n", putname, pcell(n->offset)); } } else { pt(ofd, indent, n); fprintf(ofd, "{\n"); pt(ofd, indent+1, 0); fprintf(ofd, "int cn, ch = %s;\n", pcell(n->offset)); pt(ofd, indent+1, 0); fprintf(ofd, "for(cn=0;cn<%d;cn++)\n", pcount); pt(ofd, indent+2, 0); fprintf(ofd, "%s(ch);\n", putname); pt(ofd, indent, 0); fprintf(ofd, "}\n"); } } break; case T_CHR: if (!disable_indent) pt(ofd, indent,n); if (!okay_for_cstr(n->count)) { if (n->count == '\n') fprintf(ofd, "%s('\\n');\n", putname); else fprintf(ofd, "%s(%d);\n", putname, n->count); } else { unsigned i = 0, j; int got_perc = 0; int lastc = 0; unsigned slen = 4; /* First char + nul + ? */ struct bfi * v = n; char *s, *p; while(v->next && v->next->type == T_CHR && okay_for_cstr(v->next->count)) { v = v->next; if (v->count == '%') got_perc = 1; if (v->count < ' ' || v->count > '~' || v->count == '\\' || v->count == '"') slen++; i++; slen++; if (v->next && v->next->count == '\n') ; else if (slen > 132 || (slen>32 && v->count == '\n')) break; } p = s = malloc(slen); for(j=0; j<=i; j++) { lastc = n->count; if (n->count == '\n') { *p++ = '\\'; *p++ = 'n'; } else if (n->count == '\r') { *p++ = '\\'; *p++ = 'r'; } else if (n->count == '\a') { *p++ = '\\'; *p++ = 'a'; } else if (n->count == '\b') { *p++ = '\\'; *p++ = 'b'; } else if (n->count == '\t') { *p++ = '\\'; *p++ = 't'; } else if (n->count == '\\') { *p++ = '\\'; *p++ = '\\'; } else if (n->count == '"') { *p++ = '\\'; *p++ = '"'; } else *p++ = (char) /*GCC -Wconversion*/ n->count; if (j!=i) n = n->next; } *p = 0; if ((p == s+1 && *s != '\'') || (p==s+2 && lastc == '\n')) { fprintf(ofd, "%s('%s');\n", putname, s); } else if (lastc == '\n') { *--p = 0; *--p = 0; fprintf(ofd, "puts(\"%s\");\n", s); } else if (!got_perc) fprintf(ofd, "printf(\"%s\");\n", s); else fprintf(ofd, "printf(\"%%s\", \"%s\");\n", s); free(s); } break; #undef okay_for_cstr case T_INP: if (!disable_indent) pt(ofd, indent,n); if (use_direct_getchar) { if (n->offset == 0) fprintf(ofd, "*m = getchar();\n"); else fprintf(ofd, "m[%d] = getchar();\n", n->offset); } else if (n->offset == 0) fprintf(ofd, "*m = getch(*m);\n"); else fprintf(ofd, "m[%d] = getch(m[%d]);\n", n->offset, n->offset); if (enable_trace) { pt(ofd, indent,0); fprintf(ofd, "t(%d,%d,\"\",m+ %d)\n", n->line, n->col, n->offset); } break; case T_IF: pt(ofd, indent,n); #ifdef TRY_BRANCHLESS if (n->next->next && n->next->next->jmp == n && !enable_trace && !mask_defined) { if (n->next->type == T_SET) { fprintf(ofd, "m[%d] -= (m[%d] - %d) * !!m[%d];\n", n->next->offset, n->next->offset, n->next->count, n->offset); n=n->jmp; break; } if (n->next->type == T_CALC && n->next->count == 0 && n->next->count2 == 1 && n->next->count3 == 0 ) { fprintf(ofd, "m[%d] -= (m[%d] - m[%d]) * !!m[%d];\n", n->next->offset, n->next->offset, n->next->offset2, n->offset); n=n->jmp; break; } } #endif if (n->next->next && n->next->next->jmp == n && !enable_trace) { fprintf(ofd, "if(%s) ", pcell(n->offset)); disable_indent = 1; } else if (!use_goto) { fprintf(ofd, "if(%s) ", pcell(n->offset)); fprintf(ofd, "{\n"); } else { fprintf(ofd, "if(%s == 0) ", pcell(n->offset)); fprintf(ofd, "goto E%d;\n", n->count); } break; case T_WHL: { int found_rail_runner = 0; if (n->next->type == T_MOV && n->next->next && n->next->next->jmp == n) { found_rail_runner = 1; } if (found_rail_runner && !do_run && use_dynmem && n->next->count>0) { pt(ofd, indent,n); fprintf(ofd, "while(%s) m += %d;\n", pcell(n->offset), n->next->count); pt(ofd, indent,n); fprintf(ofd, "m = move_ptr(m,0);\n"); n=n->jmp; break; } #if !defined(DISABLE_TCCLIB) && defined(__i386__) /* TCCLIB generates a slow while() with two jumps in the loop, * and several memory accesses. This is the assembler we would * actually prefer. * * These prints are really ugly; I need a 'print gas in C' * function if we have much more. */ if (found_rail_runner && cell_size == 32 && libtcc_specials) { fprintf(ofd, "#if !defined(__i386__) || !defined(__TINYC__)\n"); pt(ofd, indent,n); if (n->next->count == 1) { fprintf(ofd, "while(m[%d]) ++m;\n", n->offset); } else if (n->next->count == -1) { fprintf(ofd, "while(m[%d]) --m;\n", n->offset); } else if (n->next->count < 0) { fprintf(ofd, "while(m[%d]) m -= %d;\n", n->offset, -n->next->count); } else { fprintf(ofd, "while(m[%d]) m += %d;\n", n->offset, n->next->count); } fprintf(ofd, "#else /* Use i386 assembler */\n"); pt(ofd, indent,n); fprintf(ofd, "{ /* Rail runner */\n"); fprintf(ofd, "__asm__ __volatile__ (\n"); fprintf(ofd, "\"mov %d(%%%%ecx),%%%%eax\\n\\t\"\n", 4 * n->offset); fprintf(ofd, "\"test %%%%eax,%%%%eax\\n\\t\"\n"); fprintf(ofd, "\"je 1f\\n\\t\"\n"); fprintf(ofd, "\"2: add $%d,%%%%ecx\\n\\t\"\n", 4* n->next->count); fprintf(ofd, "\"mov %d(%%%%ecx),%%%%eax\\n\\t\"\n", 4 * n->offset); fprintf(ofd, "\"test %%%%eax,%%%%eax\\n\\t\"\n"); fprintf(ofd, "\"jne 2b\\n\\t\"\n"); fprintf(ofd, "\"1:\\n\\t\"\n"); fprintf(ofd, ": \"=c\" (m)\n"); fprintf(ofd, ": \"0\" (m)\n"); fprintf(ofd, ": \"eax\"\n"); fprintf(ofd, ");\n"); pt(ofd, indent,n); fprintf(ofd, "}\n"); fprintf(ofd, "#endif\n"); n=n->jmp; break; } #endif /* TCCLIB generates a slow 'strlen', libc is better, but the * function call overhead is horrible. */ if (found_rail_runner && cell_size == CHAR_BIT && libtcc_specials && fixed_mask == 0 && n->next->count == 1) { pt(ofd, indent,n); fprintf(ofd, "if(m[%d]) {\n", n->offset); pt(ofd, indent+1,n); fprintf(ofd, "m++;\n"); pt(ofd, indent+1,n); fprintf(ofd, "if(m[%d]) {\n", n->offset); pt(ofd, indent+2,n); fprintf(ofd, "m++;\n"); pt(ofd, indent+2,n); if (n->offset) fprintf(ofd, "m += strlen(m + %d);\n", n->offset); else fprintf(ofd, "m += strlen(m);\n"); pt(ofd, indent+1,n); fprintf(ofd, "}\n"); pt(ofd, indent,n); fprintf(ofd, "}\n"); n=n->jmp; break; } } case T_CMULT: case T_MULT: if (!use_goto) { pt(ofd, indent,n); fprintf(ofd, "while(%s) ", pcell(n->offset)); if (n->next->next && n->next->next->jmp == n && !enable_trace) disable_indent = 1; else fprintf(ofd, "{\n"); } else { if (n->next->next && n->next->next->jmp == n && !enable_trace) { disable_indent = 1; pt(ofd, indent,n); fprintf(ofd, "while(%s) ", pcell(n->offset)); break; } pt(ofd, indent,n); fprintf(ofd, "if(%s == 0) ", pcell(n->offset)); fprintf(ofd, "goto E%d;\n", n->count); pt(ofd, indent,0); fprintf(ofd, "L%d:;\n", n->count); } break; case T_END: case T_ENDIF: if (disable_indent) { disable_indent = 0; break; } if (!use_goto) { pt(ofd, indent,n); fprintf(ofd, "}\n"); } else { if (n->type == T_END) { pt(ofd, indent,n); fprintf(ofd, "if(%s != 0) ", pcell(n->jmp->offset)); fprintf(ofd, "goto L%d;\n", n->jmp->count); pt(ofd, indent,0); } else pt(ofd, indent,n); fprintf(ofd, "E%d:;\n", n->jmp->count); } break; case T_STOP: if (!disable_indent) pt(ofd, indent,n); if (e) fprintf(ofd, "exit(1);\n"); else fprintf(ofd, "return 1;\n"); break; case T_DUMP: if (!disable_indent) pt(ofd, indent,n); fprintf(ofd, "t_dump(m+%d,%d,%d);\n", n->offset, n->line, n->col); break; case T_NOP: fprintf(stderr, "Warning on code generation: " "%s node: ptr+%d, cnt=%d, @(%d,%d).\n", tokennames[n->type], n->offset, n->count, n->line, n->col); break; case T_CALL: if (!disable_indent) pt(ofd, indent,n); fprintf(ofd, "m = bf%d(m);\n", n->count); n=n->jmp; break; default: fprintf(stderr, "Code gen error: " "%s\t" "%d:%d, %d:%d, %d:%d\n", tokennames[n->type], n->offset, n->count, n->offset2, n->count2, n->offset3, n->count3); exit(1); } if (n->orgtype == T_WHL) indent++; n=n->next; } }
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; }