How to build sqlite VFS into the library - sqlite

I am trying to compile SQLite into a library which another application is then going to link against. I am not able to compile SQLite directly into that application for reasons which are beyond the scope of this question.
However, I need a VFS to be available which by default is not. In trying to figure out how to get this working I am trying to get the vfstrace shim to be made available to the application which is linking to SQLite. This will easily prove that it is working as I can log SQLite VFS activity from the shim and see that it is actually being used when the application calls SQLite.
How do I do this? All the examples I have found show the case of when you have a source file (such as shell.c) and you compile it, sqlite3.c and test_vfstrace.c to produce an executable. However, I do not have this luxury. I could compile sqlite.c and test_vfstrace.c and generate the libsqlite3.so library file, but there is no "main" function in which to call vfstrace_register so that the VFS is actually available. Is there some other hook for the library case where I can set this up? If no, how do I make a new VFS available?

SQLite is initialized via the sqlite3_initialize() function, which is called automatically when various functions such as sqlite3_open() are called by the user, although it is a no-op on subsequent invocations. This function in turn calls the OS specific initialization function sqlite3_os_init(). This is the function that initializes all the VFSes that are built into SQLite.
For the example VFS given, append test_vfstrace.c to the amalgamation and then put a call like this in sqlite3_os_init() right before the return statement:
vfstrace_register("trace",0,(int(*)(const char*,void*))fputs,stderr,1);
Then build the library with these modifications.
The last parameter's value of 1 will make this VFS be the default, so if you don't want trace messages printed for every SQLite operation performed via code linked the library you just created change this to 0 and explicitly specify this VFS when opening a database to trace the calls for. For instance, specify the SQLITE_USE_URI compile time option, and then pass a filename of the form: "file:database.db?vfs=unix" where "database.db" is the actual name of the file to open.

Related

The transaction currently built is missing an attachment for class - Attempted to find a suitable attachment but could not find any in the storage

