@@ -27,124 +27,6 @@ cat(" qry=",qry,"\n")
2727 dbGlb $ tbl $ Delete = FALSE
2828}
2929
30- checkMinColumnDefs <- function (dbo ,progress = NULL ,pn = 0 )
31- {
32- cat (" in checkMinColumnDefs\n " )
33- for (initnm in c(" FVS_StandInit" ," FVS_PlotInit" ," FVS_StandInit_Cond" ))
34- {
35- stdInit = getTableName(dbo ,initnm )
36- if (! is.null(stdInit )) break
37- }
38- cat (" stdInit=" ,stdInit ," \n " )
39- if (is.null(stdInit )) return (" No standinit table was found." )
40- fields = try(dbListFields(dbo ,stdInit ))
41- # if this is an error, then FVS_StandInit does not exist and this is an error
42- # where the standard fixup in this case is to try recovery of the database.
43- if (class(fields ) == " try-error" ) return (" Geting column names from StandInit table failed." )
44- sID = FALSE
45- sCN = FALSE
46- grp = FALSE
47- # make sure groups are defined, if missing set one to "All_Stands"
48- if (! is.null(progress )) progress $ set(message = paste0(" Checking " ,stdInit ),
49- value = pn + 1 , detail = " Groups" )
50- if (length(grep(" Groups" ,fields ,ignore.case = TRUE )) == 0 )
51- {
52- qt = try(dbExecute(dbo ,paste0(" alter table '" ,stdInit ,
53- " ' add column Groups text default 'All All_Stands'" )))
54- if (class(qt )== " try-error" ) return (" Adding group 'All All_Stands' to StandInit failed." )
55- grp = TRUE
56- }
57- # make sure Stand_ID is defined
58- if (! is.null(progress )) progress $ set(message = paste0(" Checking " ,stdInit ),
59- value = pn + 2 , detail = " Stand_ID" )
60- if (length(grep(" Stand_ID" ,fields ,ignore.case = TRUE )) == 0 )
61- {
62- qt = try(dbExecute(dbo ,paste0(" alter table '" ,stdInit ,
63- " ' add column Stand_ID text" )))
64- if (class(qt )== " try-error" ) return (" Adding 'Stand_ID' to StandInit failed." )
65- sID = TRUE
66- }
67- # make sure Stand_CN is defined
68- if (! is.null(progress )) progress $ set(message = paste0(" Checking " ,stdInit ),
69- value = pn + 3 , detail = " Stand_CN" )
70- if (length(grep(" Stand_CN" ,fields ,ignore.case = TRUE )) == 0 )
71- {
72- qt = try(dbExecute(dbo ,paste0(" alter table '" ,stdInit ,
73- " ' add column Stand_CN text" )))
74- if (class(qt )== " try-error" ) return (" Adding 'Stand_CN' to StandInit failed." )
75- sCN = TRUE
76- }
77- # make sure Inv_Year is defined
78- if (! is.null(progress )) progress $ set(message = paste0(" Checking " ,stdInit ),
79- value = pn + 4 , detail = " Inv_Year " )
80- if (length(grep(" Inv_Year" ,fields ,ignore.case = TRUE )) == 0 )
81- {
82- year = substring(as.character(Sys.time()),1 ,4 )
83- qt = try((dbExecute(dbo ,paste0(paste0(" alter table '" ,stdInit ,
84- " ' add column Inv_Year integer default " ,year )))))
85- if (class(qt )== " try-error" ) return (" Adding 'Inv_Year' to StandInit failed." )
86- }
87- # make sure FVSKeywords is defined
88- if (! is.null(progress )) progress $ set(message = paste0(" Checking " ,stdInit ),
89- value = pn + 5 , detail = " FVSKeywords " )
90- if (length(grep(" FVSKeywords" ,fields ,ignore.case = TRUE )) == 0 )
91- {
92- year = substring(as.character(Sys.time()),1 ,4 )
93- qt = try(dbExecute(dbo ,paste0(" alter table '" ,stdInit ,
94- " ' add column FVSKeywords text" )))
95- if (class(qt )== " try-error" ) return (" Adding 'FVSKeywords' to StandInit failed." )
96- }
97- # make sure Sam_Wt is defined
98- if (! is.null(progress )) progress $ set(message = paste0(" Checking " ,stdInit ),
99- value = pn + 6 , detail = " Sam_Wt" )
100- if (length(grep(" Sam_Wt" ,fields ,ignore.case = TRUE )) == 0 )
101- {
102- qt = try(dbExecute(dbo ,paste0(" alter table " ,stdInit ,
103- " add column Sam_Wt real" )))
104- if (class(qt )== " try-error" ) return (" Adding 'Sam_Wt' to StandInit failed." )
105- }
106- cat (" in checkMinColumnDefs sID=" ,sID ," sCN=" ,sCN ," \n " )
107- if (sID || sCN )
108- {
109- fvsInit = try(dbReadTable(dbo ,stdInit ))
110- if (class(fvsInit )== " try-error" ) return (" Can not read StandInit." )
111- if (! is.null(progress )) progress $ set(message = paste0(" Checking " ,stdInit ),
112- value = pn + 7 , detail = " Stand_ID and Stand_CN consistent" )
113- if (nrow(fvsInit ))
114- {
115- isCN = grep(" Stand_CN" ,names(fvsInit ),ignore.case = TRUE )
116- if (sID ) fvsInit $ Stand_ID =
117- if (sCN ) paste0(" Stand" ,1 : nrow(fvsInit )) else fvsInit [,isCN ]
118- isID = grep(" Stand_ID" ,names(fvsInit ),ignore.case = TRUE )
119- if (sCN )
120- {
121- isCN = grep(" Stand_CN" ,names(fvsInit ),ignore.case = TRUE )
122- fvsInit [,isCN ] = fvsInit [,isID ]
123- isID = grep(" Stand_ID" ,names(fvsInit ),ignore.case = TRUE )
124- fvsInit [,isCN ] = fvsInit [,isID ]
125- }
126- dbWriteTable(dbo ,stdInit ,fvsInit ,overwrite = TRUE )
127- }
128- }
129- # check groups
130- if (! grp )
131- {
132- if (! is.null(progress )) progress $ set(message = paste0(" Checking " ,stdInit ),
133- value = pn + 8 , detail = " Groups content" )
134- grps = try(dbGetQuery(dbo ,paste0(" select Groups from '" ,stdInit ," '" )))
135- if (class(grps )== " try-error" ) return (" Can not read Groups from StandInit." )
136- names(grps ) = toupper(names(grps ))
137- if (is.null(grps $ GROUPS ) || any(is.na(grps $ GROUPS )) || any(grps $ GROUPS == " " ))
138- {
139- qt = try(dbExecute(dbo ,paste0(" update '" ,stdInit ,
140- " set Groups = 'All_Stands' where Groups = ''" )))
141- if (class(qt )== " try-error" ) return (" Failure updating 'Groups' in StandInit." )
142- }
143- }
144- return (NULL )
145- }
146-
147-
14830fixFVSKeywords <- function (dbo )
14931{
15032 tbs <- dbGetQuery(dbo ," select name from sqlite_master where type='table';" )[,1 ]
0 commit comments