System.Data.SQLite in UNMANAGED C++ - sqlite

I want to use SQLite as a database for my C++ project. I also need the ability to password protect the database. I got the standard SQLite from SQLite.org working - but I need to password/encrypt the database and they don't do that - they just stub the interface for it to be done with
SQLITE_API int sqlite3_key( sqlite3 *db, const void *pKey, int nKey);
After researching on the web how to do this, I came across System.Data.SQLite. It claims to do all I need quite easily, but I need to do it from unmanaged C++ project in Visual Studio 2008. I tried their project - but I can't get my unmanaged C++ project to allow the DLL to work - it squawks about dll not being safe/clr:safe compile - which I can't set in the System.Data.SQLite project and compile.
Can anyone help me with this or point me to a good resource on how to do this? I have been thrown into a C++ project (hadn't touched C/C++ since college (97-98), so I am really struggling with this when it comes to the linker/libs/modules. Java and .NET have spoiled me!
Thanks,
Mike

You can't use a managed DLL from unmanaged code like that, they're different systems. Just use the normal unmanaged SQLite build and read the docs on how to use keys.

Recently, I've faced a similar problem like Mike and resolved it.
I would like to post my solution here in case anyone need.
I have two programs:
One is in C# to create encrypted sqlite database files using System.Data.SQLite.
The other one is in C++ to read the file created by the C# program.
After googling with no result, I looked at source code of System.Data.SQLite to figured out how System.Data.SQLite encrypts a database file.
I recognized that System.Data.SQLite uses SQLite.Interop.dll wrapping native sqlite with additional features such as encryption.
Therefore I used that native source code to build a static library. Then I use the library to read the encrypted database files.
You can find the source code at the following link:
https://github.com/OpenDataSpace/System.Data.SQLite/tree/master/SQLite.Interop/src
Update 2020/04/11
You can find a step by step guide at the following link:
https://wordpress.com/post/nguyenduyanhsite.wordpress.com/71

Related

MvvmCross, SQLite, Store App?

I can get MvvmCross working with a Windows 8.0 Store App.
I can get SQLite working with a different Windows 8.0 Store App.
I cannot figure out how to get MvvmCross + SQLite working on a Store app.
I always get this Exception:
Failed to construct and initialize ViewModel for type Flux.Core.ViewModels.TestViewModel from locator MvxDefaultViewModelLocator - check MvxTrace for more information
I've spent the entire day searching with google, hoping to solve this myself. The KittenDb example is about as close as I've come, but there's no Store app example in there. (I got the Kitten example working no problem on Android.)
Is there any working example out there?
Thanks!
SQLite for Windows Store is a C++ component and comes in separate ARM, x86 and x64 binaries.
To install it, you need to add a Visual Studio extension - instructions in http://blogs.msdn.com/b/robertgreen/archive/2012/11/13/using-sqlite-in-windows-store-apps.aspx - and then reference that extension from your UI project.
To then link the correct platform version of the Cirrious.MvvmCross.Plugins.Sqlite.WindowsStore.dll assembly to your UI project, you further need to adapt your .csproj file with a <Choose> block a bit like the one in https://nuget.codeplex.com/discussions/446656
There is an open issue within MvvmCross to make SQLite easier to use from nuget (see https://github.com/MvvmCross/MvvmCross/issues/307) but I don't know if anyone is actively working on addressing this issue currently - currently users seem to be just putting up with challenges of different processor architectures and following the manual steps to adapt their projects.

Looking for working SQLLite.Data and interop dll with compact framework on windows mobile 6

Can anyone provide me, working DLL for sqllite on compact framework,
From the forum i found, that some build has error for compact framework, and i am unable to compile c and c++ binary.
So it will be great if some one provide me working dll of SQLlite.data and SQLite.Interop.
Thanks in advance.
I use SQLite in one of the OpenNETCF ORM implementations and it gets tested on WinMo, so SQLite.Interop.dll and System.Data.SQLite.dll in the source code there (look under OpenNETCF.ORM.SQLite\references\CF35).

java.lang.UnsatisfiedLinkError: no db_java-4.2 in java.library.path

I'm trying to access a Berkeley DB database file (say Test.db) from the java code and then want to read all the pairs from it. I'm using the com.sleepycat.db.* and com.sleepycat.bdb.* packages ( NOTE: Not Oracle Berkeley DB JE )to do this task. For the implementation, I did exactly as described in this BerkeleyDB Java API Tutorial
So, when I run this project from eclipse I got this error
Exception in thread "main" java.lang.UnsatisfiedLinkError: no db_java-4.2 in java.library.path
and from the stack trace, source for this exception occured from this line
env = new DbEnv(0);
I tried to set it from the java command
$java -D<name>=<value>
but still it didn't work.
My goal is to export this project into a jar file and use it to read BDBs anywhere . Anyone who knows how to get out of this, I appreciate your help. It would be great if I can be redirected to any working tutorial for accessing Berkeley DBs from java code too. Thanks !!
SOLUTION: After a lot of work, I found out that the Sleepycat API that I'm working on is using native libraries that are written in C/C++ through the JNI. Berkeley DB that is installed on my PC didn't have the shared object file db_java-4.2 (to be accurate, file name is libdb_java-4.2) which means that this BDB is not configured for java APIs.
So, the solution is to start the installation of BDB from scratch again by enabling the java configuration.
I had the same problem.
Like kK_Pulla mentioned, the sleepycat API using native libraries written in C/C++ through the Java Native Interface. So making Sleepycat API calls means the java code is ultimately going to call compiled C/C++ code.
If you are getting the "java.lang.UnsatisfiedLinkError: no db_java-4.2 in java.library.path" error then it is likely that, at least it was in my case, you have not included the relevant native libraries in your project.
I would describe what I did to fix it in my case. Firstly let me describe my environment.
IntelliJ maven Java project on a linux machine.
Built Berkeley DB version 18.1.40.
The Berkeley build included the --enable-java switch in the configuration phase.
I included the db.jar (found in the build_unix directory) as a module dependency through the Intellij menus File> Project Structure. I selected Modules under Project settings on the left pane and then under the dependencies tab I added the db.jar file as a dependency.
This was the state of my project before I encountered the UnsatisfiedLinkError. To fix that I added the native libraries (found in the unix_build/.libs directory) to the project. You can do this by selecting the File menu> then Project Structure. On the left pane under project settings select Libraries and then click the + sign on the right pane to add the directory for the native libs.
This fixed my problem.

Qt programming error

I am developing Qt project. Previously I developed complete project that access database, but due to some reason i formatted the disk. When later on i run the project it showed me error for using QSqlDatabase QSqlError classes.
Please help me.
Perhaps something is missing in your Qmake project.

How to integrate Sqlite to Visual Studio?

I'm planning to use Sqlite but I don't know how to integrate it to visual studio or use it. Any help please... thanks.
I really recommend using System.Data.Sqlite ( http://sqlite.phxsoftware.com).
Have been using it for quite some time and it works great every time! You can create tables using the designer, similar to for MSSQL etc. Recommended++
Depends on how you want to use it. The easiest is to get the amalgamation version - this version "contains all preprocessed C code combined into a single source file", meaning you have a single .h and .c file to add to your project. This is the officially recommended practice.
If you want to build a "proper" library or link against SQLite dynamically, you have a bit more work ahead, since there's no VS project/solution files included with SQLite. You'll have to set up your own library project, add the correct files from the sqlite-source-x.y.z.zip file, and set this project as a dependency on your main project. Doing this is actually officially discouraged.
EDIT:
Forgot to mention that the above solution is assuming C/C++, as OP didn't specify language.
use System.Data.Sqlite
System.Data.SQLite is an ADO.NET provider for SQLite.

Resources