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 //
11 #include <anna/core/core.hpp>
12 #include <anna/dbms/dbms.hpp>
13 #include <anna/app/app.hpp>
15 #include <anna/dbms.mysql/Database.hpp>
16 #include <anna/dbms.mysql/OracleTranslator.hpp>
18 class Select : public Application {
21 ~Select () { delete a_db; }
24 anna::dbms::Database* a_db;
26 void initialize () throw (RuntimeException);
27 void run () throw (RuntimeException);
32 int main (int argc, const char** argv)
34 CommandLine& commandLine (CommandLine::instantiate ());
38 commandLine.initialize (argv, argc);
39 commandLine.verify ();
41 Logger::setLevel (Logger::Debug);
42 Logger::initialize ("copy", new TraceWriter ("xselect.trace", 1024 * 1024));
46 catch (Exception& ex) {
47 cout << ex.asString () << endl;
54 Application ("xselect", "Copiador de la tabla ad_funcionalidades", "1.0"),
57 CommandLine& cl (CommandLine::instantiate ());
59 cl.add ("user", CommandLine::Argument::Mandatory, "Nombre del usuario");
60 cl.add ("password", CommandLine::Argument::Mandatory, "Clave del usuario");
61 cl.add ("host", CommandLine::Argument::Optional, "Nombre de la maquina donde se ubica el MySQL");
62 cl.add ("db", CommandLine::Argument::Optional, "Nombre de la base de datos");
66 * Las sentencias SQL usadas por este programana estaba originalmente escritas para Oracle,
67 * pero no hay que cambiar cada sentencia manualmente, s�lo hay que activar el traductor
68 * correspondiente y anna.dbms.mysql lo hace autom�ticamente.
70 void Select::initialize ()
71 throw (RuntimeException)
73 CommandLine& ccll = CommandLine::instantiate ();
74 const char* host = ccll.exists ("host") ? ccll.getValue ("host"): NULL;
76 a_db = new anna::dbms::mysql::Database (ccll.getValue ("db"), host);
77 a_db->setStatementTranslator (dbms::mysql::OracleTranslator::instantiate ());
81 throw (RuntimeException)
83 LOGMETHOD (TraceMethod tm ("Select", "run", ANNA_FILE_LOCATION));
85 CommandLine& cl (CommandLine::instantiate ());
90 dbms::Integer n (true);
91 dbms::String name (15, true);
92 dbms::Float zz (true);
93 dbms::TimeStamp tt (true);
95 dbms::ResultCode resultCode;
98 Connection* connection = a_db->createConnection ("xselect", cl.getValue ("user"), cl.getValue ("password"));
100 Guard guard (connection);
102 select = a_db->createStatement ("select", "select xx,yy,zz, tt from anna_db_test");
103 select->bindOutput ("XX", n);
104 select->bindOutput ("YY", name);
105 select->bindOutput ("zz", zz);
106 select->bindOutput ("tt", tt);
108 cout << endl << " --- Leyendo ---" << endl;
109 resultCode = connection->execute (select);
111 if (resultCode.successful () == true) {
112 while (select->fetch () == true) {
113 if (n.isNull () == true)
118 cout << " | YY: " << ((name.isNull () == true) ? "<null>": name);
121 if (zz.isNull () == true)
124 cout << zz.getValue ();
126 cout << " | TT: " << ((tt.isNull () == true) ? "<null>": tt.getCStringValue ());
132 cout << resultCode.asString () << endl << endl;
134 catch (dbms::DatabaseException& edb) {
135 throw RuntimeException (edb);