Log Message:
-----------
Allow insertion of steps & schedules with SQL > 255 chars in length from dlgJob.
Ensure record IDs are correctly set.

Modified Files:
--------------
    pgadmin3/src/agent:
        dlgJob.cpp (r1.17 -> r1.18)
        dlgSchedule.cpp (r1.20 -> r1.21)
        dlgStep.cpp (r1.17 -> r1.18)
    pgadmin3/src/ui:
        dlgProperty.cpp (r1.118 -> r1.119)

Index: dlgStep.cpp
===================================================================
RCS file: /projects/pgadmin3/src/agent/dlgStep.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -Lsrc/agent/dlgStep.cpp -Lsrc/agent/dlgStep.cpp -u -w -r1.17 -r1.18
--- src/agent/dlgStep.cpp
+++ src/agent/dlgStep.cpp
@@ -168,7 +168,7 @@
         if (jobId)
             jstjobid = NumToStr(jobId);
         else
-            jstjobid = wxT("<id>");
+            jstjobid = wxT("<JobId>");
 
         if (!cbDatabase->GetSelection())
             db = wxT("NULL");
@@ -176,7 +176,7 @@
             db = qtString(cbDatabase->GetValue());
 
         sql = wxT("INSERT INTO pgagent.pga_jobstep (jstid, jstjobid, jstname, 
jstdesc, jstenabled, jstkind, jstonerror, jstcode, jstdbname)\n")
-              wxT("SELECT <id>, ") + jstjobid + wxT(", ") + qtString(name) + 
wxT(", ") + qtString(txtComment->GetValue()) + wxT(", ")
+              wxT("SELECT <StpId>, ") + jstjobid + wxT(", ") + qtString(name) 
+ wxT(", ") + qtString(txtComment->GetValue()) + wxT(", ")
                 + BoolToStr(chkEnabled->GetValue()) + wxT(", ") + 
qtString(kind) + wxT(", ") 
                 + qtString(onerror) + wxT(", ") + qtString(sqlBox->GetText()) 
+ wxT(", ") + db;
     }
Index: dlgSchedule.cpp
===================================================================
RCS file: /projects/pgadmin3/src/agent/dlgSchedule.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -Lsrc/agent/dlgSchedule.cpp -Lsrc/agent/dlgSchedule.cpp -u -w -r1.20 -r1.21
--- src/agent/dlgSchedule.cpp
+++ src/agent/dlgSchedule.cpp
@@ -210,11 +210,11 @@
         if (jobId)
             jscjobid = NumToStr(jobId);
         else
-            jscjobid = wxT("<id>");
+            jscjobid = wxT("<JobId>");
 
                // Build the various arrays of values
         sql = wxT("INSERT INTO pgagent.pga_schedule (jscid, jscjobid, jscname, 
jscdesc, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths, 
jscenabled, jscstart, jscend)\n")
-              wxT("VALUES(<id>, ") + jscjobid + wxT(", ") + qtString(name) + 
wxT(", ") + qtString(txtComment->GetValue()) + wxT(", ")
+              wxT("VALUES(<SchId>, ") + jscjobid + wxT(", ") + qtString(name) 
+ wxT(", ") + qtString(txtComment->GetValue()) + wxT(", ")
                                + wxT("'") + ChkListBox2PgArray(chkMinutes) + 
wxT("', ")
                                + wxT("'") + ChkListBox2PgArray(chkHours) + 
wxT("', ")
                                + wxT("'") + ChkListBox2PgArray(chkWeekdays) + 
wxT("', ")
Index: dlgJob.cpp
===================================================================
RCS file: /projects/pgadmin3/src/agent/dlgJob.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -Lsrc/agent/dlgJob.cpp -Lsrc/agent/dlgJob.cpp -u -w -r1.17 -r1.18
--- src/agent/dlgJob.cpp
+++ src/agent/dlgJob.cpp
@@ -246,9 +246,15 @@
         lstSteps->SetItem(pos, 1, step.GetComment());
 
         if (lstSteps->GetText(pos, 3).IsEmpty())
-            lstSteps->SetItem(pos, 2, step.GetInsertSql());
+               {
+                       wxString *stepSql = new wxString(step.GetInsertSql());
+                       lstSteps->SetItemData(pos, (long)stepSql);
+               }
         else
-            lstSteps->SetItem(pos, 2, step.GetUpdateSql());
+               {
+                       wxString *stepSql = new wxString(step.GetUpdateSql());
+                       lstSteps->SetItemData(pos, (long)stepSql);
+               }
 
         CheckChange();
     }
