Does SQLite have a machine portable file format that the C API can read/write? - sqlite

I've tried passing binary SQLite DBs over the network between different OSes and architectures - it didn't work.
What format are you all using? I've tried an unholy hack of copying SQLite's shell.c and calling shell_main() with a hacked up argc, argv, stdin with success on Mac. Pity I'm developing for the iPhone and it fails only there.
Does everyone do such awful things?

This is one of the core features of SQLite.
Stable Cross-Platform Database File
The SQLite file format is cross-platform. A database file written on one machine can be copied to and used on a different machine with a different architecture. Big-endian or little-endian, 32-bit or 64-bit does not matter. All machines use the same file format. Furthermore, the developers have pledged to keep the file format stable and backwards compatible, so newer versions of SQLite can read and write older database files.
Most other SQL database engines require you to dump and restore the database when moving from one platform to another and often when upgrading to a newer version of the software.
http://sqlite.org/different.html
Check the code that's passing the databases. Do a byte-by-byte comparison to make sure they're equal after transfer. This definitely should be working.
Beyond Compare has good binary file comparison support.

Related

How to integrate sqlcipher with qt5

I'm completely new to Qt. Actually I'm trying to build an app, which stores it's data to an encrypted sqlite database file. Ok, I've build sqlcipher successfully and found the files under ./libs (I'm on a Mac).
Where do I've to put the files in my Qt project for development, and later on, for deploy it with the app?
qDebug() << QSqlDatabase::drivers();
gives me
("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3", "QPSQL", "QPSQL7")
Thanks in advance.
I don't think a driver for SQLCipher exists in Qt. You'll only get the default drivers, which include SQLite.
I know two options: you use sqlcipher with its C API like a normal library, link to your app and you're done. Or you create the driver yourself. Creating that driver should be pretty simple as it should be almost identical to the one for sqlite, being the API almost identical. Simply linking the sqlite driver to sqlcipher instead of sqlite should be enough.
I found this online that should help you. But there are probably also other useful resources. That seems to simply re-use the sqlite plugin, linking to sqlcipher.

How do I "install" SQLite on my student domain?

I've played around with SQLite on my Windows desktop before, but I've never used it in a web context and their web documentation is maddenigly unspecific about things like this. Essentially, I have free student webspace from my school (a /public/html/ directory) and I'd like to use it for a small data-driven web project. SQLite is my only (free) option and I'm wondering how to... "install" it in this context? More specifically, is it safe just to throw the files in the html directory and call it a day?
If it helps, I'm pretty sure it's Linux environment (they run Apache).
See if it's already installed. Try the following in a bash session:
touch test.db
sqlite3 test.db
If not, you'll have to download and install sqlite3.
Useful tip: if you've been trying to run the 'sqlite' binary, it probably doesn't exist. It's called 'sqlite3'.
SQLite is an embedded database; it is typically not installed, but compiled into whatever program is used to access the database.
All the typical server-side extension languages (PHP, Ruby, Python, Perl etc.) have support modules for SQLite.
You have to check which one of those are installed on the server, and whether SQLite support has been enabled for them.

use sqlite with node.js - working module

I'm working on a node.js project and I would like to use some kind of database to store application data. I've searched for various DBMS and I've selected SQLite because I want my project to be able to run without installing heavy DBMS and because I want it to run both on linux and windows. however, all modules that we found, that connect node with SQLite are either very old, or cannot be installed due to bugs.
so, I want to ask if nowadays, 2012, there is a completely functional node.js module for SQLite.
I did a project last July (2012) in Node.JS v0.8.8, using the node-sqlite module (see https://github.com/developmentseed/node-sqlite3) and it worked just fine.
And, I successfully deployed and used this module on Heroku. However, the deployed portion of the project only involved reading out of the SQLite database – not writing. I suspect that writing into a SQLite deployed on Heroku would cause some issues, because it involves modifying the SQLite file in the file system, which AFAIK Heroku doesn't let you do.

Anyone successfully used password on sqlite database in Monotouch?

I have a Monotouch app which uses a sqlite database. I want to encrypt the database so I am doing this:
_mainConnection = new SqliteConnection("Uri="+finalDB);
_mainConnection.Open();
_mainConnection.ChangePassword("mypassword");
However, its not working (on simulator and iphone). It gets this error:
at (wrapper managed-to-native)
Mono.Data.Sqlite.UnsafeNativeMethods.sqlite3_rekey
(intptr,byte[],int) <0x0005c> at
(wrapper managed-to-native)
Mono.Data.Sqlite.UnsafeNativeMethods.sqlite3_rekey
(intptr,byte[],int) <0x0005c> at
Mono.Data.Sqlite.SQLite3.ChangePassword
(byte[]) <0x00053> at
Mono.Data.Sqlite.SqliteConnection.ChangePassword
(byte[]) <0x0004b> at
Mono.Data.Sqlite.SqliteConnection.ChangePassword
(string) <0x0005b>
Has anyone successfully used password protection on an sqlite database in Monotouch?
As per my research there are a few options for database encryption using MonoTouch. I have a forthcoming blog post on the subject, but for now these are your top two options:
SQLCipher
I've automated the SQLCipher build process substantially. All it takes is a simple make command and you've got a library that you can link into your project. It makes use of the awesome SQLite-NET library. After that, all that's required is to provide the key in the SQLite.cs file.
SQLCipherNet: https://github.com/anujb/SQLCipherNet
CSharp-SQLite
This is a managed port of the SQLite library in C#. Performance is only about ~2x slower, which is pretty awesome considering it's not native code!
Encryption: http://code.google.com/p/csharp-sqlite/wiki/ENCRYPTION
Perf Benchmarks: http://code.google.com/p/csharp-sqlite/wiki/Benchmarks
Try adding ";Password=mypassword" to your connection string, and remove the call to ChangePassword.
Please note that, by default, the iPhone implementation of sqlite does not support encryption, so the sqlite commands for that will be no-ops.
You can get a (paid) copy of the encrypt-able version of sqlite from http://www.hwaci.com/sw/sqlite/see.html, and compile it into your application, making sure to remove the libsqlite3*.dylib from your project if you've linked that in.
You may have to do a bit of digging in the Monotouch documentation and/or experimentation to make sure that the Monotouch library itself is not including the default sqlite implementation, but in fact links to the implementation you specify. Try it first, if things still don't work that's where I'd start looking.
You can do this experiment without paying for the encrypted version, simply using the sqlite3 source code available on the net, with appropriate break points.
Good luck!
PS: Note that there is no comparable solution for Android at this point, this works on iPhone because iPhone runs native C code.
PPS: There is also SQLCipher that claims to encrypt sqlite on iPhone. However I found the configuration requirements to be below my standards for simplicity. I'm also not sure if it will properly insert itself between Monotouch's framework code and the default iPhone sqlite implementation.
SQLCipher for MonoTouch provides full database encryption for SQLite databases.
http://sqlcipher.net/sqlcipher-for-monotouch
There is also a SQLCipher on Mono for Android, which allows you to reuse the same code across Mono Touch and MonoDroid applications
http://sqlcipher.net/sqlcipher-for-monodroid
Just thinking out loud but could this be due to sqlite's dynlib that comes with the iPhoneSDK not being threadsafe?
For an alternative you might try looking at WWDC Vid 209 and just lock/encrypt the DB when you're outside the app.
You can probably do it yourself by issuing a "pragma rekey" in a raw SQLite query -- that is, if the SQLite version installed is actually SqlCipher.
I had the same problem but with a windows form application in C#.
I could not find the solution so i had to encrypt my data manually when saving it and decrypt it when retrieving.

Is Jet database engine included in Windows xp, vista and Windows7?

I need a data store for single-user, read-only access. I need multiple tables, but not related. I also need to do two-column indexing. Seems like Jet is a good choice. Front end will be either VB or C#. The data is not user-entered data, but meta data about users and external files. What are the deployment issues for Jet -is it built into all Windows OS versions from xp onward? I plan on including the Access Database in the resource file.
MS Jet 4.0/DAO 3.6 are part of the operating system and are in Windows 2000, XP, Vista and Windows 7. They are updated by Windows Update and the security patches are applied as appropriate.
Alternatively to including the MDB file in the resource file you could build it if it isn't present. See the TempTables.MDB page at my website which illustrates how to use a temporary MDB in your app.
You can also use the Compare'Em utility
to keep the database files tables, fields, indexes and relationships updated as you upgrade your app.
See why-should-i-use-sqlite-over-a-jet-database, and try both.
The Microsoft Access .mdb driver is included with XP and up. It's part of MDAC.
There are a few other options for this, by the way. Look into SQL Compact, VistaDB, and SQLite.
Be aware that currently there are no 64 bit versions of the JET engine included with the operating systems!
The engines for 64 bit will be available with next Office. Beta can be downloaded from Microsoft Downloads
If you Google this you will see that Jet is no longer a standard part of Windows and has been deprecated. The ACE driver that is now part of Office 2010 does support MDB files, though Microsoft emphasizes that it is not a replacement for Jet. They want you to use SQL Express instead.
You can download and install the ACE driver separately, but note that for no sane reason you can not have the 32 and 64-bit versions of it installed on the same machine. If oyu have Office 2007 32-bit installed and you try and install the 64-bit ACE engine, it gives you this big dialog box that tells you you have to uninstall Office 2007 first.
We switched to sqlite. No more such hassles.
Be careful when using the CSV ODBC driver, there is a bug I discovered.
If you export an MS-Excel file to CSV format, you get double quoted text strings if the text string exported contains double quotes or commas embedded within it.
Example:
"Hello World", This is Eric.
exports as
"""Hello World"", This is Eric."
However, if you read in this data to an ODBC enabled program, then export the data back out, what happens is that the CSV ODBC Driver puts double quotes around text whether the text has embedded double quotes and/or commas, or not.
The huge problem with this is that you cannot run a FILE COMPARE on the original file exported from MS-Excel, and the newly created file (read in then output) from an ODBC enabled program using the CSV driver.
You will always get a FAILED FILE COMPARE (checksum) because the data is not equal. That really screws up QA/QC.
Also, another huge bug exists in ODBC Administrator
whereby you cannot edit the files the Text Driver recognizes/supports.
If you edit that entry, Chinese characters are stored in the Windows Registry. But it is a nice way to parse CSV data via ODBC instead of having to write your own code to strip out the extra Double Quotes.

Resources