Ignore:
Timestamp:
10/17/06 19:13:14 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/datacenter/macros/insertdate.C

    r7460 r8107  
    4545#include <iostream>
    4646#include <iomanip>
    47 #include <fstream>
    4847
    4948#include <TEnv.h>
    5049
    51 #include <MSQLServer.h>
    52 #include <TSQLRow.h>
    53 #include <TSQLResult.h>
     50#include <MSQLMagic.h>
    5451
    5552using namespace std;
    56 
    57 Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, const char *test)
    58 {
    59     TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test));
    60 
    61     cout << "query: " << query << endl;
    62 
    63     TSQLResult *res = serv.Query(query);
    64     if (!res)
    65         return kFALSE;
    66 
    67     Bool_t rc = kFALSE;
    68 
    69     TSQLRow *row=res->Next();
    70     if (row && (*row)[0])
    71         rc=kTRUE;
    72 
    73     delete res;
    74     return rc;
    75 }
    76 
    7753
    7854int insertdate(TString date)
     
    8056    TEnv env("sql.rc");
    8157
    82     MSQLServer serv(env);
     58    MSQLMagic serv(env);
    8359    if (!serv.IsConnected())
    8460    {
     
    9470    //insert entry for date into the table SequenceBuildStatus,
    9571    // if entry is not yet existing
    96     if (!ExistStr(serv, "fDate", "SequenceBuildStatus", date))
     72    if (!serv.ExistStr("fDate", "SequenceBuildStatus", date))
    9773    {
    98         TString query(Form("INSERT SequenceBuildStatus SET fDate='%s', fCCFilled=Now() ",
    99                            date.Data()));
     74        TString vals(Form("fDate='%s', fCCFilled=Now()", date.Data()));
    10075
    101         TSQLResult *res = serv.Query(query);
    102         if (!res)
    103         {
    104             cout << "Error - could not insert entry" << endl;
    105             return 0;
    106         }
    107         delete res;
     76        const Int_t rc = serv.Insert("SequenceBuildStatus", vals);
     77        if (rc==kFALSE) // Query failed
     78            return -1;
     79        //if (rc<0)       // Dummy mode
     80        //    return 0;
    10881    }
    10982    else
     
    11184        cout << date << " already exists... do update. " << endl;
    11285
    113         TString query="UPDATE SequenceBuildStatus SET fCCFilled=Now(), fExclusionsDone=NULL, ";
    114         query +=Form("fSequenceEntriesBuilt=NULL WHERE fDate='%s' ", date.Data());
     86        const Int_t rc = serv.Update("SequenceBuildStatus",
     87                                     "fCCFilled=Now(), fExclusionsDone=NULL, fSequenceEntriesBuilt=NULL",
     88                                     Form("fDate='%s'", date.Data()));
    11589
    116         TSQLResult *res = serv.Query(query);
    117         if (!res)
    118         {
    119             cout << "Error - could not update entry" << endl;
    120             return 0;
    121         }
    122         delete res;
     90        if (rc==kFALSE) // Query failed
     91            return -1;
     92        //if (rc<0)       // Dummy mode
     93        //    return 0;
     94
    12395    }
    12496
Note: See TracChangeset for help on using the changeset viewer.