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; }
VirtualMachine::~VirtualMachine() { if (m_pVm) { unqlite_vm_release(m_pVm); } }
/* 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; }