Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 9326)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 9327)
@@ -18,4 +18,11 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2009/02/12 Thomas Bretz
+
+   * datacenter/macros/fillsources.C:
+     - updated
+
+
+
  2009/02/11 Thomas Bretz
 
Index: /trunk/MagicSoft/Mars/datacenter/macros/fillsources.C
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/macros/fillsources.C	(revision 9326)
+++ /trunk/MagicSoft/Mars/datacenter/macros/fillsources.C	(revision 9327)
@@ -34,4 +34,5 @@
 #include <iostream>
 #include <iomanip>
+
 #include <fstream>
 
@@ -39,32 +40,11 @@
 #include <TSQLResult.h>
 
-#include "MSQLServer.h"
+#include "MSQLMagic.h"
 
 using namespace std;
 
-Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, const char *test)
+int fillsources(TString catalog, Bool_t dummy=kTRUE)
 {
-    TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test));
-
-    cout << "query: " << query << endl;
-
-    TSQLResult *res = serv.Query(query);
-    if (!res)
-        return kFALSE;
-
-    Bool_t rc = kFALSE;
-
-    TSQLRow *row=res->Next();
-    if (row && (*row)[0])
-        rc=kTRUE;
-
-    delete res;
-    return rc;
-}
-
-
-int fillsources(TString catalog)
-{
-    MSQLServer serv("sql.rc");
+    MSQLMagic serv("sql.rc");
     if (!serv.IsConnected())
     {
@@ -72,75 +52,55 @@
         return 0;
     }
-    cout << "insertdate" << endl;
-    cout << "----------" << endl;
+    cout << "insertsources" << endl;
+    cout << "-------------" << endl;
     cout << endl;
     cout << "Connected to " << serv.GetName() << endl;
+    cout << "Catalog file: " << catalog << endl;
     cout << endl;
 
-    TString source;
-    TString RA;
-    TString Dec;
-    TString waste;
+    serv.SetIsDummy(dummy);
+
     ifstream fin(catalog);
     if (!fin)
     {
         cout << "Could not open file " << catalog << endl;
-        return 0;
+        return 1;
     }
 
     while (1)
     {
+        TString src, ra, de, dum, epoch;
+
+        src.ReadToDelim(fin, ',');
+        dum.ReadToDelim(fin, ',');
+        ra.ReadToDelim(fin, ',');
+        de.ReadToDelim(fin, ',');
+        dum.ReadToDelim(fin, ',');
+        epoch.ReadToDelim(fin, '\n');
+
         if (!fin)
             break;
+/*
+        Double_t r,d;
+        if (!MAstro::Coordinate2Angle(ra, r))
+        {
+            cout << "ERROR - Interpreting right ascension: " << ra << endl;
+            return 2;
+        }
+        if (!MAstro::Coordinate2Angle(de, d))
+        {
+            cout << "ERROR - Interpreting declination: " << de << endl;
+            return 2;
+        }
+ */
+        TString vars(Form("fRightAscension='%s', fDeclination='%s', fEpoch='%s'",
+                           ra.Data(), de.Data(), epoch.Data()));
 
-        source.ReadToDelim(fin, ',');
-        waste.ReadToDelim(fin, ',');
-        RA.ReadToDelim(fin, ',');
-        Dec.ReadToDelim(fin, ',');
-        waste.ReadToDelim(fin, '\n');
+        TString where(Form("fSourceName='%s'", src.Data()));
 
-        cout << "source: " << source << endl;
-        cout << "RA: " << RA << endl;
-        cout << "Dec: " << Dec << endl;
-
-        //insert entry for date into the table SequenceBuildStatus,
-        // if entry is not yet existing
-        if (!ExistStr(serv, "fSourceName", "Source", source))
-        {
-            TString query(Form("INSERT Source SET fSourceName='%s', fRightAscension='%s', fDeclination='%s' ",
-                               source.Data(), RA.Data(), Dec.Data()));
-
-            cout << "query: " << query << endl;
-            /*
-             TSQLResult *res = serv.Query(query);
-             if (!res)
-             {
-             cout << "Error - could not insert entry" << endl;
-             return 0;
-             }
-             delete res;
-             */
-        }
-        else
-        {
-            cout << source << " already exists... do update. " << endl;
-
-            TString query(Form("Update Source SET fRightAscension='%s', fDeclination='%s' WHERE fSourceName='%s',",
-                               RA.Data(), Dec.Data(), source.Data()));
-
-            cout << "query: " << query << endl;
-            /*
-             TSQLResult *res = serv.Query(query);
-             if (!res)
-             {
-             cout << "Error - could not update entry" << endl;
-             return 0;
-             }
-             delete res;*/
-        }
+        if (!serv.InsertUpdate("Source", vars, where))
+            return 2;
     }
 
     return 1;
 }
-
-
