コード例 #1
0
ファイル: edb.c プロジェクト: zhq324/openbmc
static int
edb_set(char *path, char *key, char *value) {
  unqlite *pDb;               /* Database handle */
  int rc;

  /* Open our database */
  while (1) {
    rc = unqlite_open(&pDb, path, UNQLITE_OPEN_CREATE);
    if( rc != UNQLITE_OK ){
      syslog(LOG_WARNING, "db_set: unqlite_open failed with rc: %d\n", rc);
      rc = -1;
      break;
    }
    rc = unqlite_kv_store(pDb, key, -1, value, MAX_BUF);
    if( rc != UNQLITE_OK ){
      if( rc != UNQLITE_BUSY ){
#ifdef DEBUG
        syslog(LOG_WARNING, "db_set: unqlite_kv_store failed with rc: %d\n", rc);
#endif
        rc = -1;
        break;
      } else {
        unqlite_close(pDb);
        continue;
      }
   } else {
   /* Auto-commit the transaction and close our database */
    rc = 0;
    break;
   }
 }
  unqlite_close(pDb);
  return rc;
}
コード例 #2
0
ファイル: edb.c プロジェクト: zhq324/openbmc
static int
edb_get(char *path, char *key, char *value) {
  int rc;
  unqlite *pDb;
  size_t nBytes;      //Data length
  char zBuf[MAX_BUF] = {0};

  while (1) {
    // Open our database;
    rc = unqlite_open(&pDb, path, UNQLITE_OPEN_READONLY|UNQLITE_OPEN_MMAP);
    if( rc != UNQLITE_OK ) {
      syslog(LOG_WARNING, "db_get: unqlite_open fails with rc: %d\n", rc);
      unqlite_close(pDb);
      return -1;
    }

    //Extract record content
    nBytes = MAX_BUF;
    memset(zBuf, 0, MAX_BUF);
    rc = unqlite_kv_fetch(pDb, key, -1, value, &nBytes);
    if( rc != UNQLITE_OK ){
      if (rc == UNQLITE_NOTFOUND) {
#ifdef DEBUG
        syslog(LOG_WARNING, "db_get: can not find the key\n");
#endif
        unqlite_close(pDb);
        return -1;
      } else {
#ifdef DEBUG
        syslog(LOG_WARNING, "db_get: unqlite_key_fetch returns %d\n", rc);
#endif
        /* Auto-commit the transaction and close our database */
        unqlite_close(pDb);
        continue;
      }
    } else {
      /* Auto-commit the transaction and close our database */
      unqlite_close(pDb);
      return 0;
    }
  }

  return 0;
}
コード例 #3
0
ファイル: wrap_unqlite.c プロジェクト: zhangguof/pyunqlite
static PyObject*
wrap_unqlite_close(PyObject *self, PyObject *args)
{
	int rc;
	struct unqlite* pDb;
	if (!PyArg_ParseTuple(args,"l",&pDb))
		return NULL;
	//printf("0x%08X",pDb);
	rc = unqlite_close(pDb);

	return Py_BuildValue("l",rc);
}
コード例 #4
0
 /* No need for command line arguments, everything is stored in-memory */
