Ignore:
Timestamp:
07/23/08 14:15:14 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/msql
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/msql/MSQLMagic.cc

    r9001 r9039  
    195195Bool_t MSQLMagic::ExistStr(const char *column, const char *table, const char *test, const char *where)
    196196{
    197     TString query(Form("SELECT %s FROM %s WHERE %s='%s' %s %s", column, table, column, test, where?"AND":"", where?where:""));
     197    TString query = test ?
     198        Form("SELECT %s FROM %s WHERE %s='%s' %s %s", column, table, column, test, where?"AND":"", where?where:"") :
     199        Form("SELECT %s FROM %s WHERE %s", column, table, where);
     200
    198201    TSQLResult *res = Query(query);
    199202    if (!res)
     
    211214    delete res;
    212215    return rc;
     216}
     217
     218// --------------------------------------------------------------------------
     219//
     220// Check if at least one row with one field exists in table
     221// defined by where
     222//
     223Bool_t MSQLMagic::ExistRow(const char *table, const char *where)
     224{
     225    return ExistStr("*", table, 0, where);
    213226}
    214227
     
    306319// --------------------------------------------------------------------------
    307320//
     321// An abbreviation for checking whether a row with the condition where
     322// exists. If no such row exist Insert vars into table, otherwise update
     323// vars in table at row(s) defined by where.
     324//
     325Int_t MSQLMagic::InsertUpdate(const char *table, const char *vars, const char *where)
     326{
     327    return ExistRow(table, where) ?
     328        Update(table, vars, where) :
     329        Insert(table, vars);
     330}
     331
     332// --------------------------------------------------------------------------
     333//
    308334// An abbreviation for a Dalete-Query.
    309335//
  • trunk/MagicSoft/Mars/msql/MSQLMagic.h

    r9001 r9039  
    4545    Int_t   QueryKeyOf(const char *col, const char *ext, const char *val);
    4646    Bool_t  ExistStr(const char *column, const char *table, const char *test, const char *where=0);
     47    Bool_t  ExistRow(const char *table, const char *where);
    4748
    4849    Int_t Insert(const char *table, const char *vars, const char *where=0);
     
    5051    Int_t Delete(const char *table, const char *where);
    5152    Int_t InsertUpdate(const char *table, const char *col, const char *val, const char *vars);
     53    Int_t InsertUpdate(const char *table, const char *vars, const char *where);
    5254
    5355    void Delete(const Option_t *o) { TObject::Delete(o); }
Note: See TracChangeset for help on using the changeset viewer.