An Embeddable NoSQL Database Engine |
Tweet |
Follow @unqlite_db |
UnQLite C/C++ API Reference - Execute Jx9 Bytecode Program.
int unqlite_vm_exec(unqlite_vm *pVm);
Execute a compiled Jx9 program.
Description
This routine is used to execute Jx9 bytecode program resulting from successful compilation of the target Jx9 script using one of the compile interfaces such as unqlite_compile() or unqlite_compile_file().
If no output consumer callback were installed, then the virtual machine will automatically redirect its output to an internal buffer. The caller can point to that buffer later when the VM have finished execution of the target program via a call to unqlite_vm_config() with a configuration verb set to UNQLITE_VM_CONFIG_EXTRACT_OUTPUT. But remember, for performance reason it's preferable to install a VM output consumer callback rather than waiting for the VM to finish executing and extracting the output.
Parameters
pVm |
A pointer to a unQLite Virtual Machine. |
Return value
UNQLITE_OK is returned on success. Any other return value typically UNQLITE_CORRUPT indicates failure.
Example
Compile this C file for a smart introduction to this interface.
#define JX9_PROG \
"db_create('users'); /* Create the collection users */"\
" /* Store something */ "\
"db_store('users',{ 'name' : 'dean' , 'age' : 32 });"\
"db_store('users',{ 'name' : 'chems' , 'age' : 27 });"
int rc;
unqlite *pDb;
unqlite_vm *pVm;
// Open our database;
rc = unqlite_open(&pDb,"test.db",UNQLITE_OPEN_CREATE);
if( rc != UNQLITE_OK ){ return; }
// Compile our Jx9 program
rc = unqlite_compile(pDb,JX9_PROG,sizeof(JX9_PROG)-1,&pVm);
if( rc != UNQLITE_OK ){ /* Extract error log here */ return; }
//Configure our VM ...
// Execute our Jx9 program
rc = unqlite_vm_exec(pVm);
if( rc != UNQLITE_OK ){ return; }
// Release our VM
unqlite_vm_release(pVm);
//Auto-commit the transaction and close our handle
unqlite_close(pDb);
See also
unqlite_vm_release, unqlite_vm_config, unqlite_compile.