@@ -270,7 +276,8 @@
     if (step.Go(true) >= 0)
     {
         int pos = lstSteps->AppendItem(PGAICON_STEP, step.GetName(), 
step.GetComment());
-        lstSteps->SetItem(pos, 2, step.GetInsertSql());
+               wxString *stepSql = new wxString(step.GetInsertSql());
+               lstSteps->SetItemData(pos, (long)stepSql);
         CheckChange();
     }
 }
@@ -278,6 +285,7 @@
 
 void dlgJob::OnRemoveStep(wxCommandEvent &ev)
 {
+       delete (wxString *)lstSteps->GetItemData(lstSteps->GetSelection());
     lstSteps->DeleteCurrentItem();
 
     btnChangeStep->Disable();
@@ -309,9 +317,15 @@
         lstSchedules->SetItem(pos, 1, schedule.GetComment());
 
         if (lstSchedules->GetText(pos, 3).IsEmpty())
-            lstSchedules->SetItem(pos, 2, schedule.GetInsertSql());
+               {
+                       wxString *scheduleSql = new 
wxString(schedule.GetInsertSql());
+                       lstSchedules->SetItemData(pos, (long)scheduleSql);
+               }
         else
-            lstSchedules->SetItem(pos, 2, schedule.GetUpdateSql());
+               {
+                       wxString *scheduleSql = new 
wxString(schedule.GetUpdateSql());
+                       lstSchedules->SetItemData(pos, (long)scheduleSql);
+               }
 
         CheckChange();
     }
@@ -326,7 +340,8 @@
     if (schedule.Go(true) >= 0)
     {
         int pos = lstSchedules->AppendItem(PGAICON_SCHEDULE, 
schedule.GetName(), schedule.GetComment());
-        lstSchedules->SetItem(pos, 2, schedule.GetInsertSql());
+        wxString *scheduleSql = new wxString(schedule.GetInsertSql());
+               lstSchedules->SetItemData(pos, (long)scheduleSql);
         CheckChange();
     }
 }
@@ -334,6 +349,7 @@
 
 void dlgJob::OnRemoveSchedule(wxCommandEvent &ev)
 {
+       delete (wxString 
*)lstSchedules->GetItemData(lstSchedules->GetSelection());
     lstSchedules->DeleteCurrentItem();
 
     btnChangeSchedule->Disable();
@@ -350,7 +366,7 @@
     if (!job)
     {
         sql = wxT("INSERT INTO pgagent.pga_job (jobid, jobjclid, jobname, 
jobdesc, jobenabled)\n")
-              wxT("SELECT <id>, jcl.jclid, ") + qtString(GetName()) + 
+              wxT("SELECT <JobId>, jcl.jclid, ") + qtString(GetName()) + 
               wxT(", ") + qtString(txtComment->GetValue()) + wxT(", ") + 
BoolToStr(chkEnabled->GetValue()) + wxT("\n")
               wxT("  FROM pgagent.pga_jobclass jcl WHERE jclname=") + 
qtString(cbJobclass->GetValue());
     }
@@ -416,10 +432,14 @@
             if (index >= 0)
                 tmpSteps.RemoveAt(index);
         }
-        str=lstSteps->GetText(pos, 2);
+               
+               if(lstSteps->GetItemData(pos))
+               {
+                       str=*(wxString *)lstSteps->GetItemData(pos);
         if (!str.IsEmpty())
             sql += str + wxT(";\n");
     }
+    }
 
     for (index = 0 ; index < (int)tmpSteps.GetCount() ; index++)
     {
@@ -437,10 +457,13 @@
             if (index >= 0)
                 tmpSchedules.RemoveAt(index);
         }
-        str=lstSchedules->GetText(pos, 2);
+               if(lstSchedules->GetItemData(pos))
+               {
+                       str=*(wxString *)lstSchedules->GetItemData(pos);
         if (!str.IsEmpty())
             sql += str + wxT(";\n");
     }
