Ignore:
Timestamp:
10/13/06 09:58:15 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

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

    r7952 r8061  
    5151//  On success the name of the key is returned.
    5252//
    53 TString MSQLMagic::QueryNameOfKey(TString col, const char *key)
     53TString MSQLMagic::QueryValOf(TString col, const char *ext, const char *key)
    5454{
    5555    if (col.EndsWith("KEY"))
     
    5858        col.Remove(0, 1);
    5959
    60     const TString query=Form("SELECT f%sName FROM %s WHERE f%sKEY=%s",
    61                              col.Data(), col.Data(), col.Data(), key);
     60    const TString query=Form("SELECT f%s%s FROM %s WHERE f%sKEY=%s",
     61                             col.Data(), ext, col.Data(), col.Data(), key);
    6262
    6363    TSQLResult *res = Query(query);
     
    7575// --------------------------------------------------------------------------
    7676//
     77// Return the name corresponding to a key. If col starts with f or
     78// end with KEY it is stripped.
     79//
     80//  If the query fails an empty string is returned.
     81//
     82//  On success the name of the key is returned.
     83//
     84TString MSQLMagic::QueryNameOfKey(TString col, const char *key)
     85{
     86    return QueryValOf(col, "Name", key);
     87}
     88
     89// --------------------------------------------------------------------------
     90//
     91// Return the value corresponding to a key. If col starts with f or
     92// end with KEY it is stripped.
     93//
     94//  If the query fails an empty string is returned.
     95//
     96//  On success the value of the key is returned.
     97//
     98TString MSQLMagic::QueryValOfKey(TString col, const char *key)
     99{
     100    return QueryValOf(col, "", key);
     101}
     102
     103// --------------------------------------------------------------------------
     104//
     105//  return the key of f[col]KEY where f[col][ext]=[val]
     106//
     107//  return -1 if the query failed or the KEY was not found
     108//  return  0 if the KEY could not be determined after inserting
     109//  return the KEY in case of success
     110//
     111Int_t MSQLMagic::QueryKeyOf(const char *col, const char *ext, const char *val)
     112{
     113    const TString query1 = Form("SELECT f%sKEY FROM %s WHERE f%s%s='%s'",
     114                                col, col, col, ext, val);
     115
     116    TSQLResult *res1 = Query(query1);
     117    if (!res1)
     118    {
     119        cout << "ERROR - Query has failed: " << query1 << endl;
     120        return -1;
     121    }
     122
     123    TSQLRow *row=res1->Next();
     124
     125    const Int_t rc1 = row && (*row)[0] ? atoi((*row)[0]) : -1;
     126    delete res1;
     127    return rc1;
     128}
     129
     130// --------------------------------------------------------------------------
     131//
     132//  return the key of f[col]KEY where f[col]=[val]
     133//
     134//  return -1 if the query failed or the KEY was not found
     135//  return  0 if the KEY could not be determined after inserting
     136//  return the KEY in case of success
     137//
     138Int_t MSQLMagic::QueryKeyOfVal(const char *col, const char *val)
     139{
     140    return QueryKeyOf(col, "", val);
     141}
     142
     143// --------------------------------------------------------------------------
     144//
    77145//  return the key of f[col]KEY where f[col]Name=[name]
    78146//
     
    86154Int_t MSQLMagic::QueryKeyOfName(const char *col, const char *name, Bool_t insert)
    87155{
    88     const TString query1 = Form("SELECT f%sKEY FROM %s WHERE f%sName='%s'",
    89                                 col, col, col, name);
    90 
    91     TSQLResult *res1 = Query(query1);
    92     if (!res1)
    93     {
    94         cout << "ERROR - Query has failed: " << query1 << endl;
    95         return -1;
    96     }
    97 
    98     TSQLRow *row=res1->Next();
    99 
    100     const Int_t rc1 = row && (*row)[0] ? atoi((*row)[0]) : -1;
    101 
    102     delete res1;
     156    const Int_t rc1 = QueryKeyOf(col, "Name", name);
    103157
    104158    if (rc1>=0)
Note: See TracChangeset for help on using the changeset viewer.