How to use SQLite within a WinRT DLL? - c++

I am trying to develop a WinRT DLL which uses SQLite to write database.
But it seems like some win32 APIs in SQLite source code are not supported by metro, such as, LoadLibraryW, GetTempPathA.
Is there any way to compile SQLite source code or use SQLite with WinRT DLL?

Well you could always link sqlite3 statically and define new functions for accessing files etc via sqlite3_vfs.

In VS2012 there is an extension now called SQLite for Windows Runtime. You can download and install this via Visual Studio (requires a restart of the IDE). Then, go to your WinRT project, Add a Reference, under "Windows" choose "Extensions" and you should see it.

There's a winrt branch of SQLite now that only uses supported API. On top of that, we implemented SQLite3-WinRT, a WinRT component that allows using SQLite in any of the WinRT languages.

rename sqlite3.c to sqlite3.cpp
replace LoadLibrary with LoadPackagedLibrary
Fix lots of syntax errors.

From the SQLite site
SQLite version 3.7.13 adds support for WinRT and metro style applications for Microsoft Windows 8. The 3.7.13 release is coming sooner than is usual after the previous release in order to get this new capability into the hands of developers. To use SQLite in a metro style application, compile with the -DSQLITE_OS_WINRT flag. Because of the increased application security and safety requirements of WinRT, all database filenames should be full pathnames. Note that SQLite is not capable of accessing databases outside the installation directory and application data directory. This restriction is another security and safety feature of WinRT. Apart from these restrictions, SQLite should work exactly the same on WinRT as it does on every other system.
Tim Heuer provides a walk-through of building a metro app using SQLite on his blog

Let me add some remarks on using sqlite/winrt that may save you some headaches:
Winrt allows you to write only to specific folder (c:\users\<user>\My documents\<app>). You have to put your DB here. (Trivial in managed environment.)
Time from time Sqlite uses temp files. (Complex queries that need transient indices, vacuum etc.) These files also must be created in the app folder, but sqlite won't do this unless you set it with temp_store_directory pragma. If you don't do this, you may get random user bug reports.
Note that above pragma is officially deprecated. Ignore this. Native coders might be tempted to use global variable sqlite3_temp_directory instead (encouraged way), but the current binary release (dll) does not publish this variable. (You can do it yourself, but then change sqlite sources and use _declspec(dllexport) attribute; def file does not work.)
Don't rely too much on sqlite file operations. The implementation is not particularly good. For example testing of write access will succeed even if you don't have write permissions.
Apart from this there seem to be no problems with winrt. More advanced users might supply their own (better) winrt driver. It is not too difficult...

Related

C++ manipulating mdb database

I want to create an app based on the content of a .mdb file, I searched for libraries to do that in native but they all needed requirements, I want a way to read these files using native code(C++) only, so I could use the library in multiple platforms.
Thx,
Regards
The .mdb file format is specific to the Microsoft Access ("Jet") database engine, which is proprietary and specific to Windows. (Furthermore, it is an evolving file-format, although it does not seem to continue to be in active development now.) There is one, and only one, "correct" way to use it, and that is: to use Microsoft's library and surrounding framework, on Microsoft's operating system.
If, indeed, you need to use a "file-based SQL engine," "on multiple platforms," then I would cordially suggest that you instead use a database file format that was specifically designed for such purposes: SQLite.
Mind you, the two are not the same. They're the product of two entirely different design teams who had different purposes in mind. The SQLite team knowingly did not adhere strictly to the SQL standard. But, what they did do was to create a public domain(!) database engine, which uses a single file, and which was specifically designed to be cross-platform. Meanwhile, the Jet team designed their engine specifically, and solely, in support of the Access (and Excel) products of their company.

Integrating TideSDK with C *.dll

