Qt Sqlite user access - sqlite

I'm working with sqlite and qt. I understand that sqlite doesn't have native user access control and am fine with that, and have a plan for controlling access using my application - set up some user groups in a db and authenticate on the app side.
What I would like to know is if there is an easy way to stop my views on QSqlRelationalTableModel data from updating the database (i.e make the database readonly).
I am currently using an editstrategy of OnFieldChange, if I change it to OnManualSubmit for example (without implementing a submit call), will that prevent updates to the dB?
Is there a cleverer way of doing this? Like making the view readonly?

If you create views, then they will be read-only since sqlite doesn't support updating views:
http://www.sqlite.org/lang_createview.html
EDIT
Following-up on your comment, is the QSQLITE_OPEN_READONLY connection setting what you are looking for?
http://doc.trolltech.com/4.6/qsqldatabase.html#setConnectOptions

Related

How do I make an SQLITE database programatically in Qt?

I am making a contact book application in Qt.
I want my application to automatically create an QSQLITE database when it first runs and then access this database in future?
Is there a way to do this?
Ya you can create sqlite database at its first run and can make it progressive. Just do it in the constructor of your App and check for the existence of db before cerating it, else don't create. You can access database in subsequent runs of your same App or different App.
Use db.setDatabaseName("databasename.db"); instead of db.setDatabaseName(":memory:");, now your database will be persistent.

Flash Builder 4.5 (Mobile) - Rolling out Database Updates

This is my first question on here so please be kind lol.
I am working on a mobile application with Flash Builder 4.5.
It uses a custom sql-lite database (tables are created on program load if they don't exist) to store the data. The data gets inserted by a sync process which connects to a web service.
I'm looking to ensure that changes to the database tables won't break the program.
For example I need to add a new field to an existing database table. I already know the SQL command (ALTER TABLE) for this but I'm not sure how to tie this to the update of the program i.e. when upgrading the program to 0.1 it should add the new field. But obviously I don't want it to try and add the field more than once.
Is there any way of knowing inside the program when it has been updated by the android/ios stores? Or any suggestions on how to handle these database changes?
The following answer has helped point me in the right direction:
database updates answer

Creating a database in the blackberry device when the app is installed

I want to create a database on my blackberry device when my app is installed. I did not find any event (e.g. onInstalled) so that i can create my databse on this event when the app is installed.
Apparently there is a method DatabaseFactory.exists() which i can use to check if the database exists or not. But i do not want to check for this every time. I want to create the database when my app is installed and when the app is un-installed then the database should also get deleted.
Thanks
As far as I know RIM API SDK does not provide mechanism to catch install/uninstall events.
And even the database is once created it can be deleted/damaged via the filesystem. For instance user deletes database files from the media-card or from the device memory. Just because user does not know what these files contain and assumes these as temporary or something else.
It is a good approach to check the database presence before starting work with it. Otherwise user may get blank white screen with text "Exception 1234" and some additional text, or may get a popup with strange message, like "Error: FileNotFoundException...".
See the SQLiteDemo in the blackberry samples demo then you can get solution.

How enable iCloud support for sqlite?

I want to provide iCloud support for my wrapper around sqlite. Is not using coredata.
I wonder how enable iCloud for it. The database content is changed all the time (is for invoicing). Also, if is possible to have some kind of versioning will be great.
Exist any sample I can use to do this?
The short answer is no, you would need to use Core Data as you suspected. Apple has stated that sqlite is unsupported.
Edit: Check out the section on iCloud that's now in the iOS Application Programming Guide under Using iCloud in Conjunction with Databases
Using iCloud with a SQLite database is possible only if your app uses
Core Data to manage that database. Accessing live database files in
iCloud using the SQLite interfaces is not supported and will likely
corrupt your database. However, you can create a Core Data store based
on SQLite as long as you follow a few extra steps when setting up your
Core Data structures. You can also continue to use other types of Core
Data stores—that is, stores not based on SQLite—without any special
modifications.
You can't just put the SQLite database in the iCloud container, because it might get corrupted. (As you modify an SQLite DB, temporary files are created and renamed, so if the sync process starts copying those files, you'll get a corrupt database.)
If you don't want to move to Core Data, you can do what Core Data does: store your database in your document folder, and store a transaction log in the iCould container. Every time you change the database, you add those changes to a log file, so you can play them back and make equivalent changes on other devices.
This gets pretty complicated: aside from getting the log/reply logic right, you'll want to coalesce redundant changes and periodically collapse the log into a complete copy of the database.
You might have an easier time developing a solution if you can exploit knowledge of your application (Core Data has to solve the problem in the general case). For example, you could save invoices as separate files in the cloud container (text, Property List, XML, JSON, whatever), writing them out as the database changes and only importing ones if the system tells you they were created or changed.
In summary, your choice is either to migrate to Core Data or write a sync solution yourself. Which one is best depends on the particulars of your application.

Is it possible?

We are thinking of moving some of the 'hard coded' settings out of our windows forms application and storing them in the sql database in a table called App_Settings. The reason for this is we have values currently hard coded into appsettings and app.config which can change over time, and it is much easier and faster to update the values in a database table than it is to update, build and deploy the app over three servers.
Please can someone advise on this, and also how can we load the settings into the app and then have them readily available in any class?
Cheers
Richard
Have a look at this similar thread: Resources/App.config or Database where is the best place to application strings
When you want to store settings in the database i would implement the class as Singleton or at least as a Class with only static/shared members and a factory method(getAppSettings)which returns that single/static instance. So you could access your settings from everywhere and it is only initialized once.
Why don't you use something like YAML to save these settings? It would be easy to create a form to edit and save these settings in a file, instead of a db (which would add more maintainance problems).
Otherwise, I would suggest to use something like NHibernate to use a database, and SQLLite as the db server.
Also, note that if you are updating these settings, I would not say that these are App_Settings, since App_Settings aren't usually modifyable without
Help this helps,
Pietro

Resources