RDbms name and version - c++

I m doing a software in c++ that permit to access to some rdbms with qt library.
The software is only for pc.
The software need to know the name of rdbms and version beacuse the program needs to choose some sql query to execute. Is there any way to retrieve thisdata in any rdbms?

Is there any way to retrieve thisdata in any rdbms?
This is specific to each RDBMS - for example, in Oracle, you can do
select *
from v$version;
but in other RDBMS this view does not exist.
Some possible approaches:
You need to define connect parameters somewhere anyways. Even they are often RDBMS-specific, so you could simply add another parameter like SQLFlavor=Oracle or SQLFlavor=MySQL and then use the value of SQLFlavor in your code to determine which SQL statement to use
You can use some heuristics to find out the RDBMS. For example, query the v$version view - if it does not exist, you will get an error and you know that it is not Oracle and you can continue with the next try (like SELECT VERSION() to see if it is MySQL). Otherwise, you can use the result to find out the concrete Oracle version.

Related

Convert an unknown database file from a windows software into a MySqli Database

I have installed a software in my system and I have a lot of data from client in it. All the files which are inside DB folder of this software are with extensions for each individual party.
I want to to use these files to get converted to a MySqli Database.
Sample file from DB folder can be download from here
I have tried understanding for firebird service which this software uses to connect with these database files to get the things.
I want to extract database and import it inside MySqli (PhpMyAdmin)
The linked file seems to be a renamed Firebird database with structure version ODS 11.2 which corresponds to Firebird 2.5.x line.
For making a quick peep into the database you can use
IBSurgeon First Aid -- http://ib-aid.com
IB Expert (the Database Explorer feature) -- http://ibexpert.net
Free mode of FirstAID would let you peep into the data, but not extract it out, probably not even scroll ALL the tables. It also would most probably ignore all database structures that are not tables (UDF functions, procedures, VIEWs, auto-computed columns in tables) - afterall it is just low-level format parser, not an SQL engine.
IB Expert has as a non-commercial Personal edition, but it probably does not include DB Exp, however you may try a trial period of full version. However IBE's DBExp would probably also only show basic structures of the database, maybe it would be enough.
Alternatively you can install Firebird 2.5.8 - either a standalone version or maybe embedded (a set of DLLs used instead of FB server process) if your application can use it, then use any DB IDE suit to explore it. Most often mentioned for Firebird would be IBExpert, FlameRobin, Firebird Maestro or any other. Then you would be able to try different SQL queries, including SPs, VIEWs and UDF-functions if there were any registered for the database and actually used.
BTW IBExpert comes bundled with FB 2.5 Embedded, which one can use to open the database file.
After you figure out the format, you can either export required data into some intermediate format like CSV (for example: http://fbutils.sourceforge.net/ ) or use your C++ application (though why would anyone develop web-application in C++) using libraries like IB++ or OLE DB, etc. Maybe it would be better to just use the Firebird server and original DB files from PHP or what would you write the application in.

c++ change hardware-IDs via WMI

Currently I'm working on a program which I would like to fit to a few computers. I query some hardware IDs (disk, mainboard and CPU) with WMI according to this site:
https://msdn.microsoft.com/en-us/library/aa390423(v=vs.85).aspx
As SQL is used there, is it possible not only to recieve data via SELECT but to change data via a UPDATE query? If so, this attempt to create a "copy-protected program" would fail, right?
The WMI uses the WQL language which is only a small subset of the ANSI SQL. The WQL language doesn't supports the UPDATE or INSERT statements. Also if you want update some property value this depends if the WMI property/class is writable, finally depending of what you want accomplish you must use the IWbemClassObject.Put or the IWbemServices.PutInstance method.

Storing, tracking and updating an SQLite database version in C++ application

I have an application written in C++ which uses an SQLite database to store information. I need a way of assigning a version number to the database. By this I mean, I need to be able to assign a version number to the state of the database, and if a new 'state' (version) is available, then I need to update the current database state to match the state of the updated version.
I am wondering whether it would be good practice to store the information required for this to happen in a table. I would need the version number, and then some way of storing the tables and their columns related to each version number. This would allow me to make comparisons etc.
I realise that this question Set a version to a SQLite database file is related, however it doesn't quite answer my question, as I am unsure if my approach is correct, and if so, how I go about achieving this.
All help is much appreciated.
Use PRAGMA user_version to read and store an integer value in the database file.
When the version in your code and database file are the same, do nothing. When they are different, upgrade/downgrade accordingly and update the version number.

Unable to execute stored procedures through OLEDB

I'm locally running an instance of Oracle 11gR2 for testing. I'm connecting to it with OLEDB using VC++. I use CCommand and I'm able to select, update, insert and delete from my tables.
What I can't do right now is execute stored procedures.
It is a simple stored procedure that inserts a row to my table. I can run it from SQL Plus without a hitch. However, when I come to execute it from my code, it doesn't work. I get a 80040e14 error.
It's pretty straightforward, but here is the line anyway.
hr = cmd.Open(session, "exec get_item_count");
Any ideas?
EXEC is SQL*Plus syntax. It is not valid outside SQL*Plus (and a variety of PL/SQL GUIs that implement many of the features SQL*Plus provides).
You probably want something like this (using ODBC syntax)
hr = cmd.Open(session, "{call get_item_count}");
or this (using Oracle syntax)
hr = cmd.Open(session, "begin get_item_count; end;");
If you use the Oracle syntax, the same syntax will work both in SQL*Plus and from your application. SQL*Plus does not understand ODBC syntax. However, other OLE DB providers will support ODBC syntax so ODBC syntax is portable across different database engines.
Additionally, if you have a PL/SQL object that retrieves an item count, that should be a stored function not a stored procedure. You say that the procedure is inserting a row into your table, which is something that a procedure should do and a function should not, but the name of the object get_item_count doesn't seem to match your description of what it is doing.

How can I ensure a read-only transaction in SqLite?

I have public interface which allows people to interact with the database by typing in sql commands. However, I do not want them to change the database in any way (and if possible, not access certain tables). As I understand though, SQLite has no concept of users, so how do I accomplish this?
If within the query there are no application defined sql functions, which indirectly modifies the database(e.g: SELECT eval('DELETE FROM t1') FROM t2; ), then use sqlite3_stmt_readonly to determine whether the prepared sql statement writes the database, otherwise you can try to open an other, read_only, database connection handler(SQLITE_OPEN_READONLY) which will be used for read_only access.
Copy the "master" database file first and open that :-) No, really, this is a serious suggestion.
Otherwise, depending on how SQLite is accessed, the SQLITE_OPEN_READONLY flag that can be passed to sqlite3_open_v2. This applies to the entire connection -- and all transactions on that connection.
Another option is to limit the SQL entry, but this is very very hard to do correctly and thus I don't recommend this route.
Happy coding.