Full Error:
transactions.TransactionBuilder. - The transaction currently built is missing an attachment for class: com/gibtn/corda/printutilities/PrintLedgerTransaction. Attempted to find a suitable attachment but could not find any in the storage.
This has been asked here and here but I hope to get better clarification.
Problem:
I have built a set of libraries to perform common tasks in my Flows that I include in all my CorDapps. For now I just copy the JARs into each project, make some changes to the gradle files and everything works great.
I recently put together a small library for performing common tasks in Contracts and added the JAR the same way.
This works fine with MockNodes. But when I test with real nodes I will get this error in the CRaSH shell and the transaction will fail with a NoClassDefFoundError exception.
Question:
Is what I am doing even possible? Or do I always have to keep my utility classes inside the Contracts module in IntelliJ so they are bundled together with the Contracts into a single JAR? That way when the node starts the JAR (containing the Contracts and any utilities) is added to Attachment storage as a single Attachment.
I found a way to solve this. It's a bit dirty but initial testing seems to work. I just created a blank class in my utilities JAR that implements Contract. It's verify() method is empty. Now when the Corda node starts it sees this Contract and adds the JAR to Attachment storage. So from the CRaSH shell if I run:
attachments trustInfo
...my utility JAR will be listed (it wasn't before). I see when I use one of the utility methods in a Contract the utility JAR will be included as a separate Attachment in the WireTransaction.
I'm not crazy about this solution and will probably stop using a utility JAR for Contracts. I'll go back to copying the classes into each project. Nevertheless there is a way to do it. I would just need a more experienced Corda developer to give it their blessing before I'd go forward into production with it.

Does rocksdbjava api library contain the rocksdb database itself

I am very new to rockdb and will be using the rocksdb in my application as a lookup service. Does the rockDBjava library api provided contain the database itself, I mean is it not necessary to install rocksDB database separately.
I tried running the code using library and see some files created in the db path I mentioned in code, so not sure how exactly it works and if I need to install DB separately or if the library stores data in the directory and it itself acts as database?
No, you should not need to install RocksDB separately if you already have RocksJava working. They're not very clear on stating that, but if you look at the wiki in their Git repo you'll find this:
RocksJava is structured in 3 layers:
The Java classes within the org.rocksdb package which form the
RocksJava API. Java users only directly interact with this layer.
JNI code written in C++ that provides the link between the Java API
and RocksDB.
RocksDB itself written in C++ and compiled into a native library which
is used by the JNI layer.
That third point is basically their way of saying that RocksDB itself is one of the layers of RocksJava.

What FIRApp.deleteApp does and when should I use it?

The iOS SDK of Firebase provides the function FIRApp.deleteApp which, according to the documentation:
Cleans up the current FIRApp, freeing associated data and returning its name to the pool for future use.
A similar function is available in the JavaScript SDK but not in the Java or C++ ones.
What this function does and when should I use it?
My understanding is that this function works as a destructor and thus I am supposed to call it when my app is closing. Is it correct? Should I call it on FIRApp.defaultApp too?
A FIRApp object contains references to the configuration data of your Firebase project. It is a lightweight object, mostly using a bit of memory keep those settings available when your application needs them.
Most applications create only a single FIRApp instance for the entire duration of their lifecycle. In such cases the resources will be automatically released when the application exists, and there is no need to explicitly delete the FIRApp instance.

WinDBG - Symbols path not included

I am trying to trace a possible memory leak in a very large ASP.NET application. I am trying to familiarize myself with WinDBG before attempting to use this tool in the live environment.
I have followed the instructions in the following article, which I found very helpful: http://humblecoder.co.uk/uncategorized/spotting-a-memory-leak-with-windbg-in-net. I am able to create a "memory dump" file of the ASP.NET process and show that the delegate is causing the memory leak as specified in the article. I refer to the paragraph in the article that starts: "Next we need the symbols". I did not add the symbol files using File\Symbol File Path; in WinDBG and yet I still seem to be able to debug the application and follow through the remaining steps of the article. Are symbol paths not required with an ASP.NET application?
Because .NET assemblies contain metadata, including the name of every method and its parameters, symbols aren't necessary to obtain a readable stack trace of a managed thread.
One thing symbols can provide is the file name and line number of each statement, so you can more easily figure out which frames in the stack trace correspond to which lines in your source code.
As Michael says symbols are not strictly necessary for managed code as most of the relevant information is available at runtime as metadata, but if you're digging into native code it is very useful to have symbols.
For many scenarios you can just do .symfix which will tell WinDbg to use Microsoft's public symbol server. That will give you access to symbols for all the CLR and Win32 specific calls in your code. Remember to do a .reload if you set the path.
If your code includes native non-Microsoft assemblies as well, you need to append the location of the corresponding PDB files to the symbol path. Use the .sympath command for that.
To troubleshoot symbol loading use the !sym noisy command.
For more information see this.

How to run a VBScript in a Qt application without involving cscript.exe or wscript.exe?

I am writing a Qt application that calls QProcess::startDetached("wscript.exe script.vbs") to show the delete confirmation dialog in Windows.
this is the script:
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("-")
Set objFolderItem = objFolder.ParseName("-")
objFolderItem.InvokeVerb("Delete")
the arguments for Namespace and ParseName are from the arguments passed to the script.
This may be inefficient because it opens an external application first before running the script. I was wondering if i can run VBScripts in a Qt application.
If not, what alternatives can i do?
My VBScript is very weak, so I'm not 100% sure I understand what you are trying to do. My assumption is that you are trying to delete a folder, but want to give the user the normal confirmation box and animation while the action is occurring. If that is not correct, please let me know and I will remove this answer.
A few ideas:
You could call the Windows API directory within your C++ code to do this. I believe the correct call would be to use IFileOperation (Vista and later) or SHFileOperation (pre-Vista)
Qt already has message box dialogs. Although you might not get the exact same functionality as the native shell, you could use this (QMessageBox::warning) and then delete the folder using QDir. This would also be cross-platform portable.
If you stick with the VBScript, I doubt you would see any performance issues unless this is being called many, many times in a loop or something. You know, the old "premature optimization is the root of all evil" thing.
You should read up on the IActiveScript COM interface. You can create an instance of an interpreter that implements IActiveScript to provide a runtime for evaluating scripts. VBScript and JScript can both be used for this and a number of other third-party scripting languages also provide IActiveScript support.
The overview for working with this is you create a language runtime (an instance of VBScript for instance) then add some custom objects to it. Typically if you are embedding an interpreter into your application then exposing an Application object is a good place to start. This can be just an IDispatch interface or something more concrete with an IDL generated typelibrary and all the trimmings. Once you have added the necessary named items into the runtime you load one or more scripts. Any public functions or subroutines declared in the scripts now get exposed via the IDispatch interface of the live runtime once you switch its state to active or running. To actually run the script program, I invoke the Main function for my stuff - you could choose some other scheme as applicable to your environment.
The nice thing about ActiveScripting, is to change language you just change the runtime CLSID. So if people prefer Perl they can use PerlScript or PythonScript etc. Your Application object remains the same hence you don't have to write additional code to support the new languages. The only requirement is that everything is COM.

Resources