char * extract_unqlite_log_error(unqlite *pDb) { /*This function will return the number of chars at the error message If there is no error message than 0 is returned */ int length; char *buffer; //Extract the errror if exists unqlite_config(pDb,UNQLITE_CONFIG_JX9_ERR_LOG,&buffer,&length); return buffer; }
void UnqliteException::AppendLogError(unqlite* pDB, bool compiler_log) { if (pDB) { int error_text_len = 0; int nOp = compiler_log ? UNQLITE_CONFIG_JX9_ERR_LOG : UNQLITE_CONFIG_ERR_LOG; int rc = unqlite_config(pDB, nOp, 0, &error_text_len); if ( rc == UNQLITE_OK && error_text_len > 0 ) { std::string log_message(error_text_len + 1, '\0'); rc = unqlite_config(pDB, UNQLITE_CONFIG_ERR_LOG, &log_message[0], &error_text_len); if (rc == UNQLITE_OK) { this->_error_text += '\n'; this->_error_text += log_message; } } } }
void KVUnqlite::log_error() { unqlite* pDbHandle = static_cast<unqlite*>(_pDbHandle); if (!pDbHandle) return; const char *zBuf = 0; int iLen; unqlite_config(pDbHandle,UNQLITE_CONFIG_ERR_LOG,&zBuf,&iLen); if( iLen > 0 ) { OSS_LOG_ERROR("KVUnqlite Exception: " << zBuf); } }
void Storage::Private::reportDbError(const char *functionName) { std::cerr << "ERROR: " << functionName; if (db) { const char *errorMessage; int length; /* Something goes wrong, extract database error log */ unqlite_config(db, UNQLITE_CONFIG_ERR_LOG, &errorMessage, &length); if (length > 0) { std::cerr << ": " << errorMessage; } } std::cerr << std::endl; }
static PyObject* wrap_unqlite_compile(PyObject *self, PyObject *args) { int rc; struct unqlite_vm *pVm; struct unqlite *pDb; const char* jx9_prog; int prog_len; if (!PyArg_ParseTuple(args,"lsl",&pDb,&jx9_prog,&prog_len)) return NULL; rc = unqlite_compile(pDb,jx9_prog,prog_len,&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"); } //printf("unqlite compile ok.\n"); /* 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 Py_None; }
/* 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; }
void Storage::Private::reportDbError(const char *functionName, int errorCode, const std::function<void(const Storage::Error &error)> &errorHandler) { if (db) { const char *errorMessage; int length; /* Something goes wrong, extract database error log */ unqlite_config(db, UNQLITE_CONFIG_ERR_LOG, &errorMessage, &length); if (length > 0) { Error error(name.toStdString(), errorCode, errorMessage); errorHandler(error); return; } } Error error(name.toStdString(), errorCode, functionName); errorHandler(error); }
static void Fatal(unqlite *pDb,const char *zMsg) { if( pDb ){ const char *zErr; int iLen = 0; /* Stupid cc warning */ /* Extract the database error log */ unqlite_config(pDb,UNQLITE_CONFIG_ERR_LOG,&zErr,&iLen); if( iLen > 0 ){ /* Output the DB error log */ puts(zErr); /* Always null termniated */ } }else{ if( zMsg ){ puts(zMsg); } } /* Manually shutdown the library */ unqlite_lib_shutdown(); /* Exit immediately */ exit(0); }
Producer::Config::Config( const string& file, uint32_t id ) { // set default values prefix = Name("unnamed"); sigverif_delay = NanoSeconds( 30345 ); bloom_delay = NanoSeconds( 2535 ); // database and vm structs unqlite* db; unqlite_vm* vm; // initialize database int rc = unqlite_open( &db, ":mem:", UNQLITE_OPEN_READONLY ); if( rc != UNQLITE_OK ) { // something went wrong const char* err; int errlen; unqlite_config( db, UNQLITE_CONFIG_JX9_ERR_LOG, &err, &errlen ); cout << "Error: creating unqlite database: " << err << endl; exit(1); } // initialize unqlite vm rc = unqlite_compile_file( db, file.c_str(), &vm ); if( rc != UNQLITE_OK ) { // something went wrong const char* err; int errlen; unqlite_config( db, UNQLITE_CONFIG_JX9_ERR_LOG, &err, &errlen ); cout << "Error: compiling config script: " << err << endl; exit(1); } unqlite_value* id_val = unqlite_vm_new_scalar( vm ); unqlite_value_int64( id_val, id ); rc = unqlite_vm_config( vm, UNQLITE_VM_CONFIG_CREATE_VAR, "ID", id_val ); if( rc != UNQLITE_OK ) { // something went wrong const char* err; int errlen; unqlite_config( db, UNQLITE_CONFIG_JX9_ERR_LOG, &err, &errlen ); cout << "Error: exporting ID to config: " << err << endl; exit(1); } unqlite_vm_release_value( vm, id_val ); // execute config script rc = unqlite_vm_exec( vm ); if( rc != UNQLITE_OK ) { // something went wrong const char* err; int errlen; unqlite_config( db, UNQLITE_CONFIG_JX9_ERR_LOG, &err, &errlen ); cout << "Error: executing config script: " << err << endl; exit(1); } // retrieve config values const char* str; int len; unqlite_value* val; val = unqlite_vm_extract_variable( vm, "prefix" ); if( val ) { str = unqlite_value_to_string( val, &len ); prefix = string(str, len ); } val = unqlite_vm_extract_variable( vm, "sigverif_delay" ); if( unqlite_value_is_float( val ) ) sigverif_delay = Seconds( unqlite_value_to_double( val ) ); if( unqlite_value_is_int( val ) ) sigverif_delay = Seconds( unqlite_value_to_int64( val ) ); val = unqlite_vm_extract_variable( vm, "bloom_delay" ); if( unqlite_value_is_float( val ) ) bloom_delay = Seconds( unqlite_value_to_double( val ) ); if( unqlite_value_is_int( val ) ) bloom_delay = Seconds( unqlite_value_to_int64( val ) ); val = unqlite_vm_extract_variable( vm, "contents" ); if( val && unqlite_value_is_json_array( val ) ) { size_t count = unqlite_array_count( val ); for( size_t i = 0 ; i < count ; i++ ) { stringstream ss; string key; ss << i; ss >> key; unqlite_value* elem = unqlite_array_fetch ( val, key.c_str(), key.size() ); if( elem && unqlite_value_is_json_object( elem ) ) { unqlite_value* name_val = unqlite_array_fetch ( elem, "name", -1 ); unqlite_value* size_val = unqlite_array_fetch ( elem, "size", -1 ); unqlite_value* access_val = unqlite_array_fetch( elem, "access_level", -1 ); if( name_val && size_val && access_val && unqlite_value_is_string( name_val ) && unqlite_value_is_int( size_val ) && unqlite_value_is_int( access_val ) ) { str = unqlite_value_to_string( name_val, &len ); size_t size = unqlite_value_to_int( size_val ); uint8_t access_level = unqlite_value_to_int ( access_val ); contents.emplace( string( str, len ), Config::Content { size, access_level } ); } } } }
/* 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; }