I've already written some backend *.dll files that I intend to use in a project. I need to visualize a simulation of the code, for which I intend to use charts and graphs from Chart.JS, by using it along with TideSDK for a desktop application.
I have no clue on how to call the C libraries via JS though. And I want to avoid creating wrapper classes in Python and going through that circuitous route. Any other options? Or are there any alternatives when trying to create an HTML/CSS/JS desktop application connected to a backend C/C++ library? Will AppJS make things easier?
TideSDK is capable of extension with modules that can be compiled and included in its runtime. It was written to be extended but I would recommend waiting for TideKit. TideSDK is a bit old and setting up a toolchain could be problematic at this point.
We've been investing in a broader vision with TideKit that is getting ready for release. You will be able to extend it with native modules and you won't need to wait too much longer to see what we've been up to. http://youtu.be/aE7gN-d0GhUthat
If you have started anything with TideSDK, you will be able to migrate your code easily to TideKit. The ability to work with with native or JavaScript modularity, and to develop for all screens from a single project code base is where all our efforts have been going.
Note that AppJS was discontinued earlier this year. An alternative is writing C extensions in node through node-webkit. Note that if you are going cross platform on this and you needed OSX as well, you cannot achieve Apple AppStore compliance with node-webkit due to private APIs as a result of its port of webkit.

In native C++, how does one use a SqlCe .sdf database?

Is there a simple way, without .NET?
I've found some libraries but none for SqlCe 3.5. There is http://sqlcehelper.codeplex.com/ but it's far from done, since a major feature like using a password is not yet implemented. I've looked at the source and it uses OLEdb to handle the database.
The official Microsoft Northwind example (that is shipped with SQL Compact 3.1, but not with 3.5) also doesn't work, I've tried setting it up with no success.
Actually I don't have a sample working code. Was anyone able to set it up paired with a passworded .sdf?
What are the alternatives?
Thanks.
Several months ago, I compared certain database implementations for our desktop application. Using SqlCE with native C++ code is awful. If I remember right, some of native examples contains "goto" type jumps, hard to bind data and so on. If you have a choice then use SQLite.

Database Access Libraries for C++

