コード例 #1
0
/*
** Set up a database file with the following properties:
**
**   * Page size is 1024 bytes.
**   * Block size is 64 KB.
**   * Contains 5000 key-value pairs starting at 0 from the
**     datasource returned getDatasource().
*/
static void setup_populate_db2(){
  Datasource *pData;
  int ii;
  int rc;
  int nBlocksize = 64*1024;
  int nPagesize = 1024;
  int nWritebuffer = 4*1024;
  lsm_db *pDb;

  testDeleteLsmdb(LSMTEST6_TESTDB);
  rc = lsm_new(tdb_lsm_env(), &pDb);
  if( rc==LSM_OK ) rc = lsm_open(pDb, LSMTEST6_TESTDB);

  lsm_config(pDb, LSM_CONFIG_BLOCK_SIZE, &nBlocksize); 
  lsm_config(pDb, LSM_CONFIG_PAGE_SIZE, &nPagesize); 
  lsm_config(pDb, LSM_CONFIG_AUTOFLUSH, &nWritebuffer); 

  pData = getDatasource();
  for(ii=0; rc==LSM_OK && ii<5000; ii++){
    void *pKey; int nKey;
    void *pVal; int nVal;
    testDatasourceEntry(pData, ii, &pKey, &nKey, &pVal, &nVal);
    lsm_insert(pDb, pKey, nKey, pVal, nVal);
  }
  testDatasourceFree(pData);
  lsm_close(pDb);

  testSaveDb(LSMTEST6_TESTDB, "log");
  assert( rc==LSM_OK );
}
コード例 #2
0
/*
** Create a small database. With the following content:
**
**    "one"   -> "one"
**    "two"   -> "four"
**    "three" -> "nine"
**    "four"  -> "sixteen"
**    "five"  -> "twentyfive"
**    "six"   -> "thirtysix"
**    "seven" -> "fourtynine"
**    "eight" -> "sixtyfour"
*/
static void setup_populate_db(){
  const char *azStr[] = {
    "one",   "one",
    "two",   "four",
    "three", "nine",
    "four",  "sixteen",
    "five",  "twentyfive",
    "six",   "thirtysix",
    "seven", "fourtynine",
    "eight", "sixtyfour",
  };
  int rc;
  int ii;
  lsm_db *pDb;

  testDeleteLsmdb(LSMTEST6_TESTDB);

  rc = lsm_new(tdb_lsm_env(), &pDb);
  if( rc==LSM_OK ) rc = lsm_open(pDb, LSMTEST6_TESTDB);

  for(ii=0; rc==LSM_OK && ii<ArraySize(azStr); ii+=2){
    rc = lsmWriteStr(pDb, azStr[ii], azStr[ii+1]);
  }
  lsm_close(pDb);

  testSaveDb(LSMTEST6_TESTDB, "log");
  assert( rc==LSM_OK );
}
コード例 #3
0
/*
** Test the results of OOM conditions in lsm_new().
*/
static void simple_oom_1(OomTest *pOom){
  int rc;
  lsm_db *pDb;

  rc = lsm_new(tdb_lsm_env(), &pDb);
  testOomAssertRc(pOom, rc);

  lsm_close(pDb);
}
コード例 #4
0
/*
** Test the results of OOM conditions in lsm_open().
*/
static void simple_oom_2(OomTest *pOom){
  int rc;
  lsm_db *pDb;

  rc = lsm_new(tdb_lsm_env(), &pDb);
  if( rc==LSM_OK ){
    rc = lsm_open(pDb, "testdb.lsm");
  }
  testOomAssertRc(pOom, rc);

  lsm_close(pDb);
}
コード例 #5
0
static void testOomOpen(
  OomTest *pOom,
  const char *zName,
  lsm_db **ppDb,
  int *pRc
){
  if( *pRc==LSM_OK ){
    int rc;
    rc = lsm_new(tdb_lsm_env(), ppDb);
    if( rc==LSM_OK ) rc = lsm_open(*ppDb, zName);
    testOomAssertRc(pOom, rc);
    *pRc = rc;
  }
}
コード例 #6
0
ファイル: lsmtest7.c プロジェクト: HongliYu/firefox-ios
static lsm_db *newLsmConnection(
  const char *zDb, 
  int nPgsz, 
  int nBlksz,
  int *pRc
){
  lsm_db *db = 0;
  if( *pRc==0 ){
    int n1 = nPgsz;
    int n2 = nBlksz;
    *pRc = lsm_new(tdb_lsm_env(), &db);
    if( *pRc==0 ){
      if( n1 ) lsm_config(db, LSM_CONFIG_PAGE_SIZE, &n1);
      if( n2 ) lsm_config(db, LSM_CONFIG_BLOCK_SIZE, &n2);
      *pRc = lsm_open(db, "testdb.lsm");
    }
  }
  return db;
}
コード例 #7
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);
}
コード例 #8
0
ファイル: lsm_vtab.c プロジェクト: likema/sqlcipher
/*
** The lsm1Connect() method is invoked to create a new
** lsm1_vtab that describes the virtual table.
*/
static int lsm1Connect(
  sqlite3 *db,
  void *pAux,
  int argc, const char *const*argv,
  sqlite3_vtab **ppVtab,
  char **pzErr
){
  lsm1_vtab *pNew;
  int rc;
  char *zFilename;

  if( argc!=4 || argv[3]==0 || argv[3][0]==0 ){
    *pzErr = sqlite3_mprintf("filename argument missing");
    return SQLITE_ERROR;
  }
  *ppVtab = sqlite3_malloc( sizeof(*pNew) );
  pNew = (lsm1_vtab*)*ppVtab;
  if( pNew==0 ){
    return SQLITE_NOMEM;
  }
  memset(pNew, 0, sizeof(*pNew));
  rc = lsm_new(0, &pNew->pDb);
  if( rc ){
    *pzErr = sqlite3_mprintf("lsm_new failed with error code %d",  rc);
    rc = SQLITE_ERROR;
    goto connect_failed;
  }
  zFilename = sqlite3_mprintf("%s", argv[3]);
  lsm1Dequote(zFilename);
  rc = lsm_open(pNew->pDb, zFilename);
  sqlite3_free(zFilename);
  if( rc ){
    *pzErr = sqlite3_mprintf("lsm_open failed with %d", rc);
    rc = SQLITE_ERROR;
    goto connect_failed;
  }

/* Column numbers */
#define LSM1_COLUMN_KEY         0
#define LSM1_COLUMN_BLOBKEY     1
#define LSM1_COLUMN_VALUE       2
#define LSM1_COLUMN_BLOBVALUE   3
#define LSM1_COLUMN_COMMAND     4

  rc = sqlite3_declare_vtab(db,
     "CREATE TABLE x("
     "  key,"              /* The primary key.  Any non-NULL */
     "  blobkey,"          /* Pure BLOB primary key */
     "  value,"            /* The value associated with key.  Any non-NULL */
     "  blobvalue,"        /* Pure BLOB value */
     "  command hidden"    /* Insert here for control operations */
     ");"
  );
connect_failed:
  if( rc!=SQLITE_OK ){
    if( pNew ){
      if( pNew->pDb ) lsm_close(pNew->pDb);
      sqlite3_free(pNew);
    }
    *ppVtab = 0;
  }
  return rc;
}