Ticket #22: query.patch

File query.patch, 3.8 kB (added by zork, 8 months ago)

some work on API, not branched yet

  • dba/test/querytest.h

    old new  
     1// 
     2// C++ Interface: querytest 
     3// 
     4// Description:  
     5// 
     6// 
     7// Author: Lukasz Michalski <lm@zork.pl>, (C) 2008 
     8// 
     9// Copyright: See COPYING file that comes with this distribution 
     10// 
     11// 
     12#ifndef DBA_TESTSQUERYTEST_H 
     13#define DBA_TESTSQUERYTEST_H 
     14 
     15#include <cppunit/TestCase.h> 
     16#include <cppunit/extensions/HelperMacros.h> 
     17 
     18namespace dba_tests { 
     19 
     20/** 
     21Test cases for query construction 
     22 
     23        @author Lukasz Michalski <lm@zork.pl> 
     24*/ 
     25class QueryTest : public CppUnit::TestCase { 
     26    CPPUNIT_TEST_SUITE(QueryTest); 
     27      CPPUNIT_TEST(type_string); 
     28    CPPUNIT_TEST_SUITE_END(); 
     29  public: 
     30    void type_string(); 
     31  private: 
     32}; 
     33 
     34} //namespace 
     35 
     36#endif 
  • dba/test/querytest.cpp

    old new  
     1// 
     2// C++ Implementation: querytest 
     3// 
     4// Description:  
     5// 
     6// 
     7// Author: Lukasz Michalski <lm@zork.pl>, (C) 2008 
     8// 
     9// Copyright: See COPYING file that comes with this distribution 
     10// 
     11// 
     12#include "querytest.h" 
     13#include "dba/query.h" 
     14#include <iostream> 
     15 
     16namespace dba_tests { 
     17 
     18CPPUNIT_TEST_SUITE_REGISTRATION(QueryTest); 
     19 
     20class A { 
     21  public: 
     22    void operator<<(const char* pArg) { 
     23      std::cout << pArg << std::endl; 
     24    }; 
     25}; 
     26 
     27class B { 
     28}; 
     29 
     30void 
     31into(const char* t) { 
     32  std::cout << "into " << t << std::endl; 
     33}; 
     34 
     35void  
     36QueryTest::type_string() { 
     37/*  dba::Query q; 
     38  int val = 4; 
     39  q << "INSERT INTO test_tbl VALUES" << val; 
     40  CPPUNIT_ASSERT(q == "SELECT somefield FROM sometable");*/ 
     41  A a; 
     42  B b; 
     43  a << "avs",into("b"); 
     44 
     45  dba::Query q("INSERT into t(a,b) values %d, %s"); 
     46  q << MyFilter(a) << MyFilter(b); 
     47   
     48  dba::DbResult* res = stream.sendQuery("SELECT a FROM t"); 
     49  while(res->fetchRow()) 
     50    res->getCustom(new MyFilter(a),1); 
     51     
     52}; 
     53 
     54} //namespace 
  • dba/dba/query.cpp

    old new  
     1// 
     2// C++ Implementation: query 
     3// 
     4// Description:  
     5// 
     6// 
     7// Author: Lukasz Michalski <lm@zork.pl>, (C) 2008 
     8// 
     9// Copyright: See COPYING file that comes with this distribution 
     10// 
     11// 
     12#include "query.h" 
     13 
     14namespace dba { 
     15 
     16Query::Query() 
     17  : std::string() 
     18{ 
     19} 
     20 
     21Query::Query(const char* pTemplate) 
     22  : std::string(pTemplate) 
     23{}; 
     24 
     25Query::~Query() 
     26{ 
     27} 
     28 
     29} //namespace 
  • dba/dba/query.h

    old new  
     1// 
     2// C++ Interface: query 
     3// 
     4// Description:  
     5// 
     6// 
     7// Author: Lukasz Michalski <lm@zork.pl>, (C) 2008 
     8// 
     9// Copyright: See COPYING file that comes with this distribution 
     10// 
     11// 
     12#ifndef DBAQUERY_H 
     13#define DBAQUERY_H 
     14 
     15#include <string> 
     16 
     17namespace dba { 
     18 
     19/** 
     20Helper class for simple query construction 
     21 
     22        @author Lukasz Michalski <lm@zork.pl> 
     23*/ 
     24class Query : public std::string { 
     25  public: 
     26    Query(); 
     27    Query(const char* pTemplate); 
     28    ~Query(); 
     29}; 
     30 
     31} //namespace 
     32 
     33#endif