##- # Author: Brian Tiffin # Dedicated to the public domain # # Date: December, 2016 # Modified: 2016-12-03/22:21-0500 ##+ # # uniunql-v1.icn, Embed UnQLite in Unicon # # tectonics: # gcc -o uniunql-v1.so -shared -fpic uniunql-vi.c unqlite.c # procedure main() uniunql := loadfunc("./uniunql-v1.so", "uniunql") program := "/* Create the collection 'users' */\n_ if( !db_exists('users') ){\n_ /* Try to create it */\n_ $rc = db_create('users');\n_ if ( !$rc ){\n_ /*Handle error*/\n_ print db_errlog();\n_ return;\n_ }else{\n_ print \"Collection 'users' successfuly created\n\";\n_ }\n_ }\n_ /*The following is the records to be stored shortly in our collection*/ \n_ $zRec = [\n_ {\n_ name : 'james',\n_ age : 27,\n_ mail : 'dude@example.com'\n_ },\n_ {\n_ name : 'robert',\n_ age : 35,\n_ mail : 'rob@example.com'\n_ },\n_ {\n_ name : 'monji',\n_ age : 47,\n_ mail : 'monji@example.com'\n_ },\n_ {\n_ name : 'barzini',\n_ age : 52,\n_ mail : 'barz@mobster.com'\n_ }\n_ ];\n_ /*Store our records*/\n_ $rc = db_store('users',$zRec);\n_ if( !$rc ){\n_ /*Handle error*/\n_ print db_errlog();\n_ return;\n_ }\n_ /*Create our filter callback*/\n_ $zCallback = function($rec){\n_ /*Allow only users >= 30 years old.*/\n_ if( $rec.age < 30 ){\n_ /* Discard this record*/\n_ return FALSE;\n_ }\n_ /* Record correspond to our criteria*/\n_ return TRUE;\n_ }; /* Dont forget the semi-colon here*/\n_ /* Retrieve collection records and apply our filter callback*/\n_ $data = db_fetch_all('users',$zCallback);\n_ print \"Filtered records\n\";\n_ /*Iterate over the extracted elements*/\n_ foreach($data as $value){ /*JSON array holding the filtered records*/\n_ print $value..JX9_EOL;\n_ }" result := uniunql(":mem:", program) write("Unicon result: ", result) end