X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdbms.mysql%2FxSelect%2Fmain.cpp;fp=example%2Fdbms.mysql%2FxSelect%2Fmain.cpp;h=6f7fdcca37102b0732901108dab35f4f0bca8d3a;hb=78be86969d2f26a9084b0c4af6ce43d5fa4ed3fd;hp=0000000000000000000000000000000000000000;hpb=a3b95648bd76140ef55e0b5941d423eee6c3856f;p=anna.git diff --git a/example/dbms.mysql/xSelect/main.cpp b/example/dbms.mysql/xSelect/main.cpp new file mode 100644 index 0000000..6f7fdcc --- /dev/null +++ b/example/dbms.mysql/xSelect/main.cpp @@ -0,0 +1,139 @@ +// ANNA - Anna is Not Nothingness Anymore // +// // +// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo // +// // +// See project site at http://redmine.teslayout.com/projects/anna-suite // +// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE // + + +#include + +#include +#include +#include + +#include +#include + +class Select : public Application { +public: + Select (); + ~Select () { delete a_db; } + +private: + anna::dbms::Database* a_db; + + void initialize () throw (RuntimeException); + void run () throw (RuntimeException); +}; + +using namespace std; + +int main (int argc, const char** argv) +{ + CommandLine& commandLine (CommandLine::instantiate ()); + Select testNull; + + try { + commandLine.initialize (argv, argc); + commandLine.verify (); + + Logger::setLevel (Logger::Debug); + Logger::initialize ("copy", new TraceWriter ("xselect.trace", 1024 * 1024)); + + testNull.start (); + } + catch (Exception& ex) { + cout << ex.asString () << endl; + } + + return 0; +} + +Select::Select () : + Application ("xselect", "Copiador de la tabla ad_funcionalidades", "1.0"), + a_db (NULL) +{ + CommandLine& cl (CommandLine::instantiate ()); + + cl.add ("user", CommandLine::Argument::Mandatory, "Nombre del usuario"); + cl.add ("password", CommandLine::Argument::Mandatory, "Clave del usuario"); + cl.add ("host", CommandLine::Argument::Optional, "Nombre de la maquina donde se ubica el MySQL"); + cl.add ("db", CommandLine::Argument::Optional, "Nombre de la base de datos"); +} + +/* + * Las sentencias SQL usadas por este programana estaba originalmente escritas para Oracle, + * pero no hay que cambiar cada sentencia manualmente, s�lo hay que activar el traductor + * correspondiente y anna.dbms.mysql lo hace autom�ticamente. + */ +void Select::initialize () + throw (RuntimeException) +{ + CommandLine& ccll = CommandLine::instantiate (); + const char* host = ccll.exists ("host") ? ccll.getValue ("host"): NULL; + + a_db = new anna::dbms::mysql::Database (ccll.getValue ("db"), host); + a_db->setStatementTranslator (dbms::mysql::OracleTranslator::instantiate ()); +} + +void Select::run () + throw (RuntimeException) +{ + LOGMETHOD (TraceMethod tm ("Select", "run", ANNA_FILE_LOCATION)); + + CommandLine& cl (CommandLine::instantiate ()); + + Statement* select; + + dbms::Integer n (true); + dbms::String name (15, true); + dbms::Float zz (true); + dbms::TimeStamp tt (true); + + dbms::ResultCode resultCode; + + try { + Connection* connection = a_db->createConnection ("xselect", cl.getValue ("user"), cl.getValue ("password")); + + Guard guard (connection); + + select = a_db->createStatement ("select", "select xx,yy,zz, tt from anna_db_test"); + select->bindOutput ("XX", n); + select->bindOutput ("YY", name); + select->bindOutput ("zz", zz); + select->bindOutput ("tt", tt); + + cout << endl << " --- Leyendo ---" << endl; + resultCode = connection->execute (select); + + if (resultCode.successful () == true) { + while (select->fetch () == true) { + if (n.isNull () == true) + cout << ""; + else + cout << n; + + cout << " | YY: " << ((name.isNull () == true) ? "": name); + + cout << " | ZZ: "; + if (zz.isNull () == true) + cout << ""; + else + cout << zz.getValue (); + + cout << " | TT: " << ((tt.isNull () == true) ? "": tt.getCStringValue ()); + + cout << endl; + } + } + else + cout << resultCode.asString () << endl << endl; + } + catch (dbms::DatabaseException& edb) { + throw RuntimeException (edb); + } +} + + +