SQLCipher with custom options - c++

I’m using sqlcipher to encrypt sqlite db using custom parameters such as,
PRAGMA cipher_page_size = 1024;
PRAGMA kdf_iter = 16000;
PRAGMA cipher_hmac_algorithm = HMAC_SHA512;
PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA512;
These parameters are set up using graphycal interface of DBBrowser (SQLCipher) under Win with a specific password, and the resulting DB will be used in Raspberry let say.
I’m developing a C++ app to open the DB and query it. The result is that: file is not a database.
Went back to my Ubuntu vm and I’ve installed sqlcipher from apt. I also installed sqlitebrowser.
From the first executing pragmas and opening the db file gives the same error, from sqlitebrowser setting custom params on GUI, I’m able to open it.
What’s wrong with my steps? So what are correct steps to set custom config at command line to query the DB?
I think that this will help a lot for my C++ app too.

Related

Creating Database in iOS Application

I developed an application in iOS using qt. I am trying to create a DB sqlitedata.db. But DB is not getting created.
I have used
QStandardPaths::standardLocations(QStandardPaths::StandardLocation type)
to get the correct path.
The path returned from qDebug() was:
/var/mobile/Applications/262093E8-F9A7-4624-9559-FB3C6BF393E5/Library/Application Support/sqlitedata.db
But inside the Library folder, there is no folder named Application Support and no DB.
Please help with a solution to create a DB and read / update the DB through application.
make sure the path returned from QStandardPath actually exists. If it doesn't, than create it first.

Creating triggers using embedded mysql C++

I am working with the libmysqld c library in a C++ application on windows in order to interface with an embedded mysql server i.e. a mysql server that is online for the lifetime of the process that embeds it. The application that creates the database uses a mysql .ini file for creating the datadir relative to the application directory instead of in the global mysql install folder e.g.
[libmysqld_server]
basedir=./
datadir=./Database
I can programatically create a trigger with no problem e.g.
status = mysql_query(mysql,
"CREATE TRIGGER del_trigger AFTER DELETE ON table FOR EACH ROW\
INSERT INTO otherTable (col1, col2) VALUES (OLD.col1, OLD.col2)\
");
if (status == 0) {
Log(DEBUG, "Initialize(): <%p> Delete Trigger creation passed ...", this);
}
else {
Log(DEBUG, "Initialize(): <%p> Delete Trigger creation failed with error %s...", this, mysql_error(mysql));
}
The problem I run into however is that when the trigger gets called, mysql will complain that the mysql.proc table does not exist because I do not have a mysql database inside my application specific datadir. I have tried copying the mysql folder from the installation directory in C:\Program Files\MySQL... but then I run into issues where mysql reports
Error:Cannot load from mysql.proc. The table is probably corrupted
The only advice I have seen related to the above error is to run the 'mysql_upgrade' command which does not seem to work for the case of an embedded database using its own datadir. I'm at the point where all of the tables are created and their respective triggers are setup but just can't get around this mysql.proc error.
UPDATE:
I am also seeing some inconsistent behavior here. My version of MySQL is "mysql-5.5.16-win32" and it comes with a mysql_embedded.exe binary that I can use to open up a console and point to the database files generated by my application when it isn't running. When I perform operations in the mysql_embedded.exe, the triggers work without issue (no 'mysql.proc is probably corrupted' errors). So it seems like only the libmysqld c api is having an issue with the mysql system tables.
The solution was as simple as verifying that the "mysql" database was the same version as mysql version embedded in libmysqld. I verified my client version info via the following:
const char * version = mysql_get_client_info();
This returned "5.1.44" instead of the "5.5.16" that I was expecting. Downloading the mysql ZIP archive for 5.1.44 and using the mysql database in the datadir fixed the issue that I was experiencing.

Why LOAD DATA LOCAL INFILE will work from the CLI but not in application?

