Пример #1
0
/* {{{ rberkeley_dbcursor_count */
SEXP rberkeley_dbcursor_count (SEXP _dbc, SEXP _flags)
{
  DBC *dbc;
  db_recno_t countp;
  u_int32_t flags;
  int ret;

  flags = (u_int32_t)INTEGER(_flags)[0]; /* unused by API, set to 0L */

  dbc = R_ExternalPtrAddr(_dbc);
  if(R_ExternalPtrTag(_dbc) != install("DBC") || dbc == NULL)
    error("invalid 'dbc' handle");

  ret = dbc->count(dbc, &countp, flags);

  if(ret != 0)
    return ScalarInteger(ret);

  return ScalarInteger((u_int32_t)countp);
}
Пример #2
0
static int count_blocks(DB *sdb){
    DBC *cursor;
    DBT key, data;
    db_recno_t dup_count;
    char *filename = "big_blocks.txt";
    FILE *fp;

    memset(&key, 0, sizeof(key));
    memset(&data, 0, sizeof(data));

    fp = fopen(filename, "w");
    sdb->cursor(sdb, NULL, &cursor, 0);
    while(DB_NOTFOUND != cursor->get(cursor, &key, &data, DB_NEXT_NODUP)){
        cursor->count(cursor, &dup_count, 0);
        if((int)dup_count > 500)
            fprintf(fp, "%s, %lu\n", (char*)key.data, (size_t)dup_count);
    }
    fclose(fp);
    return 0;
}
Пример #3
0
size_t kmapdset_base::count_impl(const void* k1, DB_TXN* txn, const char* func)
{
	PortableDataOutput<AutoGrownMemIO> oKey1;
	try {
		save_key1(oKey1, k1);
	}
	catch (const IOException& exp)
	{
		string_appender<> oss;
		oss << exp.what() << "... at: " << func;
		throw std::runtime_error(oss.str());
	}
	DBT tk1; memset(&tk1, 0, sizeof(DBT)); tk1.data = oKey1.begin(); tk1.size = oKey1.tell();
	DBT tdd; memset(&tdd, 0, sizeof(DBT));
	DBC* curp = NULL;
	int ret = m_db->cursor(m_db, txn, &curp, 0);
	if (0 == ret)
	{
		ret = curp->get(curp, &tk1, &tdd, DB_SET);
		db_recno_t count = 0;
		if (0 == ret)
			ret = curp->count(curp, &count, 0);
		else if (DB_NOTFOUND == ret)
			count = 0, ret = 0; // clear error

		curp->close(curp);
		if (0 != ret)
			goto ErrorL;
		return count;
	}
ErrorL:
	string_appender<> oss;
	oss << db_strerror(ret)
		<< "... at: " << func
		<< "\n"
		;
	throw std::runtime_error(oss.str());
}
Пример #4
0
int input_load(DB *db, sqlite3* sql_db, char* sql_table){
    int ret;
    struct sqlite_workspace w;
    DB *sdb;
    DBC *cursor;
    DBT pkey;
    memset(&pkey, 0, sizeof(pkey));
    sqlite3_stmt *ppStmt;
    DbRecord recordp;
    DB_BTREE_STAT *stat;
    db_recno_t count=0;
    w.count = &count;
    db_recno_t max = 0;
    char big_block[128];

    if ((ret = db->cursor(db, NULL, &cursor, 0)) != 0) {
		dbenv->err(dbenv, ret, "DB->cursor");
		return (1);
	}
	memset(&(w.key), 0, sizeof(w.key));
	memset(&(w.data), 0, sizeof(w.data));
    
    if(DB_NOTFOUND ==
      (ret = cursor->get(cursor, &(w.key), &(w.data), DB_LAST)))
        w.primary_key = 0;
    else{
        w.primary_key = *(u_int32_t*)(w.data.data);
        w.primary_key++;
    }

    ret = cursor->close(cursor);

    sqlite3_prepare_v2(sql_db, sql_query, -1, &ppStmt, NULL);
    while(SQLITE_ROW == (ret=sqlite3_step(ppStmt))){
        memcpy(&recordp, &DbRecord_base, sizeof(DbRecord));
        build_record(ppStmt, &recordp, &w);
        DbRecord_write(&recordp, db, &w);
        if((count++ % 100000)==0){
            printf("%lu records processed...\n", (ulong)count);
            db->sync(db, 0);
        }
    }
    count = 0;
    sqlite3_finalize(ppStmt);
    

    db->cursor(db, NULL, &cursor, 0);
    cursor->get(cursor, &(w.key), &(w.data), DB_LAST);
    DbRecord_dump(w.data.data);

    db->stat(db, NULL, &stat, 0);
    printf("primary nkeys: %lu\n", (u_long)(stat->bt_nkeys));
    free(stat);

    sqlite_db_secondary_open(db, &sdb, "block_idx", 8*1024, DB_DUPSORT, blocking_callback, compare_uint32);
    sdb->stat(sdb, NULL, &stat, 0);
    printf("block_idx keys: %lu\n", (u_long)(stat->bt_nkeys));
    free(stat);
    sdb->cursor(sdb, NULL, &cursor, 0);
    
    while(DB_NOTFOUND != cursor->pget(cursor, &(w.key), &pkey, &(w.data), DB_NEXT)){
        cursor->count(cursor, &count, 0);
        if (count > max){
            max = count;
            memcpy(big_block, w.key.data, (size_t)w.key.size);
            big_block[w.key.size] = '\0';
        }
    }
    cursor->close(cursor);
    printf("Biggest block: %s\n", big_block);
    printf("%u records.\n", (size_t)max);
    
    count_blocks(sdb);
    sdb->close(sdb, 0);
    

    sqlite_db_secondary_open(db, &sdb, "idx", 8*1024, 0, index_callback, NULL);
    ret = sdb->stat(sdb, NULL, &stat, 0);
    printf("%d\n", ret);
    printf("idx_keys: %lu\n", (u_long)(stat->bt_nkeys));
    free(stat);
    sdb->close(sdb, 0);
    
    return(0);
}