1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #include <anna/core/functions.hpp>
11 #include <anna/dbms/Connection.hpp>
12 #include <anna/dbms/Database.hpp>
13 #include <anna/dbms/functions.hpp>
14 #include <anna/dbms/String.hpp>
15 #include <anna/dbms/Statement.hpp>
21 void dbms::functions::verifyDataScheme(dbms::Connection& connection, const char* tableName, const char* requiredPatch, const char* columnID, const char* columnDate)
22 throw(RuntimeException) {
23 dbms::Database& database = connection.getDatabase();
24 dbms::Statement* statement = NULL;
26 string sql = anna::functions::asString(
27 "select max(%s) from %s where %s in (select max(%s) from %s)",
28 columnID, tableName, columnDate,
33 statement = database.createStatement("dbms::functions::VerifyDataScheme", sql);
34 statement->bindOutput("max_id", id);
35 dbms::ResultCode resultCode = connection.execute(statement);
37 if(resultCode.successful() == false)
38 throw dbms::DatabaseException(resultCode, ANNA_FILE_LOCATION);
41 const string _id(id.getValue());
42 const string _required(requiredPatch);
44 if(_required != _id) {
45 std::string msg("DataScheme is out of date | Current patch: ");
47 msg += " | Required patch: ";
49 throw RuntimeException(msg, ANNA_FILE_LOCATION);
52 database.releaseStatement(statement);
53 } catch(dbms::DatabaseException& edb) {
54 database.releaseStatement(statement);
55 throw RuntimeException(edb);
56 } catch(RuntimeException&) {
57 database.releaseStatement(statement);