+    }
 
     for (index = 0 ; index < (int)tmpSchedules.GetCount() ; index++)
     {
Index: dlgProperty.cpp
===================================================================
RCS file: /projects/pgadmin3/src/ui/dlgProperty.cpp,v
retrieving revision 1.118
retrieving revision 1.119
diff -Lsrc/ui/dlgProperty.cpp -Lsrc/ui/dlgProperty.cpp -u -w -r1.118 -r1.119
--- src/ui/dlgProperty.cpp
+++ src/ui/dlgProperty.cpp
@@ -1312,20 +1312,36 @@
     sql=GetInsertSql();
     if (!sql.IsEmpty())
     {
-               if (sql.Contains(wxT("<id>")))
+               int pos;
+               long jobId, schId, stpId;
+               if (sql.Contains(wxT("<JobId>")))
                {
-                       if (sql.StartsWith(wxT("INSERT INTO pgagent.pga_job")))
-                               
recId=StrToLong(connection->ExecuteScalar(wxT("SELECT 
nextval('pgagent.pga_job_jobid_seq');")));
-                       else if (sql.StartsWith(wxT("INSERT INTO 
pgagent.pga_schedule")))
-                               
recId=StrToLong(connection->ExecuteScalar(wxT("SELECT 
nextval('pgagent.pga_schedule_jscid_seq');")));
-                       else if (sql.StartsWith(wxT("INSERT INTO 
pgagent.pga_jobstep")))
-                               
recId=StrToLong(connection->ExecuteScalar(wxT("SELECT 
nextval('pgagent.pga_jobstep_jstid_seq');")));
+                       jobId=StrToLong(connection->ExecuteScalar(wxT("SELECT 
nextval('pgagent.pga_job_jobid_seq');")));
+            while ((pos=sql.Find(wxT("<JobId>"))) >= 0)
+                sql = sql.Left(pos) + NumToStr(jobId) + sql.Mid(pos+7);
+               }
 
-            int pos;
-            while ((pos=sql.Find(wxT("<id>"))) >= 0)
-                sql = sql.Left(pos) + NumToStr(recId) + sql.Mid(pos+4);
+               if (sql.Contains(wxT("<SchId>")))
+               {
+                       schId=StrToLong(connection->ExecuteScalar(wxT("SELECT 
nextval('pgagent.pga_schedule_jscid_seq');")));
+                       while ((pos=sql.Find(wxT("<SchId>"))) >= 0)
+                sql = sql.Left(pos) + NumToStr(schId) + sql.Mid(pos+7);
                }
 
+               if (sql.Contains(wxT("<StpId>")))
+               {
+                       stpId=StrToLong(connection->ExecuteScalar(wxT("SELECT 
nextval('pgagent.pga_jobstep_jstid_seq');")));
+                       while ((pos=sql.Find(wxT("<StpId>"))) >= 0)
+                sql = sql.Left(pos) + NumToStr(stpId) + sql.Mid(pos+7);
+               }
+
+               // OK, so what are we inserting? We need to set recId 
appropriately.
+               if (sql.StartsWith(wxT("INSERT INTO pgagent.pga_job")))
+                       recId = jobId;
+               else if (sql.StartsWith(wxT("INSERT INTO 
pgagent.pga_schedule")))
+                       recId = schId;
+               else if (sql.StartsWith(wxT("INSERT INTO pgagent.pga_jobstep")))
+                       recId = stpId;
 
         pgSet *set=connection->ExecuteSet(sql);
         if (set)
@@ -1343,8 +1359,23 @@
     if (!sql.IsEmpty())
     {
         int pos;
-        while ((pos=sql.Find(wxT("<id>"))) >= 0)
-            sql = sql.Left(pos) + NumToStr(recId) + sql.Mid(pos+4);
+        while ((pos=sql.Find(wxT("<JobId>"))) >= 0)
+            sql = sql.Left(pos) + NumToStr(recId) + sql.Mid(pos+7);
+
+               long newId;
+               if (sql.Contains(wxT("<SchId>")))
+               {
+                       newId=StrToLong(connection->ExecuteScalar(wxT("SELECT 
nextval('pgagent.pga_schedule_jscid_seq');")));
+                       while ((pos=sql.Find(wxT("<SchId>"))) >= 0)
+                sql = sql.Left(pos) + NumToStr(newId) + sql.Mid(pos+7);
+               }
+
+               if (sql.Contains(wxT("<StpId>")))
+               {
+                       newId=StrToLong(connection->ExecuteScalar(wxT("SELECT 
nextval('pgagent.pga_jobstep_jstid_seq');")));
+                       while ((pos=sql.Find(wxT("<StpId>"))) >= 0)
+                sql = sql.Left(pos) + NumToStr(newId) + sql.Mid(pos+7);
+               }
 
         if (!connection->ExecuteVoid(sql))
         {
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
      joining column's datatypes do not match

Reply via email to