@@ -693,7 +693,9 @@ func (sr *systemTableRow) skip() bool {
693
693
// callback will be passed the value associated with that column, if
694
694
// found, and its return value overwrites the value for that
695
695
// column. The callback is not called if the column name is invalid.
696
- func (sr * systemTableRow ) processColumn (column string , fn func (interface {}) interface {}) {
696
+ func (sr * systemTableRow ) processColumn (
697
+ column string , skipMissing bool , fn func (interface {}) interface {},
698
+ ) {
697
699
if sr .skip () {
698
700
return
699
701
}
@@ -702,6 +704,9 @@ func (sr *systemTableRow) processColumn(column string, fn func(interface{}) inte
702
704
hasCol := colIdx < len (sr .columns ) && sr .columns [colIdx ] == column
703
705
704
706
if ! hasCol {
707
+ if skipMissing {
708
+ return
709
+ }
705
710
sr .err = fmt .Errorf ("could not find column %s on %s" , column , sr .table )
706
711
return
707
712
}
@@ -712,19 +717,19 @@ func (sr *systemTableRow) processColumn(column string, fn func(interface{}) inte
712
717
// Matches allows the caller to only apply certain changes if the
713
718
// value of a certain column matches a given value.
714
719
func (sr * systemTableRow ) Matches (column string , value interface {}) * systemTableRow {
715
- sr .processColumn (column , func (actualValue interface {}) interface {} {
720
+ sr .processColumn (column , false /*skipMissing */ , func (actualValue interface {}) interface {} {
716
721
sr .matches = reflect .DeepEqual (actualValue , value )
717
722
return actualValue
718
723
})
719
724
720
725
return sr
721
726
}
722
727
723
- // WithSentinel replaces the contents of the given columns with a
724
- // fixed sentinel value.
725
- func (sr * systemTableRow ) WithSentinel (columns ... string ) * systemTableRow {
728
+ // WithSentinelIfExists replaces the contents of the given columns with a
729
+ // fixed sentinel value, if the column exists .
730
+ func (sr * systemTableRow ) WithSentinelIfExists (columns ... string ) * systemTableRow {
726
731
for _ , column := range columns {
727
- sr .processColumn (column , func (value interface {}) interface {} {
732
+ sr .processColumn (column , true /* skipMissing */ , func (value interface {}) interface {} {
728
733
return systemTableSentinel
729
734
})
730
735
}
@@ -819,7 +824,7 @@ func (sc *systemTableContents) settingsHandler(
819
824
// `name` column equals 'version'
820
825
Matches ("name" , "version" ).
821
826
// use the sentinel value for every column in the settings table
822
- WithSentinel (columns ... ).
827
+ WithSentinelIfExists (columns ... ).
823
828
Values ()
824
829
}
825
830
@@ -837,7 +842,7 @@ func (sc *systemTableContents) scheduledJobsHandler(
837
842
values []interface {}, columns []string ,
838
843
) ([]interface {}, error ) {
839
844
return newSystemTableRow (sc .table , values , columns ).
840
- WithSentinel ("next_run" , "schedule_details" , "schedule_state" ).
845
+ WithSentinelIfExists ("next_run" , "schedule_details" , "schedule_state" ).
841
846
Values ()
842
847
}
843
848
@@ -848,15 +853,15 @@ func (sc *systemTableContents) usersHandler(
848
853
values []interface {}, columns []string ,
849
854
) ([]interface {}, error ) {
850
855
return newSystemTableRow (sc .table , values , columns ).
851
- WithSentinel ("estimated_last_login_time" ).
856
+ WithSentinelIfExists ("estimated_last_login_time" ).
852
857
Values ()
853
858
}
854
859
855
860
func (sc * systemTableContents ) commentsHandler (
856
861
values []interface {}, columns []string ,
857
862
) ([]interface {}, error ) {
858
863
return newSystemTableRow (sc .table , values , columns ).
859
- WithSentinel ("object_id" ). // object_id is rekeyed
864
+ WithSentinelIfExists ("object_id" ). // object_id is rekeyed
860
865
Values ()
861
866
}
862
867
0 commit comments