コード例 #1
0
static void testOomScan(
  OomTest *pOom, 
  lsm_db *pDb, 
  int bReverse,
  const void *pKey, int nKey,
  int nScan,
  int *pRc
){
  if( *pRc==0 ){
    int rc;
    int iScan = 0;
    lsm_cursor *pCsr;
    int (*xAdvance)(lsm_cursor *);
    

    rc = lsm_csr_open(pDb, &pCsr);
    testOomAssertRc(pOom, rc);

    if( rc==LSM_OK ){
      if( bReverse ){
        rc = lsm_csr_seek(pCsr, pKey, nKey, LSM_SEEK_LE);
        xAdvance = lsm_csr_prev;
      }else{
        rc = lsm_csr_seek(pCsr, pKey, nKey, LSM_SEEK_GE);
        xAdvance = lsm_csr_next;
      }
    }
    testOomAssertRc(pOom, rc);

    while( rc==LSM_OK && lsm_csr_valid(pCsr) && iScan<nScan ){
      const void *p; int n;

      rc = lsm_csr_key(pCsr, &p, &n);
      testOomAssertRc(pOom, rc);
      if( rc==LSM_OK ){
        rc = lsm_csr_value(pCsr, &p, &n);
        testOomAssertRc(pOom, rc);
      }
      if( rc==LSM_OK ){
        rc = xAdvance(pCsr);
        testOomAssertRc(pOom, rc);
      }
      iScan++;
    }

    lsm_csr_close(pCsr);
    *pRc = rc;
  }
}
コード例 #2
0
ファイル: TestLsmMainWindow.cpp プロジェクト: audioprog/lsmdb
void TestLsmMainWindow::on_actionTest1_triggered()
{
    int rc;
    lsm_db *db;

    /* Allocate a new database handle */
    rc = lsm_new(0, &db);
    if( rc!=LSM_OK ) return;

//	rc = lsm_config(db, LSM_CONFIG_PAGE_SIZE,);
//	rc = lsm_config(db, LSM_CONFIG_BLOCK_SIZE, 1024);

    /* Connect the database handle to database "test.db" */
    rc = lsm_open(db, "d:\\test.db");
    if( rc!=LSM_OK ) return;

    lsm_insert(db, "testkey", 7, "testval", 7);
    lsm_insert(db, "testkey", 7, "testval", 7);
    lsm_insert(db, "testkey", 7, "testval", 7);
    lsm_insert(db, "testkey", 7, "testval", 7);

    lsm_cursor* csr;
    rc = lsm_csr_open(db, &csr);

    rc = lsm_csr_seek(csr, "testkey", 7, LSM_SEEK_EQ);
    if( lsm_csr_valid(csr) ) {
        const char *pVal;
        int nVal;

        rc = lsm_csr_value(csr, (const void **)&pVal, &nVal);
        if( rc==LSM_OK ) {
            QString test = QString::fromLatin1(pVal, nVal);
            qDebug(test.toLatin1().constData());
            /* pVal now points to a buffer nVal bytes in size containing the
            ** value associated with database key "b".  */
        }
    }

    lsm_csr_close(csr);

    rc = lsm_close(db);
}
コード例 #3
0
static void testOomFetch(
  OomTest *pOom,
  lsm_db *pDb,
  void *pKey, int nKey,
  void *pVal, int nVal,
  int *pRc
){
  testOomAssertRc(pOom, *pRc);
  if( *pRc==LSM_OK ){
    lsm_cursor *pCsr;
    int rc;

    rc = lsm_csr_open(pDb, &pCsr);
    if( rc==LSM_OK ) rc = lsm_csr_seek(pCsr, pKey, nKey, 0);
    testOomAssertRc(pOom, rc);

    if( rc==LSM_OK ){
      const void *p; int n;
      testOomAssert(pOom, lsm_csr_valid(pCsr));

      rc = lsm_csr_key(pCsr, &p, &n);
      testOomAssertRc(pOom, rc);
      testOomAssert(pOom, rc!=LSM_OK || (n==nKey && memcmp(pKey, p, nKey)==0) );
    }

    if( rc==LSM_OK ){
      const void *p; int n;
      testOomAssert(pOom, lsm_csr_valid(pCsr));

      rc = lsm_csr_value(pCsr, &p, &n);
      testOomAssertRc(pOom, rc);
      testOomAssert(pOom, rc!=LSM_OK || (n==nVal && memcmp(pVal, p, nVal)==0) );
    }

    lsm_csr_close(pCsr);
    *pRc = rc;
  }
}