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