Background:
I have an application written in native C++ which uses the wxWidgets toolkit's wxODBC database access library which is being removed from all future versions of wxWidgets . I need to replace this with another database access method that supports the assumptions and contraints outlined below. I don't require that the replacement use native DBMS APIs or ODBC under the hood, but it must meet the contraints outlined below.
Assumptions/Constraints
The library must:
Support Native (i.e. unmanaged) C++
32-bit Windows 2000/XP/2003
Visual Studio 2005
Microsoft SQL Server 2000 and 2005
Oracle 9 and 10
Run-time Performance greater than or equal to wxODBC
Single programmer API supporting multiple DBMS (e.g. don't want to write different code for using different DBMS)
Nice but Optional:
64-bit Windows operating systems
32-bit and/or 64-bit Linux operating systems
Microsoft SQL Server 2008
Oracle 11
MySQL
Any additional DBMS
Visual Studio 2008
Open Source
Runtime Performance near or equal to native DBMS API
Question:
What good libraries are available - either free, open source or pay - that support multiple DBMS from a single API including Oracle and Microsoft SQL Server and can be used from native C++?
Please describe any past experiences you have had - good OR bad - with a given library and why you are making your recommendation for or against a given library, especially in regards to the assumptions and contraints above.
See Also:
https://stackoverflow.com/questions/74141/good-orm-for-c-solutions
I use SQLAPI++. Well worth a look.
http://www.sqlapi.com/
A library is http://otl.sourceforge.net/
An employer of mine used it.
I can't tell you how its performance compares with wxODBC, but it might fit your requirements.
You can use SOCI http://soci.sourceforge.net or also Wt::Dbo, http://www.webtoolkit.eu and look at the Wt::Dbo component.
You can check Debea - SQL Database Access and ORM for C++. It has API for wxWidgets built-in.
Qt is also an option. It supports the connections to the servers you want, and quite simple to use.
http://doc.trolltech.com/4.4/sql-driver.html#supported-databases
When using Qt, you don't need to build against all Qt. You can for example just use the SQL part, and leave the whole GUI part outside.
Since it has been recently LGPL-ed, you can also use it for a proprietary application.

how-to: programmatic install on windows?

Can anyone list the steps needed to programatically install an application on Windows. Aside from copying the files where they need to be, what are the additional steps needed so that your app will be a first-class citizen in Windows (i.e. show up in the programs list, uninstall list...etc.)
I tried to google this, but had no luck.
BTW: This is for an unmanaged c++ application (developed in Qt), so I'd rather not involve the .net framework if I don't have to.
I highly recommend NSIS. Open Source, very active development, and it's hard to match/beat its extensibility.
To add your program to the Add/Remove Programs (or Programs and Features) list, add the following reg keys:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PROGRAM_NAME]
"DisplayName"="PROGRAM_NAME"
"Publisher"="COMPANY_NAME"
"UninstallString"="PATH_TO_UNINSTALL_PROGRAM"
"DisplayIcon"="PATH_TO_ICON_FILE"
"DisplayVersion"="VERSION"
"InstallLocation"="PATH_TO_INSTALLATION_LOCATION"
I think the theme to the answers you'll see here is that you should use an installation program and that you should not write the installer yourself. Use one of the many installer-makers, such as Inno Setup, InstallSheild, or anything else someone recommends.
If you try to write the installer yourself, you'll probably do it wrong. This isn't a slight against you personally. It's just that there are a lot of little details that an installer should consider, and a lot of things that can go wrong, and if you want to write the installer yourself, you're just going to have to get all those things right. That means lots of research and lots of testing on your part. Save yourself the trouble.
Besides copying files, installation tasks vary quite a bit depending on what your program needs. Maybe you need to put an icon on the Start menu; an installer tool should have a way to make that happen very easily, automatically filling in the install location that the customer chose earlier in the installation, and maybe even choosing the right local language for the shortcut's label.
You might need to create registry entries, such as for file associations or licensing. Your installer tool should already have an easy way to specify what keys and values to create or modify.
You might need to register a COM server. That's a common enough action that your installer tool probably has a way of specifying that as part of the post-file-copy operation.
If there are some actions that your chosen installer tool doesn't already provide for, the tool will probably offer a way to add custom actions, perhaps through a scripting language, or perhaps through linking external code from a DLL you would write that gets included with your installer. Custom actions might include downloading an update from a specific Web site, sending e-mail, or taking an inventory of what other products from your company are already installed.
A couple of final things that an installer tool should provide are ways to apply upgrades to an existing installation, and a way to uninstall the program, undoing all those installation tasks (deleting files, restoring backups, unregistering COM servers, etc.).
I've used Inno Setup to package my software for C++. It's very simple compared to heavy duty solutions such at InstallShield. Everything can be contained in a single setup.exe without creating all these crazy batch scripts and so on.
Check it out here: http://www.jrsoftware.org/isinfo.php
It sounds like you need to check out the Windows Installer system. If you need the nitty-gritty, see the official documentation. For news, read the installer team's blog. Finally, since you're a programmer, you probably want to build the installer as a programmer would. WiX 3.0 is my tool of choice - open source code, from Microsoft to boot. Start with this tutorial on WiX. It's good.
The GUI for innosetup (highly recommended) is Istool
You can also use the MSI installer built into Visual Studio, it's a steeper learning curve (ie is a pain) but is useful if you are installing software in a corporate environment.
To have your program show up in the Start program menu,
You would need to create folder
C:\Documents and Settings\All Users\Start Menu\Programs
and added a short cut to the program you want to launch.
(If you want your application be listed
directly in the Start menu, or in the programs submenu,
you would put your short cut in the respective directory)
To programically create a short cut you can use IShellLink
(See MSDN article).
Since you want to uninstall, that gets a lot more involved because you don't want to simply go deleting DLLs or other common files without checking dependencies.
I would recommend using a setup/installation generator, especially nowadays with Vista being so persnickety, it is getting rather complicated to roll your own installation
if you need anything more than a single executable and a start menu shortcut.
I have been using Paquet Builder setup generator for several years now.
(The registered version includes uninstall).
You've already got the main steps. One you left out is to install on the Start Menu and provide an option to create a desktop and/or quick launch icon.
I would encourage you to look into using a setup program, as suggested by Jeremy.