The problem:
My C++ application connects to a MySQL server, reads the first/header line of each db export.txt, makes a create table statement to prepare for the import and executes that against the database (no problem with that, the table appears just as intended) -- but when I try and execute the LOAD DATA LOCAL INFILE to import the data into the newly created table, I get the error "The used command is not allowed with this MySQL version". But, this works on the CLI! When I execute this command on the CLI using mysql -u <user> -p<password> -e "LOAD DATA LOCAL INFILE 'myfile.txt' INTO TABLE mytable FIELDS TERMINATED BY '|' LINES TERMINATED BY '\r\n';" it works flawlessly?
The Situation:
My company gets a large quantity of database exports (160 files/10gb of .txt files that are '|' delimited) from our vendors on a monthly basis that have to replace the old vendor lists. I am working on a smallish C++ app to deal with it on my work desktop. The application is meant to set up the required tables, import the data, then execute a series of intermediate queries against multiple tables to assemble information in a series of final tables, which is then itself exported and uploaded to the production environment, for use in the companies e-commerce website.
My Setup:
Ubuntu 12.04
MySQL Server v. 5.5.29 + MySQL Command Line client
Linux GNU C++ Compiler
libmysqlcppconn is installed and I have the required mysqlconn library linked in.
I have already overcome/tried the following issues/combinations:
1.) I have already discovered (the hard way) that LOAD DATA [LOCAL] INFILE statements must be enabled in the config -- I have the "local-infile" option set in the configuration files for both client and server. (fixed by updating the /etc/mysql/my.cnf with "local-infile" statements for the client and server. NOTE: I could have used the --local-infile=1 to restart the mysql-server, but this is my local dev environment so I just wanted it turned on permanently)
2.) LOAD DATA LOCAL INFILE seems to fail to perform the import (from the CLI) if the target import file does not have execute permissions enabled (fixed with chmod +x target_file.txt)
3.) I am using the mysql root account in my application code (because its my localhost, not production and this particular program will never run on a production server.)
4.) I have tried executing my compiled binary program using the sudo command (no change, same error "The used command is not allowed with this MySQL version")
5.) I have tried changing the ownership of the binary file from my normal login to root (no change, same error "The used command is not allowed with this MySQL version")
6.) I know the libcppmysqlconn is working because I am able to connect and perform the CREATE TABLE call without a problem, and I can do other queries and execute statements
What am I missing? Any suggestions? Thanks in advance :)
After much diligent trial and error working with the /etc/mysql/my.cfg file (I know this is a permissions issue because it works on the command line, but not from the connector) and after much googling and finding some back alley tech support posts I've come to conclude that the MySQL C++ connector did not (for whatever reason) decide to implement the ability for developers to be able to allow the local-infile=1 option from the C++ connector.
Apparently some people have been able to hack/fork the MySQL C++ connector to expose the functionality, but no one posted their source code -- only said it worked. Apparently there is a workaround in the MySQL C API after you initialize the connection you would use this:
mysql_options( &mysql, MYSQL_OPT_LOCAL_INFILE, 1 );
which apparently allows the LOAD DATA LOCAL INFILE statements to work with the MySQL C API.
Here are some reference articles that lead me to this conclusion:
1.) How can I get the native C API connection structure from MySQL Connector/C++?
2.) Mysql 5.5 LOAD DATA INFILE Permissions
3.) http://osdir.com/ml/db.mysql.c++/2004-04/msg00097.html
Essentially if you want the ability to use the LOAD DATA LOCAL INFILE functionality from a programmatic Connector API -- you have to use the mysql C API or hack/fork the existing mysql C++ api to expose the connection structure. Or just stick to executing the LOAD DATA LOCAL INFILE from the command line :(

How to programmatically dump Launch Services database?

How can I programmatically dump/query Launch Services database in MacOS (i.e. analog of command lsregister -dump)?
EDIT: I want to get set of associations UTI -> Bundle_IDs. Using LSCopyAllRoleHandlersForContentType - does not always work, here a similar trouble, therefore concluded that the best working method - parsing the output of "lsregister -dump", but the location of lsregister changes from version to version.

error in connecting access database in c++ program

i am getting error "security issue : the connection string may contain a password"
i want to connect access database with my c++ program using ODBC.
i am using visual studio 2008.
following are the steps what i have done to create this
created simple access database (testdb.mdb) and added user dsn(test)
then created mfc application in database support i selected database view with file support and selected odbc and cliked button data source and selected my created dsn(test)
now when i build this that above error occurs what shoul i do ?
just remove the line
#error Security Issue: The connection string may contain a password
from the generated header file.
it is there just to make you aware of that it is not good to have hardcoded passwords in your code.