*/
#include <fstream>
+#include <sstream>
#include <db-crypto.h>
#include <dpl/db/sql_connection.h>
#include <dpl/log/log.h>
* increment and update DB_VERSION_CURRENT,
* then provide migration mechanism!
*/
- DB_VERSION_CURRENT = 3
+ DB_VERSION_CURRENT = 4
};
const char *SCRIPT_CREATE_SCHEMA = "create_schema";
"INSERT INTO OBJECTS("
" exportable, dataType,"
" algorithmType, encryptionScheme,"
- " iv, dataSize, data, tag, idx) "
+ " iv, dataSize, data, tag, idx, backendId) "
" VALUES(?001, ?002, ?003, ?004, ?005, "
" ?006, ?007, ?008,"
- " (SELECT idx FROM NAMES WHERE name=?101 and label=?102)"
+ " (SELECT idx FROM NAMES WHERE name=?101 and label=?102),"
+ " ?009"
" );";
const char *DB_CMD_OBJECT_SELECT_BY_NAME_AND_LABEL =
row.dataSize = selectCommand->GetColumnInteger(7);
row.data = selectCommand->GetColumnBlob(8);
row.tag = selectCommand->GetColumnBlob(9);
+ row.backendId = static_cast<CryptoBackend>(selectCommand->GetColumnInteger(11));
return row;
}
insertObjectCommand->BindInteger(6, row.dataSize);
insertObjectCommand->BindBlob (7, row.data);
insertObjectCommand->BindBlob (8, row.tag);
+ insertObjectCommand->BindInteger(9, static_cast<int>(row.backendId));
// name table reference
insertObjectCommand->BindString (101, row.name.c_str());
insertObjectCommand->Step();
}
+
+ std::string Crypto::getSchema() {
+ SqlConnection::DataCommandUniquePtr schema =
+ m_connection->PrepareDataCommand("SELECT sql FROM "
+ "(SELECT * FROM sqlcipher_master UNION ALL "
+ "SELECT * FROM sqlcipher_temp_master) "
+ "WHERE type!='meta' "
+ "ORDER BY tbl_name, type DESC, name;");
+
+ std::stringstream ss;
+ while(schema->Step()) {
+ ss << schema->GetColumnString(0) << std::endl;
+ }
+ return ss.str();
+ }
+
+ std::string Crypto::getContent() {
+ SqlConnection::DataCommandUniquePtr tableSelect =
+ m_connection->PrepareDataCommand(
+ "SELECT name FROM sqlcipher_master "
+ "WHERE type IN ('table','view') AND name NOT LIKE 'sqlcipher_%' "
+ "UNION ALL "
+ "SELECT name FROM sqlcipher_temp_master "
+ "WHERE type IN ('table','view') "
+ "ORDER BY 1; ");
+
+ std::vector<std::string> tables;
+ while(tableSelect->Step()) {
+ tables.push_back(tableSelect->GetColumnString(0));
+ }
+
+ std::stringstream ss;
+
+ for (auto &e : tables) {
+ ss << "Table " << e << std::endl;
+ std::string query = "select * from " + e + ";";
+ SqlConnection::DataCommandUniquePtr result =
+ m_connection->PrepareDataCommand(query.c_str());
+ while(result->Step()) {
+ int maxColumn = result->GetColumnCount();
+ for (int i = 0; i < maxColumn; ++i) {
+ switch(result->GetColumnType(i)) {
+ case 1: // int64
+ ss << result->GetColumnInteger(i) << " | ";
+ break;
+ case 2: // float
+ ss << result->GetColumnFloat(i) << " | ";
+ break;
+ case 3: // string
+ ss << result->GetColumnString(i) << " | ";
+ break;
+ case 4: // Blob
+ {
+ auto buffer = result->GetColumnBlob(i);
+ ss << "BLOB (Size: " << buffer.size() << ") | ";
+ break;
+ }
+ case 5: // NULL
+ ss << "NULL | ";
+ break;
+ }
+ }
+ ss << std::endl;
+ }
+ }
+
+ return ss.str();
+ }
} // namespace DB
} // namespace CKM