Re: [ROOT] TSQLServer::Query enhancement request

From: Christian Holm Christensen (cholm@hehi03.nbi.dk)
Date: Wed Mar 06 2002 - 17:14:18 MET


Hi Anton, Fons, et al

On Wed, 6 Mar 2002 15:41:07 +0100
anton.fokin@nl.fortisbank.com wrote
concerning "[ROOT] TSQLServer::Query enhancement request":
> Hi Fons et.al.,
> 
> could you enhance SQLServer::Query() so that it takes format string and an
> optional list of parameters lke printf().
> 
> SQLServer::Query("DELETE FROM stock WHERE name = %s", Stock->GetName());


I think a better thing would be to have a TSQLQuery class, and all
the Query methods could accept this kind of object as an argument.   

A possible interface could be 

  class TSQLQuery : public TObject
  {
  private: 
    TString fQuery;   // The actual query 
  public: 
    TSQLQuery(const Char_t* query); 
    TSQLQuery(const Char_t* fmt, ...); 
    
    static TSQLQuery* Select(const Char_t* fields, 
	                     const Char_t* tables, 
			     const Char_t* conditions=0, 
			     const Char_t* other=0); 
    static TSQLQuery* Insert(const Char_t* table, 
			     const Char_t* values);
    static TSQLQuery* Update(const Char_t* table, 
	                     const Char_t* variables, 
			     const Char_t* values, 
			     cosnt Char_t* conditions);

    TSQLQuery& operator+=(const Char_t* query);
    TSQLQuery& operator+=(const TString& query);
    TSQLQuery& operator<<(const Char_t* query);
    TSQLQuery& operator<<(const TString& query);
    
    void              Reset() { fQuery.Clear(); }
    const TString&    Query() const { return fQuery; }
    const Char_t*     Data()  const { return fQuery.Data(); }
    operator const Char_t*()  { return fQuery.Data(); }
    ...

    ClassDef(TSQLQuery, 1)  // SQL query class
  };

Maybe, this would help in making real SQL queries for TTree's. The
class could have a member function 

  TSelection* TSQLQuery::Selection(TTree* tree) const 

that parses the SQL string, matches field and table names to branches
and leaves in the TTree, and make the appropiate TSelection object. 

Just my two cents worth. 

Yours, 

Christian Holm Christensen -------------------------------------------
Address: Sankt Hansgade 23, 1. th.           Phone:  (+45) 35 35 96 91 
         DK-2200 Copenhagen N                Cell:   (+45) 28 82 16 23
         Denmark                             Office: (+45) 353  25 305 
Email:   cholm@nbi.dk                        Web:    www.nbi.dk/~cholm



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:44 MET