int main(void)
{
	unqlite *pDb;       /* Database handle */
	unqlite_vm *pVm;    /* UnQLite VM resulting from successful compilation of the target Jx9 script */
	int rc;

	puts(zBanner);

	/* Open our database */
	rc = unqlite_open(&pDb,":mem:" /* In-mem DB */,UNQLITE_OPEN_CREATE);
	if( rc != UNQLITE_OK ){
		Fatal(0,"Out of memory");
	}
	
	/* Compile our Jx9 script defined above */
	rc = unqlite_compile(pDb,JX9_PROG,sizeof(JX9_PROG)-1,&pVm);
	if( rc != UNQLITE_OK ){
		/* Compile error, extract the compiler error log */
		const char *zBuf;
		int iLen;
		/* Extract error log */
		unqlite_config(pDb,UNQLITE_CONFIG_JX9_ERR_LOG,&zBuf,&iLen);
		if( iLen > 0 ){
			puts(zBuf);
		}
		Fatal(0,"Jx9 compile error");
	}

	/* Install a VM output consumer callback */
	rc = unqlite_vm_config(pVm,UNQLITE_VM_CONFIG_OUTPUT,VmOutputConsumer,0);
	if( rc != UNQLITE_OK ){
		Fatal(pDb,0);
	}
	
	/* Execute our script */
	rc = unqlite_vm_exec(pVm);
	if( rc != UNQLITE_OK ){
		Fatal(pDb,0);
	}

	/* Release our VM */
	unqlite_vm_release(pVm);
	
	/* Auto-commit the transaction and close our database */
	unqlite_close(pDb);
	return 0;
}
コード例 #5
0
ファイル: KVUnqlite.cpp プロジェクト: yulubupt/oss_core
bool KVUnqlite::close()
{
  unqlite* pDbHandle = static_cast<unqlite*>(_pDbHandle);
  if (pDbHandle)
  {
    if (unqlite_close(pDbHandle) == UNQLITE_OK)
    {
      _pDbHandle = 0;
      return true;
    }
    else
    {
      log_error();
      return false;
    }
  }
  return true;
}
コード例 #6
0
ファイル: unqlite_tar.c プロジェクト: Nercury/unqlite
int main(int argc,char *argv[])
{
	int db_extract = 0;          /* TRUE to extract records from the dabase */
	int db_store = 0;            /* TRUE to store files in the database */
	int db_iterate = 0;          /* TRUE to iterate over the inserted elements */
	unqlite *pDb;                /* Database handle */
	int c,i,rc;

	if( argc < 3 ){
		/* Missing database name */
		Help();
	}
	
	c = argv[2][0];
	if( c != '-' ){
		/* Missing command */
		Help();
	}
	c = argv[2][1];
	if( c == 'i' || c == 'I' ){
		/* Iterate over the inserted elements */
		db_iterate = 1;
	}else if( c == 'w' || c == 'W' ){
		/* Store some files */
		db_store = 1;
	}else{
		/* Extract some records */
		db_extract = 1;
	}
	

	/* Open our database */
	rc = unqlite_open(&pDb,argv[1],db_store ? UNQLITE_OPEN_CREATE : (UNQLITE_OPEN_READONLY|UNQLITE_OPEN_MMAP) /* Read-only DB */ );
	if( rc != UNQLITE_OK ){
		Fatal(0,"Out of memory");
	}
	
	if( db_store ){
		void *pMap;          /* Read-only memory view of the target file */
		unqlite_int64 nSize; /* file size */
		
		/* Start the insertion */
		for( i = 3 ; i < argc ; ++i ){
			const char *zFile = argv[i];
			printf("Inserting %s\t ... ",zFile);

			/* Obtain a read-only memory view of the whole file */
			rc = unqlite_util_load_mmaped_file(zFile,&pMap,&nSize);
			if( rc == UNQLITE_OK ){
				/* Store the whole file */
				rc = unqlite_kv_store(pDb,zFile,-1,pMap,nSize);
				/* Discard this view */
				unqlite_util_release_mmaped_file(pMap,nSize);
			}
			puts(rc == UNQLITE_OK ? "OK" : "Fail");
		}
		/* Mnually commit the transaction. 
		 * In fact, a call to unqlite_commit() is not necessary since UnQLite
		 * will automatically commit the transaction during a call to unqlite_close().
		 */
		rc = unqlite_commit(pDb);
		if( rc != UNQLITE_OK ){
			/* Rollback the transaction */
			rc = unqlite_rollback(pDb);
		}
		if( rc != UNQLITE_OK ){
			/* Something goes wrong, extract the database error log and exit */
			Fatal(pDb,0);
		}
	}else if( db_iterate ){
		/* Iterate over the inserted records */
		unqlite_kv_cursor *pCur;
		
		/* Allocate a new cursor instance */
		rc = unqlite_kv_cursor_init(pDb,&pCur);
		if( rc != UNQLITE_OK ){
			Fatal(0,"Out of memory");
		}

		/* Point to the first record */
		unqlite_kv_cursor_first_entry(pCur);
		
		/* Iterate over the entries */
		while( unqlite_kv_cursor_valid_entry(pCur) ){
			unqlite_int64 nDataLen; 
			
			/* Consume the key */
			unqlite_kv_cursor_key_callback(pCur,DataConsumerCallback,0);
			
			/* Extract the data size */
			unqlite_kv_cursor_data(pCur,0,&nDataLen);
			printf(":\t %ld Bytes\n",nDataLen);
			/* unqlite_kv_cursor_data_callback(pCur,DataConsumerCallback,0); */

			/* Point to the next entry */
			unqlite_kv_cursor_next_entry(pCur);
		}
		/* Finally, Release our cursor */
		unqlite_kv_cursor_release(pDb,pCur);
	}else{
		/* Extract one more records */
		for( i = 3 ; i < argc ; ++i ){
			const char *zFile = argv[i];
			rc = unqlite_kv_fetch_callback(pDb,zFile,-1,DataConsumerCallback,0);
			if( rc == UNQLITE_NOTFOUND ){
				printf("No such record: %s\n",zFile);
			}
		}
	}

	/* All done, close our database */
	unqlite_close(pDb);
	return 0;
}
コード例 #7
0
ファイル: 3.c プロジェクト: Nercury/unqlite
int main(int argc,char *argv[])
{
	unqlite *pDb;               /* Database handle */
	unqlite_kv_cursor *pCur;    /* Cursor handle */
	char zKey[14];              /* Random generated key */
	char zData[32];             /* Dummy data */
	int i,rc;

	puts(zBanner);

	/* Open our database */
	rc = unqlite_open(&pDb,argc > 1 ? argv[1] /* On-disk DB */ : ":mem:" /* In-mem DB */,UNQLITE_OPEN_CREATE);
	if( rc != UNQLITE_OK ){
		Fatal(0,"Out of memory");
	}
	
	printf("Starting insertions of %d random records...\n",MAX_RECORDS);
	
	/* Start the random insertions */
	for( i = 0 ; i < MAX_RECORDS; ++i ){
		
		/* Genearte the random key first */
		unqlite_util_random_string(pDb,zKey,sizeof(zKey));

		/* Perform the insertion */
		rc = unqlite_kv_store(pDb,zKey,sizeof(zKey),zData,sizeof(zData));
		if( rc != UNQLITE_OK ){
			/* Something goes wrong */
			break;
		}
	}
	if( rc != UNQLITE_OK ){
		/* Something goes wrong, extract the database error log and exit */
		Fatal(pDb,0);
	}
	puts("Done...Starting the iteration process");

	/* Allocate a new cursor instance */
	rc = unqlite_kv_cursor_init(pDb,&pCur);
	if( rc != UNQLITE_OK ){
		Fatal(0,"Out of memory");
	}
	/* Point to the first record */
	unqlite_kv_cursor_first_entry(pCur);
	/* To point to the last record instead of the first, simply call [unqlite_kv_cursor_last_entry()] as follows */
	
	/* unqlite_kv_cursor_last_entry(pCur); */
		
	/* Iterate over the entries */
	while( unqlite_kv_cursor_valid_entry(pCur) ){
		int nKeyLen;
		/* unqlite_int64 nDataLen; */
		
		/* Consume the key */
		unqlite_kv_cursor_key(pCur,0,&nKeyLen); /* Extract key length */
		printf("\nKey ==> %u\n\t",nKeyLen);
		unqlite_kv_cursor_key_callback(pCur,DataConsumerCallback,0);
			
		/* Consume the data */
		/*
		unqlite_kv_cursor_data(pCur,0,&nDataLen);
		printf("\nData ==> %lld\n\t",nDataLen);
		unqlite_kv_cursor_data_callback(pCur,DataConsumerCallback,0);
		*/


		/* Point to the next entry */
		unqlite_kv_cursor_next_entry(pCur);

		/*unqlite_kv_cursor_prev_entry(pCur); //If [unqlite_kv_cursor_last_entry(pCur)] instead of [unqlite_kv_cursor_first_entry(pCur)] */
	}
	/* Finally, Release our cursor */
	unqlite_kv_cursor_release(pDb,pCur);
	
	/* Auto-commit the transaction and close our database */
	unqlite_close(pDb);
	return 0;
}
コード例 #8
0
ファイル: newfs.c プロジェクト: cac23/fuse-fs-implementation
void shutdown_fs(){
    write_log("shutdown_fs: shutting down file system\n");
    unqlite_close(pDb);
}
コード例 #9
0
ファイル: 2.c プロジェクト: Nercury/unqlite
/* No need for command line arguments, everything is stored in-memory */
int main(void)
{
    unqlite *pDb;       /* Database handle */
    unqlite_vm *pVm;    /* UnQLite VM resulting from successful compilation of the target Jx9 script */
    int rc;

    puts(zBanner);

    /* Open our database */
    rc = unqlite_open(&pDb,":mem:" /* In-mem DB */,UNQLITE_OPEN_CREATE);
    if( rc != UNQLITE_OK ) {
        Fatal(0,"Out of memory");
    }

    /* Compile our Jx9 script defined above */
    rc = unqlite_compile(pDb,JX9_PROG,sizeof(JX9_PROG)-1,&pVm);
    if( rc != UNQLITE_OK ) {
        /* Compile error, extract the compiler error log */
        const char *zBuf;
        int iLen;
        /* Extract error log */
        unqlite_config(pDb,UNQLITE_CONFIG_JX9_ERR_LOG,&zBuf,&iLen);
        if( iLen > 0 ) {
            puts(zBuf);
        }
        Fatal(0,"Jx9 compile error");
    }

    /* Now we have our program compiled, it's time to register our constants
     * and their associated C procedure.
     */
    rc = unqlite_create_constant(pVm, "__PI__", PI_Constant, 0);
    if( rc != UNQLITE_OK ) {
        Fatal(0,"Error while installing the __PI__ constant");
    }

    rc = unqlite_create_constant(pVm, "__TIME__", TIME_Constant, 0);
    if( rc != UNQLITE_OK ) {
        Fatal(0,"Error while installing the __TIME__ constant");
    }

    rc = unqlite_create_constant(pVm, "__OS__", OS_Constant, 0);
    if( rc != UNQLITE_OK ) {
        Fatal(0,"Error while installing the __OS__ constant");
    }

    /* Install a VM output consumer callback */
    rc = unqlite_vm_config(pVm,UNQLITE_VM_CONFIG_OUTPUT,VmOutputConsumer,0);
    if( rc != UNQLITE_OK ) {
        Fatal(pDb,0);
    }

    /* Execute our script */
    rc = unqlite_vm_exec(pVm);
    if( rc != UNQLITE_OK ) {
        Fatal(pDb,0);
    }

    /* Release our VM */
    unqlite_vm_release(pVm);

    /* Auto-commit the transaction and close our database */
    unqlite_close(pDb);
    return 0;
}
コード例 #10
0
ファイル: storage_unqlite.cpp プロジェクト: KDE/sink
Storage::Private::~Private()
{
    unqlite_close(db);
}