Changeset 8061 for trunk/MagicSoft/Mars/msql/MSQLMagic.cc
- Timestamp:
- 10/13/06 09:58:15 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/msql/MSQLMagic.cc
r7952 r8061 51 51 // On success the name of the key is returned. 52 52 // 53 TString MSQLMagic::Query NameOfKey(TString col, const char *key)53 TString MSQLMagic::QueryValOf(TString col, const char *ext, const char *key) 54 54 { 55 55 if (col.EndsWith("KEY")) … … 58 58 col.Remove(0, 1); 59 59 60 const TString query=Form("SELECT f%s NameFROM %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); 62 62 63 63 TSQLResult *res = Query(query); … … 75 75 // -------------------------------------------------------------------------- 76 76 // 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 // 84 TString 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 // 98 TString 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 // 111 Int_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 // 138 Int_t MSQLMagic::QueryKeyOfVal(const char *col, const char *val) 139 { 140 return QueryKeyOf(col, "", val); 141 } 142 143 // -------------------------------------------------------------------------- 144 // 77 145 // return the key of f[col]KEY where f[col]Name=[name] 78 146 // … … 86 154 Int_t MSQLMagic::QueryKeyOfName(const char *col, const char *name, Bool_t insert) 87 155 { 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); 103 157 104 158 if (rc1>=0)
Note:
See TracChangeset
for help on using the changeset viewer.